public async Task <IActionResult> CreateUser([FromForm] UserRegistrationDTO userRegistrationRequest) { if (!_reCaptcha.Validate(userRegistrationRequest.ReCaptchaToken)) { return(Ok(new Status { Success = false, Errors = new[] { "Invalid ReCaptcha." } })); } var userRegistration = _userRegistration.TrimFields(userRegistrationRequest); if (!ModelState.IsValid) { return(Ok(new Status { Success = false, Errors = new[] { "Fields missing." } })); } if (_userRegistration.CheckWhitespace(userRegistration)) { return(Ok(new Status { Success = false, Errors = new[] { "Fields can't have whitespace." } })); } if (_context.Users.Any(x => x.UserName == userRegistration.UserName)) { return(Ok(new Status { Success = false, Errors = new[] { "Username already exists." } })); } if (_context.Users.Any(x => x.Email == userRegistration.Email)) { return(Ok(new Status { Success = false, Errors = new[] { "Email already exists." } })); } var hashedUser = _userRegistration.HashPassword(userRegistration); _context.Users.Add(hashedUser); await _context.SaveChangesAsync(); return(Ok(new Status { Success = true })); }