public async Task <LoginResult> LoginAsync(LoginCredentials loginCredentials) { var user = await _userManager.FindByEmailAsync(loginCredentials.Email); if (user == null) { throw new RestException(HttpStatusCode.NotFound, $"Email address {loginCredentials.Email} not found."); } var result = await _signInManager.CheckPasswordSignInAsync(user, loginCredentials.Password, false); if (!result.Succeeded) { throw new RestException(HttpStatusCode.BadRequest, "Email/Password is invalid."); } if (!user.EmailConfirmed) { throw new RestException(HttpStatusCode.BadRequest, "Your account is not confirmed yet."); } await _messageHub.SendLoginMessageAsync(new LoginEventMessageDto { Message = $"{user.FirstName} just logged in!", UserId = user.Id }); return(new LoginResult { JwtToken = _tokenGenerator.Generate(user), FirstName = user.FirstName, Id = user.Id }); }