public async Task <IActionResult> Login(UserForLoginDto userForLoginDto) { return(Ok(new { token = await jwtTokenGeneratorService.GenerateJwtTokenString(userForLoginDto.Username, userForLoginDto.Password) })); }
public async Task <IActionResult> Login(UserForLoginDto userForLoginDto) { var user = await userManager.FindByNameAsync(userForLoginDto.UserName); if (user == null) { return(BadRequest(new { result = "No user has found" })); } var result = await signInManager.CheckPasswordSignInAsync(user, userForLoginDto.Password, false); if (!result.Succeeded) { return(Unauthorized()); } { var appUser = await userManager.Users.FirstOrDefaultAsync(u => u.NormalizedUserName == userForLoginDto.UserName.ToUpper()); var userToReturn = mapper.Map <User>(appUser); return(Ok(new { token = await jwtTokenGenerator.GenerateJwtTokenString(userToReturn) })); } }