public async Task <ServiceResponse <AuthenticateViewModel> > Register(RegisterRequest request) { var isEmailValid = EmailValidator.IsEmailValid(request.Email); if (!isEmailValid) { return(ServiceResponse <AuthenticateViewModel> .Error("Invalid email")); } var player = await _context.Players.FirstOrDefaultAsync( x => x.Email == request.Email); if (player != null) { return(ServiceResponse <AuthenticateViewModel> .Error("Email already exist")); } var(isPasswordValid, passwordMessage) = _passwordValidator.ValidateAsync(request.Password); if (!isPasswordValid) { return(ServiceResponse <AuthenticateViewModel> .Error(passwordMessage)); } var hashedPassword = _passwordHasher.HashPassword(player, request.Password); var refreshToken = _jwtHelper.GenerateRefreshToken(); var newPlayer = new Player { Email = request.Email, PasswordHash = hashedPassword, Nick = request.Nick, RefreshToken = refreshToken, }; await _context.Players.AddAsync(newPlayer); await _context.SaveChangesAsync(); var accessToken = _jwtHelper.GenerateJwtToken(newPlayer); return(ServiceResponse <AuthenticateViewModel> .Ok( new AuthenticateViewModel(accessToken, refreshToken.Token))); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { const int SQL_SERVER_DATETIME_MINIMUM_SAFE_YEAR = 1753; if (DateOfBirth.Year < SQL_SERVER_DATETIME_MINIMUM_SAFE_YEAR) { yield return(new ValidationResult("Please enter a valid Date of Birth", new[] { nameof(DateOfBirth) })); } if ((FirstName + LastName).Length < 2) { yield return(new ValidationResult("Please enter at least a First or Last Name.", new[] { nameof(FirstName), nameof(LastName) })); } if (!EmailValidator.IsEmailValid(Email)) { yield return(new ValidationResult("Please enter a valid Email address", new[] { nameof(Email) })); } }
public async Task <ServiceProviderResponse> CreateOrUpdateSenderAsync( [FromHeader(Constant.OperationTrackingIdHeader)] string requestId, [FromHeader] string account, [FromBody] Sender request) { Validator.ArgumentNotNull(request, nameof(request)); Validator.ArgumentNotNullOrEmpty(request.SenderAddress, nameof(request.SenderAddress)); Validator.ArgumentNotNullOrEmpty(request.ForwardAddress, nameof(request.ForwardAddress)); Validator.IsTrue <ArgumentException>(EmailValidator.IsEmailValid(request.SenderAddress), nameof(request.SenderAddress), "SenderAddr is invalid."); Validator.IsTrue <ArgumentException>(EmailValidator.IsEmailValid(request.ForwardAddress), nameof(request.ForwardAddress), "ForwardAddr is invalid."); if (request.SenderAddrID != null) { Validator.ArgumentValidGuid(request.SenderAddrID, nameof(request.SenderAddrID)); } var currentAccount = await EnsureAccount(account, requestId); request.EngagementAccount = currentAccount.EngagementAccount; var senderResult = await this.engine.CreateOrUpdateSenderAsync(request, requestId); return(ServiceProviderResponse.CreateJsonResponse(HttpStatusCode.OK, senderResult)); }