Пример #1
0
        public User FindUser(LoginAttemptModel model)
        {
            var email      = model.Email;
            var dictionary = _dao.RetrieveUser(email);

            return(new User(int.Parse(dictionary["SystemID"]), email, dictionary["FirstName"], dictionary["LastName"], dictionary["AccountStatus"], DateTime.Parse(dictionary["DateOfBirth"]), dictionary["Gender"]));
        }
        public async Task <IActionResult> Attempt(LoginAttemptModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await m_signInManager.PasswordSignInAsync(model.InputEmailAddress, model.InputPassword, model.RememberPasswordCheck, false);

                if (result.Succeeded)
                {
                    return(Redirect("/home"));
                }
            }

            return(View("Views/Pages/Login.cshtml", new LoginPageModel()
            {
                SigninSuccess = false
            }));
        }
Пример #3
0
 public IHttpActionResult LoginAccount([FromBody] LoginAttemptModel loginAttempt)
 {
     try
     {
         // Model Binding Validation
         if (!ModelState.IsValid)
         {
             return(BadRequest());
         }
         // Try to login and get token
         return(Ok(_userManager.LoginAccount(loginAttempt)));
     }
     catch (Exception e)
     {
         var newError = new Exception(e.Message, null);
         return(InternalServerError(newError));
     }
 }
        public string LoginAccount(LoginAttemptModel account)
        {
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    _authNService._userEmail = account.Email;
                    var authNSuccess = _authNService.Authenticate(account.Password);
                    if (authNSuccess)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    var handler = new ErrorController();
                    handler.Handle(e);
                }
                if (i == 2)
                {
                    throw new Exception("Failed to Authenticate User");
                }
            }

            for (int i = 0; i < 3; i++)
            {
                try
                {
                    var user = _authNService.FindUser(account);
                    if (user is object)
                    {
                        return(_authService.GenerateJWT(user));
                    }
                }
                catch (Exception e)
                {
                    var handler = new ErrorController();
                    handler.Handle(e);
                }
            }


            throw new Exception("Failed to Login");
        }