public async Task <LoginResponse> Login(LoginRequest request) { var result = await _signInManager.PasswordSignInAsync(request.Username, request.Password, request.RememberMe, true); if (result.RequiresTwoFactor) { return(LoginResponse.TwoFactorAuthenticationEnabled()); } if (result.IsLockedOut) { return(LoginResponse.LockedOut()); } if (result.Succeeded) { var user = _applicationUserManager.Users.Include(y => y.Groups).First(x => x.UserName.ToLower().Equals(request.Username)); var roles = await _applicationUserManager.GetRolesAsync(user); var groups = user.Groups.Select(x => x.Group.Name); var token = _jwtTokenService.CreateToken(HelperService.ToUser(user), roles); return(LoginResponse.Success(token, GetResponseUser(user, token))); } else { return(LoginResponse.Failure("Invalid Username or Password")); } }