Beispiel #1
0
        bool LoginAuthor()
        {
            if (!SiteUser.EmailExistsInDB(siteSettings.SiteId, txtEmail.Text))
            {
                message.Message = "Email Don't Exists";
                return(false);
            }
            else
            {
                string result = SiteUser.Login(siteSettings, txtEmail.Text, txtPass.Text);
                if (result != "")
                {
                    try
                    {
                        SiteUser temp        = SiteUser.GetByEmail(siteSettings, txtEmail.Text);
                        KLAuthor authorlogin = KLAuthor.GetKLAuthorByUserID(temp.UserId);
                        if (authorlogin.IsActive != false)
                        {
                            GeneralVariables.NameAuthor = temp.Name;
                            GeneralVariables.Level      = authorlogin.LevelAuthor;
                            if (temp.Email != "")
                            {
                                if ((siteSettings.UseEmailForLogin))
                                {
                                    FormsAuthentication.SetAuthCookie(temp.Email, false);
                                    SiteUtils.CreateAndStoreSessionToken(temp);
                                }
                            }
                            else
                            {
                                if ((!siteSettings.UseEmailForLogin))
                                {
                                    FormsAuthentication.SetAuthCookie(temp.LoginName, false);

                                    SiteUtils.CreateAndStoreSessionToken(temp);
                                }
                            }

                            return(true);
                        }
                        else
                        {
                            message.Message = "This Account not yet approved";
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex.Message);
                    }
                }
                else
                {
                    message.Message = "Password Wrong";
                }
            }

            return(false);
        }
Beispiel #2
0
        private void DoUserLogin(SiteUser siteUser)
        {
            if (siteUser.IsLockedOut)
            {
                FailureText.Text = ResourceHelper.GetResourceString("Resource", "LoginAccountLockedMessage");
            }
            else
            {
                if (siteSettings.UseEmailForLogin)
                {
                    FormsAuthentication.SetAuthCookie(siteUser.Email, true);
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(siteUser.LoginName, true);
                }

                SiteUtils.CreateAndStoreSessionToken(siteUser);
            }
        }
        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));
            }
        }