public async Task<SignInInfoDto> SignInAsync(SignInDto signInDto) { var user = await _userRepository.FindUserByAsync(new Filter("Login", signInDto.Login)); if (user == null || !PasswordHash.ValidatePassword(signInDto.Password, user.Password)) { return new SignInInfoDto() { State = UserState.NotFound }; } else { var result = new SignInInfoDto() { Sid = user.Sid, Name = user.Name, Login = user.Login, State = UserState.Success }; if (!user.Activated) result.State = UserState.NotActivated; if (!user.Enabled) result.State = UserState.Locked; return result; } }
public async Task<ActionResult> SignIn(SignInDto model, string returnUrl) { AuthenticationManager.SignOut(); if (!ModelState.IsValid) { return View(model); } var result = await _userProvider.SignInAsync(model); switch (result.State) { case UserState.Success: SignIn(result, model.RememberMe); return RedirectToLocal(returnUrl); case UserState.Locked: return View("Lockout"); case UserState.NotActivated: return View("NotActivated"); case UserState.NotFound: default: ModelState.AddModelError("", ValidationMessages.ResourceManager.GetString("InvalidUsernameOrPassword")); return View(model); } }