Ejemplo n.º 1
0
        void Register_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            var email    = Email.Text;
            var password = Password.Text;
            var userName = SiteUtils.SuggestLoginNameFromEmail(siteSettings.SiteId, email);

            SiteUser existingUser = null;

            if (SiteUser.EmailExistsInDB(siteSettings.SiteId, email))
            {
                if (WebConfigSettings.AllowNewRegistrationToActivateDeletedAccountWithSameEmail)
                {
                    existingUser = SiteUser.GetByEmail(siteSettings, email);
                    if ((existingUser != null) && (!existingUser.IsDeleted))
                    {
                        existingUser = null;
                    }
                }

                if (existingUser == null)
                {
                    RegisterResults.Text = ResourceHelper.GetResourceString("Resource", "DuplicateEmailMessage");
                    return;
                }
            }

            if (SiteUser.LoginExistsInDB(siteSettings.SiteId, userName))
            {
                RegisterResults.Text = ResourceHelper.GetResourceString("Resource", "DuplicateUserNameMessage");
                return;
            }

            if (password.Length < siteSettings.MinRequiredPasswordLength)
            {
                RegisterResults.Text = ResourceHelper.GetResourceString("ProductResources", "CheckoutRegisterInvalidPassword");
                return;
            }

            int nonAlphaNumericCharactersUsedCount = 0;

            for (int i = 0; i < password.Length; i++)
            {
                if (!char.IsLetterOrDigit(password, i))
                {
                    nonAlphaNumericCharactersUsedCount++;
                }
            }

            if (nonAlphaNumericCharactersUsedCount < siteSettings.MinRequiredNonAlphanumericCharacters)
            {
                RegisterResults.Text = ResourceHelper.GetResourceString("ProductResources", "CheckoutRegisterInvalidPassword");
                return;
            }

            if (siteSettings.PasswordStrengthRegularExpression.Length > 0)
            {
                if (!Regex.IsMatch(password, siteSettings.PasswordStrengthRegularExpression))
                {
                    RegisterResults.Text = ResourceHelper.GetResourceString("ProductResources", "CheckoutRegisterInvalidPassword");
                    return;
                }
            }

            SiteUser siteUser;

            if (existingUser != null)
            {
                siteUser = existingUser;
            }
            else
            {
                siteUser = new SiteUser(siteSettings);
            }

            siteUser.Name      = userName;
            siteUser.LoginName = userName;
            siteUser.Email     = email;
            siteUser.FirstName = FullName.Text.Trim();

            var PasswordFormat = (MembershipPasswordFormat)siteSettings.PasswordFormat;

            if (PasswordFormat != MembershipPasswordFormat.Clear)
            {
                siteUser.PasswordSalt = SiteUser.CreateRandomPassword(128, WebConfigSettings.PasswordGeneratorChars);
                password = (new gbMembershipProvider()).EncodePassword(siteUser.PasswordSalt + password, PasswordFormat);
            }

            siteUser.Password         = password;
            siteUser.ApprovedForLogin = !siteSettings.RequireApprovalBeforeLogin;
            bool created = siteUser.Save();

            if (existingUser != null)
            {
                SiteUser.FlagAsNotDeleted(siteUser.UserId);
            }

            if (created)
            {
                if (siteSettings.UseEmailForLogin)
                {
                    FormsAuthentication.SetAuthCookie(siteUser.Email, false);
                }
                SiteUtils.CreateAndStoreSessionToken(siteUser);
                siteUser.UpdateLastLoginTime();
            }

            if (config.CheckoutNextZoneId > 0)
            {
                WebUtils.SetupRedirect(this, CartHelper.GetZoneUrl(config.CheckoutNextZoneId));
            }
        }