internal static UserSecurityKeyModel ProcessSigninRequest(SigninRequestModel signinRequest) { try { var userName = RsaUtil.Decrypt(signinRequest.UserName).ToLower(); // get the user id var userId = GetUserIdByUserName(userName); if (userId == Guid.Empty) { throw new KeyNotFoundException("This user does not exist."); } // save the client RSA public key to database RsaUtil.SaveClientKey(signinRequest.ClientRsaPublicKey, userId); return(GetUserSecurityKey(userId)); } catch (KeyNotFoundException) { throw; } catch (Exception e) { Logger.Error(e); throw new Exception("Failed to process the sign in request."); } }
internal static string Signin(SigninRequestModel signinRequest) { try { var userId = GetUserIdByUserName(RsaUtil.Decrypt(signinRequest.UserName).ToLower()); return(ValidateUser(userId, signinRequest.Password) ? AesUtil.Encrypt(AuthUtil.GenerateToken(userId), userId) : string.Empty); } catch (Exception e) { Logger.Error(e); throw new Exception("Failed to validate the user login."); } }
public ActionResult <string> RequestSignin([FromBody] SigninRequestModel signinRequest) { try { return(Ok(UserUtil.ProcessSigninRequest(signinRequest))); } catch (KeyNotFoundException ke) { return(NotFound(ke.Message)); } catch (Exception e) { Logger.Error(e); return(StatusCode(500, e.Message)); } }
public ActionResult <string> Signin([FromBody] SigninRequestModel signinRequest) { try { var token = UserUtil.Signin(signinRequest); if (token == string.Empty) { return(Unauthorized()); } return(Ok(token)); } catch (Exception e) { Logger.Error(e); return(StatusCode(500, e.Message)); } }