示例#1
0
        public async Task <object> CreateAsync(
            [FromServices] GoogleRecaptchaService recaptchaService,
            [FromServices] UserAccountService userAccountService,
            [FromBody] CreateUserRequest body)
        {
            var remoteIp = HttpContext.Connection.RemoteIpAddress.ToString();

            if (!await recaptchaService.ValidateAsync(remoteIp, body.Captcha).ConfigureAwait(false))
            {
                return(BadRequest(JResponse.Error("reCAPTCHA validation failed.")));
            }
            if (!await userAccountService.IsNameAvailabilityAsync(body.Username))
            {
                return(BadRequest(JResponse.Error("User name already taken.")));
            }
            if (!await userAccountService.IsEmailAvailabilityAsync(body.Email))
            {
                return(BadRequest(JResponse.Error("Email address already registered.")));
            }
            await userAccountService.CreateAccountAsync(body.Username, body.Email, body.Password);

            return(JResponse.OK());
        }