Beispiel #1
0
        public async Task <object> Register([FromBody] UserRegister userRegister)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.SelectMany(start => start.Errors).Select(error => error.ErrorMessage).Take(1).ElementAt(0)));
            }

            // Google Recaptcha Validation
            if (WebConfigurationManager.AppSettings["GoogleRecaptcha"] == "true")
            {
                GoogleResponse googleResponse = await _google.ValidateRecaptcha <GoogleResponse>(userRegister.Token);

                if (!googleResponse.Success)
                {
                    return(BadRequest("error.validation.invalid-recaptcha"));
                }
            }

            // HCaptcha Validation
            if (WebConfigurationManager.AppSettings["HCaptcha"] == "true")
            {
                HCaptchaResponse hCaptchaResponse = await _hCaptcha.Validate <HCaptchaResponse>(userRegister.Token);

                if (!hCaptchaResponse.Success)
                {
                    return(BadRequest("error.validation.invalid-hcaptcha"));
                }
            }

            UserRegisterResponse user = await _userService.Register(userRegister);

            if (user.ErrorEmail)
            {
                return(BadRequest("error.user.email-exists"));
            }

            if (user.ErrorCpf)
            {
                return(BadRequest("error.user.cpf-exists"));
            }

            // Register Mail
            if (WebConfigurationManager.AppSettings["Mail"] == "true")
            {
                string message = RenderRazor.RenderView("~/Views/MailTemplates/Register.cshtml", userRegister, null);
                MailService.SendMailAsync(userRegister.Email, new string[] { }, "Register", message);
            }


            return(Ok(user));
        }
Beispiel #2
0
        public async Task <object> Login([FromBody] UserLogin userLogin)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values.SelectMany(start => start.Errors).Select(error => error.ErrorMessage).Take(1).ElementAt(0)));
            }

            // Google Recaptcha Validation
            if (WebConfigurationManager.AppSettings["GoogleRecaptcha"] == "true")
            {
                GoogleResponse googleResponse = await _google.ValidateRecaptcha <GoogleResponse>(userLogin.Token);

                if (!googleResponse.Success)
                {
                    return(BadRequest("error.validation.invalid-recaptcha"));
                }
            }

            // HCaptcha Validation
            if (WebConfigurationManager.AppSettings["HCaptcha"] == "true")
            {
                HCaptchaResponse hCaptchaResponse = await _hCaptcha.Validate <HCaptchaResponse>(userLogin.Token);

                if (!hCaptchaResponse.Success)
                {
                    return(BadRequest("error.validation.invalid-hcaptcha"));
                }
            }

            object user = await _userService.Auth(userLogin);

            if (user == null)
            {
                return(BadRequest("error.validation.incorrect-login"));
            }

            return(Ok(user));
        }