public TokenResponseModel Login(LoginInputType loginInput) { var result = new TokenResponseModel { Message = "Success" }; if (string.IsNullOrEmpty(loginInput.Email) || string.IsNullOrEmpty(loginInput.Password)) { result.Message = "Invalid Credentials"; return(result); } var user = _authContext.User.Where(_ => _.EmailAddress == loginInput.Email).FirstOrDefault(); if (user == null) { result.Message = "Invalid Credentials"; return(result); } if (!ValidatePasswordHash(loginInput.Password, user.Password)) { result.Message = "Invalid Credentials"; return(result); } var roles = _authContext.UserRoles.Where(_ => _.UserId == user.UserId).ToList(); result.AccessToken = GetJWTAuthKey(user, roles); result.RefreshToken = GenerateRefreshToken(); user.RefreshToken = result.RefreshToken; user.RefershTokenExpiration = DateTime.Now.AddDays(7); _authContext.SaveChanges(); return(result); }
public TokenResponseModel Login([Service] IAuthLogic authLogic, LoginInputType loginInput) { return(authLogic.Login(loginInput)); }