Exemplo n.º 1
0
 public async void SaveLoginAttempt(string username, DateTime loginTime, bool isSuccesful)
 {
     LoginAttemptDTO laDTO = new LoginAttemptDTO {
         Username = username, LoginTime = loginTime, IsSuccessful = isSuccesful
     };
     //bool x = loginService.AddLoginAttempt(laDTO).Result; //niepotrzebny bool
     await loginService.AddLoginAttempt(laDTO);
 }
        public ActionResult Index(string userName, string password, string returnUrl)
        {
            Guid attemptId = Guid.NewGuid();

            _loginHandler.Handle(new LoginCommand
            {
                AttemptId = attemptId,
                Username  = userName,
                Password  = password
            });

            LoginAttemptDTO result = _loginRepository.GetLoginAttemptById(attemptId);

            if (result.Succeeded)
            {
                _userProvider.SetUser(result.UserId.Value, result.UserRole);
                return(!string.IsNullOrEmpty(returnUrl)
                                        ? (ActionResult)Redirect(returnUrl)
                                        : RedirectToAction("Index", "Home"));
            }

            ModelState.AddModelError("LoginFailed", result.Message);
            return(View());
        }