public override async Task <SignInReply> SignIn(SignInRequest request, ServerCallContext context) { var signInInfo = _mapper.Map <SignInInfoDto>(request); SignInResultDto result = await _authService.SignInAsync(signInInfo); return(_mapper.Map <SignInReply>(result)); }
public async Task <SignInResultDto> SignInAsync(AuthenticationRequestDto authenticationRequestDto) { var signInResult = await _signInManager.PasswordSignInAsync(authenticationRequestDto.UserName, authenticationRequestDto.Password, true, false); var serializedJwtToken = string.Empty; if (signInResult.Succeeded) { serializedJwtToken = await _jwtTokenAppFactory.CreateSerializedJtwTokenAsync(authenticationRequestDto.UserName); } var result = new SignInResultDto { SerializedJwtToken = serializedJwtToken, Succeeded = signInResult.Succeeded }; return(result); }
public SignInResultDto SignIn(SignInDto signInDto) { var user = _signInManager.UserManager.Users.FirstOrDefault(u => u.UserName == signInDto.UserName); if (user == null) { throw new EntityNotFoundException(string.Format(USER_NOT_FOUND, signInDto.UserName)); } if (!_signInManager.UserManager.CheckPasswordAsync(user, signInDto.Password).Result) { throw new ArgumentException(WRONG_PASSWORD_MESSAGE); } var signInResultDto = new SignInResultDto { Id = user.Id, Role = _userManager.GetRolesAsync(user).Result.First(), Token = GenerateJwtToken(user).Result }; return(signInResultDto); }
public async Task <IActionResult> LoginUserAsync([FromBody] LoginViewModel loginViewModel) { if (!ModelState.IsValid) { return(Json(ModelState.DefaultInvalidModelStateWithErrorMessages())); } await _userService.SignOutAsync(); LoginUserDto loginUserDto = loginViewModel.GetLoginUserDto(); SignInResultDto signInResult = await _userService.SignInAsync(loginUserDto); if (!signInResult.Success) { return(Json(new { success = false })); } int userId = await _userService.GetUserIdByEmailAsync(loginViewModel.Email); await _tempDataService.UpdateTempDataAsync(TempData, userId); return(Json(new { success = true, loggedin = true })); }