public override async Task <AccountRegistrationResponse> RegisterAccount(AccountRegistrationRequest request, ServerCallContext context) { RedisUserModel user = await RedisUserModel.GetUserFromUsername(request.Username); if (user != null) { return new AccountRegistrationResponse() { Status = ResponseFactory.createResponse(ResponseType.DUPLICATE) } } ; // Create a new user model RedisUserModel model = new RedisUserModel(request); await model.SaveToDatabase(); string token = JwtManager.GenerateToken(model.UserModel.Id); context.ResponseTrailers.Add("Authorization", token); return(new AccountRegistrationResponse { Token = token, User = model.asUser(), Status = ResponseFactory.createResponse(ResponseType.SUCCESS), }); } }
public override async Task <AuthorizationResponse> Login(AuthorizationRequest request, ServerCallContext context) { // Try to get a user RedisUserModel user = await RedisUserModel.GetUserFromUsername(request.Username); if (user == null || !JwtManager.VerifyPasswordHash(request.Password, user.UserModel.PasswordHash)) { return new AuthorizationResponse() { Status = ResponseFactory.createResponse(ResponseType.INVALID_CREDENTIALS) } } ; string token = JwtManager.GenerateToken(user.UserModel.Id); context.ResponseTrailers.Add("Authorization", token); return(new AuthorizationResponse { Token = token, User = user.asUser(), Status = ResponseFactory.createResponse(ResponseType.SUCCESS), }); }