Example #1
0
        public static void FillUserFromModel(this UserDto user, UserModel loginModel, AuthModel authModel)
        {
            var access = new AccessDto
            {
                Id = authModel.AccessId,
                Type = (loginModel.Remember ? AuthType.Cookie : AuthType.Session)
            };

            switch (loginModel.LoggedUntil)
            {
                case LoggedUntil.Hour:
                    access.ValidUntil = DateTime.UtcNow.AddHours(1);
                    break;
                case LoggedUntil.Day:
                    access.ValidUntil = DateTime.UtcNow.AddDays(1);
                    break;
                case LoggedUntil.Week:
                    access.ValidUntil = DateTime.UtcNow.AddDays(7);
                    break;
                case LoggedUntil.Month:
                    access.ValidUntil = DateTime.UtcNow.AddMonths(1);
                    break;
                case LoggedUntil.Year:
                    access.ValidUntil = DateTime.UtcNow.AddYears(1);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            user.AccessList.Add(access);
        }
Example #2
0
        public IActionResult Login(UserModel model)
        {
            if (!ModelState.IsValid)
                return View();

            var result = _userService.Login(model);
            return View(result ? "LoginSuccess" : "LoginFail");
        }
Example #3
0
 public static UserDto FillUserFromModel(UserModel model, UserDto user)
 {
     return model.FillUserFromModel(user);
 }
Example #4
0
        public bool Login(UserModel model)
        {
            var authModel = new AuthModel(model.Email);
            var user = GetUser(model.Email);

            if (user == null)
            {
                user = new UserDto();
                user.FillNewUserFromModel(model, authModel);
            }
            else
            {
                user.FillUserFromModel(model, authModel);
            }

            //SetWatchlist(model, user, false);

            if (!SetUser(user))
            {
                throw new Exception("Could not save user to database!");
            }

            var loginAuth = _encryptionService.Encrypt(authModel);
            var loginUrl = _context.Request.GetHostUrl() + "/User/Auth?token=" + loginAuth;
            return _emailService.SendAuthenticationEmail(user, authModel, loginUrl);
        }
Example #5
0
 public static void FillNewUserFromModel(this UserDto user, UserModel loginModel, AuthModel authModel)
 {
     user.Email = loginModel.Email;
     user.FillUserFromModel(loginModel, authModel);
 }