Ejemplo n.º 1
0
        public ActionResult Register(Models.RegisterModel model)
        {
            if (!ReCaptcha.Validate(DataUtils.GetConfig("reCaptcha:SecretKey")))
            {
                ModelState.AddModelError("", "Captcha cannot be empty");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var users = _auth0Helper.SearchAuth0UserByEmail(model.EmailAddress);
                    if (!users.Any())
                    {
                        var newUser = new SignupUserRequest();
                        newUser.ClientId     = Auth0Helper.Auth0ClientId;
                        newUser.Connection   = Auth0Helper.Connection;
                        newUser.Email        = model.EmailAddress;
                        newUser.Password     = model.Password;
                        newUser.UserMetadata = new { model.FirstName, model.LastName, model.PhoneNumber };

                        SignupUserResponse response = _client.SignupUserAsync(newUser).Result;

                        var customer = new AccountProfileModel(model.Content)
                        {
                            UserId       = $"auth0|{response.Id}",
                            EmailAddress = model.EmailAddress,
                            FirstName    = model.FirstName,
                            LastName     = model.LastName
                        };

                        MailController.Instance(Request, model.Content, CurrentUser.LanguageCode).RegistrationConfirmMail(customer).Send();
                        return(Redirect($"/{CurrentUser.LanguageCode}/account/confirm-your-email-address/"));
                    }
                    else
                    {
                        var unverifiedUser = users.FirstOrDefault(u => u.UserId.StartsWith("auth0") && u.EmailVerified == false);
                        if (unverifiedUser != null)
                        {
                            return(Redirect($"/{CurrentUser.LanguageCode}/account/resend-email-verification/?u={unverifiedUser.UserId}"));
                        }
                        ModelState.AddModelError("", "E-mail adress already exists");
                    }
                }
                catch (Exception e)
                {
                    HandleAuth0Exception(e);
                }
            }
            return(CurrentUmbracoPage());
        }
Ejemplo n.º 2
0
        public ActionResult ResendEmailVerification(ContentModel model, string u)
        {
            var unverifiedUser = _auth0Helper.GetAuth0User(u);
            var customer       = new AccountProfileModel(model.Content)
            {
                UserId       = unverifiedUser.UserId,
                EmailAddress = unverifiedUser.Email,
                FirstName    = unverifiedUser.FirstName,
                LastName     = unverifiedUser.LastName
            };

            MailController.Instance(Request, model.Content, CurrentUser.LanguageCode).RegistrationConfirmMail(customer).Send();
            return(Redirect($"/{CurrentUser.LanguageCode}/account/confirm-your-email-address/"));
        }
Ejemplo n.º 3
0
        public ActionResult PasswordRecovery(PasswordRecoveryModel model)
        {
            User user = _auth0Helper.SearchAuth0UserByEmail(model.Email)?.SingleOrDefault(x => x.UserId.StartsWith("auth0"));

            if (user == null)
            {
                ModelState.AddModelError("", "E-mail not found");
            }

            if (ModelState.IsValid)
            {
                MailController.Instance(Request, model.Content, CurrentUser.LanguageCode).PasswordRecovery(user).Send();
                return(Redirect($"/{CurrentUser.LanguageCode}/account/change-password-email/"));
            }
            return(CurrentUmbracoPage());
        }