public async Task <ActionResult> Handle(LoginCommand request, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); _unitOfWork.BeginTransaction(); var user = await _identityUserManager.FindByNameAsync(request.Email); if (user == null) { return(new ActionResult { Suceeded = false, ErrorMessages = new List <string> { "E-mail or password is incorrect!" } }); } var result = await _signInManager.CheckPasswordSignInAsync(user, request.Password, false); if (result.Succeeded) { await _signInManager.SignInAsync(user, request.RememberMe); _unitOfWork.Commit(); return(new ActionResult { Suceeded = true }); } else { var loginResult = new ActionResult { Suceeded = false }; if (result.IsLockedOut) { loginResult.ErrorMessages.Add("Your account is locked out!"); } else { loginResult.ErrorMessages.Add("E-mail or password is incorrect!"); } _unitOfWork.Rollback(); return(loginResult); } }
public async Task <object> SignIn(LoginAccount model) { var user = await _userManager.FindByNameAsync(model.UserName); if (user == null) { return(new { message = "Invalid information" }); } var result = await _signInManager.CheckPasswordSignInAsync(user, model.Password, false); if (result.Succeeded) { var token = await GetTokenAsync(user); return(new { token }); } return(new { message = "Invalid information" }); }