public async Task <IActionResult> Login(LoginInfoDto loginInfoDto) { var user = await _userManager.FindByNameAsync(loginInfoDto.UserName); if (user == null) { return(BadRequest(new { message = "Username or password is incorrect!" })); } var check = await _userInformationService.CheckInitializedInfo(user.Id); if (!check) { await _userInformationService.AddWithEmptyInfo(user.Id, ""); await _unitOfWork.Commit(); } var userInfo = await _userInformationService.GetOne(user.Id); var result = await _authService.AuthenticateUser(user, loginInfoDto.Password, userInfo.IsBlocked); switch (result) { case AuthenticateUserResult.Invalid: return(BadRequest(new { message = "Username or password is incorrect!" })); case AuthenticateUserResult.Blocked: return(Forbid()); case AuthenticateUserResult.Succeeded: var token = await _tokenService.GenerateToken(user, _appSetting.JwtSecret); return(Ok(new { token, user.Id })); default: return(NotFound()); } }
public async Task <IActionResult> GetOne(string id) { var userInfo = await _userInformationService.GetOne(id); return(Ok(userInfo)); }