public async Task <IActionResult> LoginUserAsync([FromBody] LoginRequestDto dto) { Logger.LogInformation($"{nameof(LoginUserAsync)}, dto:{dto.ToJson()}"); var user = await _userManager.FindByEmailAsync(dto.Email); ValidateUserAllowed(user, dto); await ValidateEmailConfirmed(user, dto); ValidateUserNotLocked(user, dto); await ValidatePasswordsMatch(user, dto.Password, dto); return(new ObjectResult(new LoginResponseDto { CurrentUser = Mapper.Map <User, UserDto>(user), Token = _authenticationService.GenerateToken(user) })); }
private static async Task <HttpResponseMessage> AuthenticateAsync(this TestServerFixture testServerFixture, string email, string password, ITestOutputHelper output) { var requestData = new LoginRequestDto { Email = email, Password = password }; var content = new StringContent(JsonConvert.SerializeObject(requestData), Encoding.UTF8, "application/json"); output.WriteLine($"METHOD POST, url:'{AllInOne.Common.Constants.Api.V1.Authentication.Login}' dto:'{requestData.ToJson()}'"); var response = await testServerFixture.Client.PostAsync(AllInOne.Common.Constants.Api.V1.Authentication.Login, content); var dto = await response.ConvertToAsync <LoginResponseDto>(output); testServerFixture.Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", dto.Token); return(response); }