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); }
void btnCreateUser_Click(object sender, EventArgs e) { Page.Validate(); if (!Page.IsValid) { return; } if (hdnIdentifier.Value.Length == 0) { // form manipulation if this is missing Response.Redirect(SiteRoot + "/Secure/Register.aspx"); return; } string email = txtEmail.Text; string loginName = string.Empty; if ((hdnPreferredUsername.Value.Length > 0) && (!SiteUser.LoginExistsInDB(siteSettings.SiteId, hdnPreferredUsername.Value))) { loginName = hdnPreferredUsername.Value; } if (loginName.Length == 0) { loginName = SiteUtils.SuggestLoginNameFromEmail(siteSettings.SiteId, email); } string name = loginName; if (hdnDisplayName.Value.Length > 0) { name = hdnDisplayName.Value; } if (SiteUser.EmailExistsInDB(siteSettings.SiteId, email)) { lblError.Text = Resource.RegisterDuplicateEmailMessage; } else { bool emailIsVerified = false; SiteUser newUser = CreateUser( hdnIdentifier.Value, email, loginName, name, emailIsVerified); SignInUser(newUser); } }
private void CreateUser() { if (SiteUser.EmailExistsInDB(siteSettings.SiteId, txtEmail.Text)) { lblErrorMessage.Text = Resource.DuplicateEmailMessage; return; } if (SiteUser.LoginExistsInDB(siteSettings.SiteId, txtLoginName.Text)) { lblErrorMessage.Text = Resource.DuplicateUserNameMessage; return; } SiteUser user = new SiteUser(siteSettings); user.Name = txtName.Text; user.LoginName = txtLoginName.Text; user.Email = txtEmail.Text; CMembershipProvider CMembership = (CMembershipProvider)Membership.Provider; user.Password = CMembership.EncodePassword(txtPassword.Text, siteSettings); if (user.Save()) { user.PasswordQuestion = this.txtPasswordQuestion.Text; user.PasswordAnswer = this.txtPasswordAnswer.Text; user.Save(); CProfileConfiguration profileConfig = CProfileConfiguration.GetConfig(); // set default values foreach (CProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions) { CProfilePropertyDefinition.SavePropertyDefault(user, propertyDefinition); } CacheHelper.TouchMembershipStatisticsCacheDependencyFile(); UserRegisteredEventArgs u = new UserRegisteredEventArgs(user); OnUserRegistered(u); WebUtils.SetupRedirect(this, SiteRoot + "/Admin/ManageUsers.aspx?userId=" + user.UserId.ToString() + "&username="******"&pageid=" + pageID); return; } }
void btnChangePassword_Click(object sender, EventArgs e) { Page.Validate("ChangePassword1"); if (Page.IsValid) { if (siteUser.OpenIdUri.Length == 0) { return; } if (siteUser.Email.Contains(siteUser.OpenIdUri) && siteUser.Email != Email.Text.Trim()) { if (SiteUser.EmailExistsInDB(siteSettings.SiteId, Email.Text.Trim())) { FailureText.Text = ResourceHelper.GetResourceString("Resource", "RegisterDuplicateEmailMessage"); return; } siteUser.Email = Email.Text.Trim(); } if (siteUser.LoginName != UserName.Text.Trim()) { if (SiteUser.LoginExistsInDB(siteSettings.SiteId, UserName.Text.Trim())) { FailureText.Text = ResourceHelper.GetResourceString("Resource", "RegisterDuplicateUserNameMessage"); return; } siteUser.LoginName = UserName.Text.Trim(); siteUser.Name = siteUser.LoginName; } siteUser.PasswordResetGuid = Guid.Empty; gbMembershipProvider m = Membership.Provider as gbMembershipProvider; siteUser.Password = m.EncodePassword(siteSettings, siteUser, txtNewPassword.Text); siteUser.MustChangePwd = false; siteUser.ApprovedForLogin = true; siteUser.Save(); siteUser.UpdateLastPasswordChangeTime(); DoUserLogin(siteUser); //if (!string.IsNullOrEmpty(Request.QueryString["gl"])) // Response.Redirect("/cart", true); SetupScripts(); } }
void btnCreateUser_Click(object sender, EventArgs e) { Page.Validate("profile"); if (Page.IsValid) { //PopulateRequiredProfileControls(); string openID = CookieHelper.GetSecureCookieValue(openidCookieName); string email = txtEmail.Text; if ( (CookieHelper.CookieExists(openIdEmailCookieName)) && (email.Length == 0) ) { email = CookieHelper.GetSecureCookieValue(openIdEmailCookieName); } if (openID.Length == 0) { return; } string loginName = openID.Replace("http://", string.Empty).Replace("https://", string.Empty).Replace("/", string.Empty); string name = loginName; if (CookieHelper.CookieExists(openIdFullNameCookieName)) { name = CookieHelper.GetSecureCookieValue(openIdFullNameCookieName); } if (SiteUser.EmailExistsInDB(siteSettings.SiteId, email)) { lblError.Text = Resource.RegisterDuplicateEmailMessage; } else { CreateUser(openID, email, SecurityHelper.RemoveMarkup(loginName), SecurityHelper.RemoveMarkup(name)); } } }
private bool IsValidForNewUser() { bool result = true; Page.Validate("profile"); if (!Page.IsValid) { return(false); } if (SiteUser.LoginExistsInDB(siteSettings.SiteId, txtUserName.Text)) { result = false; lblError.Text = Resource.RegisterDuplicateUserNameMessage; } if (SiteUser.EmailExistsInDB(siteSettings.SiteId, txtEmail.Text)) { result = false; lblError.Text += " " + Resource.RegisterDuplicateEmailMessage; } return(result); }
private void UpdateUser() { userEmail = siteUser.Email; if ( (siteUser.Email != txtEmail.Text) && (SiteUser.EmailExistsInDB(siteSettings.SiteId, siteUser.UserId, txtEmail.Text)) ) { lblErrorMessage.Text = Resource.DuplicateEmailMessage; return; } if ((siteSettings.AllowUserEditorPreference) && (divEditorPreference.Visible)) { siteUser.EditorPreference = ddEditorProviders.SelectedValue; } if (siteSettings.AllowUserFullNameChange) { siteUser.Name = txtName.Text; } siteUser.Email = txtEmail.Text; if (WebConfigSettings.LogIpAddressForEmailChanges) { if ((siteUser.UserId != -1) && (userEmail != siteUser.Email)) { log.Info("email for user changed from " + userEmail + " to " + siteUser.Email + " from ip address " + SiteUtils.GetIP4Address()); } } if (pnlSecurityQuestion.Visible) { siteUser.PasswordQuestion = this.txtPasswordQuestion.Text; siteUser.PasswordAnswer = this.txtPasswordAnswer.Text; } else { //in case it is ever changed later to require password question and answer after making it not required // we need to ensure there is some question and answer. if (siteUser.PasswordQuestion.Length == 0) { siteUser.PasswordQuestion = Resource.ManageUsersDefaultSecurityQuestion; siteUser.PasswordAnswer = Resource.ManageUsersDefaultSecurityAnswer; } } if (siteUser.LiveMessengerId.Length > 0) { siteUser.EnableLiveMessengerOnProfile = chkEnableLiveMessengerOnProfile.Checked; } else { siteUser.EnableLiveMessengerOnProfile = false; } if (allowUserSkin) { siteUser.Skin = SkinSetting.GetValue(); //if (ddSkins.SelectedValue != "printerfriendly") //{ // siteUser.Skin = ddSkins.SelectedValue; //} } #if !MONO ISettingControl setting = timeZoneSetting as ISettingControl; if (setting != null) { siteUser.TimeZoneId = setting.GetValue(); } #endif //if ((!disableOldAvatars)&&(!WebConfigSettings.OnlyAdminsCanEditCheesyAvatars)) //{ siteUser.AvatarUrl = ddAvatars.SelectedValue; } siteUser.PasswordFormat = siteSettings.PasswordFormat; if (siteUser.Save()) { mojoProfileConfiguration profileConfig = mojoProfileConfiguration.GetConfig(); foreach (mojoProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions) { if ( (propertyDefinition.EditableByUser) && ( (propertyDefinition.OnlyAvailableForRoles.Length == 0) || (WebUser.IsInRoles(propertyDefinition.OnlyAvailableForRoles)) ) ) { mojoProfilePropertyDefinition.SaveProperty( siteUser, pnlProfileProperties, propertyDefinition, timeOffset, timeZone); } } siteUser.UpdateLastActivityTime(); if ((userEmail != siteUser.Email) && (siteSettings.UseEmailForLogin) && (!siteSettings.UseLdapAuth)) { FormsAuthentication.SetAuthCookie(siteUser.Email, false); } ProfileUpdatedEventArgs u = new ProfileUpdatedEventArgs(siteUser, false); OnUserUpdated(u); SiteUtils.SetSkinCookie(siteUser); WebUtils.SetupRedirect(this, Request.RawUrl); return; } }
private void DoNewUserLogic(OpenIdEventArgs e) { if (e == null) { return; } ClaimsResponse claim = e.Response.GetExtension <ClaimsResponse>(); if (claim == null) { return; } if (IsValidForUserCreation(e, claim)) { if (SiteUser.EmailExistsInDB(siteSettings.SiteId, claim.Email)) { // show message that user should login and associate // their open id account on their profile page. lblError.Text = Resource.OpenIDRegisterUserEmailExistsMessage; } else { // create user automagically since we have all // the needed data string loginName = SecurityHelper.RemoveMarkup(e.ClaimedIdentifier.ToString().Replace("http://", string.Empty).Replace("https://", string.Empty).Replace("/", string.Empty)); CreateUser( e.ClaimedIdentifier.ToString(), claim.Email, loginName, SecurityHelper.RemoveMarkup(claim.FullName)); return; } } else { // prompt user to enter needed fields CookieHelper.SetSecureCookie(openidCookieName, e.ClaimedIdentifier.ToString()); if ( (claim != null) && (claim.Email != null) && (claim.Email.Length > 3) && (Email.IsValidEmailAddressSyntax(claim.Email)) ) { CookieHelper.SetSecureCookie(openIdEmailCookieName, claim.Email); divEmailInput.Visible = false; divEmailDisplay.Visible = true; litEmail.Text = claim.Email; } else { divEmailInput.Visible = true; divEmailDisplay.Visible = false; } if ( (claim != null) && (claim.FullName != null) && (claim.FullName.Length > 0) ) { CookieHelper.SetSecureCookie(openIdFullNameCookieName, SecurityHelper.RemoveMarkup(claim.FullName)); } pnlNeededProfileProperties.Visible = true; pnlOpenID.Visible = false; if (e.ClaimedIdentifier != null) { litOpenIDURI.Text = e.ClaimedIdentifier.ToString(); } //PopulateRequiredProfileControls(); //DisplayResults(e); litInfoNeededMessage.Text = Resource.OpenIDAdditionalInfoNeededMessage; } }
private void DoNewUserLogic(OpenIdEventArgs e) { if (e == null) { return; } ClaimsResponse claim = e.Response.GetExtension <ClaimsResponse>(); if (claim == null) { return; } if (IsValidForUserCreation(e, claim)) { if (SiteUser.EmailExistsInDB(siteSettings.SiteId, claim.Email)) { // show message that user should login and associate // their open id account on their profile page. lblError.Text = Resource.OpenIDRegisterUserEmailExistsMessage; return; } else { // create user automagically since we have all // the needed data SiteUser newUser = new SiteUser(siteSettings); newUser.Email = claim.Email; newUser.Name = claim.FullName; string loginName = newUser.Name.Replace(" ", ".").ToLower(); if (loginName.Length > 50) { loginName = loginName.Substring(0, 50); } if (SiteUser.LoginExistsInDB( siteSettings.SiteId, loginName)) { loginName = e.ClaimedIdentifier.ToString().Replace("http://", string.Empty).Replace("https://", string.Empty).Replace("/", string.Empty); if (loginName.Length > 50) { loginName = loginName.Substring(0, 50); } int i = 1; while (SiteUser.LoginExistsInDB( siteSettings.SiteId, loginName)) { loginName += i.ToString(); if (loginName.Length > 50) { loginName = loginName.Remove(40, 1); } i++; } } newUser.LoginName = loginName; newUser.Password = SiteUser.CreateRandomPassword(7, WebConfigSettings.PasswordGeneratorChars); newUser.PasswordQuestion = Resource.ManageUsersDefaultSecurityQuestion; newUser.PasswordAnswer = Resource.ManageUsersDefaultSecurityAnswer; newUser.OpenIdUri = e.ClaimedIdentifier.ToString(); newUser.Save(); if (siteSettings.UseSecureRegistration) { newUser.SetRegistrationConfirmationGuid(Guid.NewGuid()); } // track user ip address UserLocation userLocation = new UserLocation(newUser.UserGuid, SiteUtils.GetIP4Address()); userLocation.SiteGuid = siteSettings.SiteGuid; userLocation.Hostname = Page.Request.UserHostName; userLocation.Save(); if ( (siteSettings.UseSecureRegistration) && (newUser.RegisterConfirmGuid != Guid.Empty) ) { Notification.SendRegistrationConfirmationLink( SiteUtils.GetSmtpSettings(), ResourceHelper.GetMessageTemplate("RegisterConfirmEmailMessage.config"), siteSettings.DefaultEmailFromAddress, siteSettings.DefaultFromEmailAlias, newUser.Email, siteSettings.SiteName, WebUtils.GetSiteRoot() + "/ConfirmRegistration.aspx?ticket=" + newUser.RegisterConfirmGuid.ToString()); lblError.Text = Resource.LoginUnconfirmedEmailMessage; log.Info("Automatically created User " + newUser.Name + " on login from open id. Tried to login but email address is not confirmed."); return; } if (siteSettings.UseEmailForLogin) { FormsAuthentication.SetAuthCookie( newUser.Email, true); } else { FormsAuthentication.SetAuthCookie( newUser.LoginName, true); } if (WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites) { string cookieName = "siteguid" + siteSettings.SiteGuid; CookieHelper.SetCookie(cookieName, newUser.UserGuid.ToString(), true); } newUser.UpdateLastLoginTime(); string redirectUrl = GetRedirectPath(); CookieHelper.ExpireCookie(returnUrlCookieName); WebUtils.SetupRedirect(this, redirectUrl); return; } } else { // user not found // required fields not available from open id // redirect to register page? // Or show message with Link to // register page string registerLinkHref = siteRoot + "/Secure/RegisterWithOpenID.aspx"; litNotRegisteredYetMessage.Text = string.Format( Resource.OpenIDMustRegisterBeforeLoginMesage, registerLinkHref); } }
private SiteUser CreateUser(FaceBookUser oUser) { if (string.IsNullOrEmpty(oUser.Email) || !Email.IsValidEmailAddressSyntax(oUser.Email)) { oUser.Email = oUser.Id + "@facebook.com"; } if (SiteUser.EmailExistsInDB(siteSettings.SiteId, oUser.Email)) { var user = new SiteUser(siteSettings, oUser.Email); if (user != null && user.UserId > 0) { if (string.IsNullOrEmpty(user.OpenIdUri)) { user.OpenIdUri = oUser.Id; //if (oUser.Email != user.Email) // user.ApprovedForLogin = true; user.Save(); } return(user); } } SiteUser newUser = new SiteUser(siteSettings); newUser.Email = oUser.Email; newUser.LoginName = SiteUtils.SuggestLoginNameFromEmail(siteSettings.SiteId, newUser.Email); newUser.Name = newUser.LoginName; gbMembershipProvider gbMembership = (gbMembershipProvider)Membership.Provider; newUser.Password = gbMembership.EncodePassword(siteSettings, newUser, SiteUser.CreateRandomPassword(7, WebConfigSettings.PasswordGeneratorChars)); newUser.ApprovedForLogin = false; newUser.OpenIdUri = oUser.Id; //"http://www.facebook.com/profile.php?id=" + oUser.Id; if (!string.IsNullOrEmpty(oUser.First_Name)) { newUser.FirstName = oUser.First_Name; } if (!string.IsNullOrEmpty(oUser.Last_Name)) { newUser.FirstName = (oUser.Last_Name + " " + newUser.FirstName).Trim(); //newUser.LastName = oUser.Last_Name; } if (string.IsNullOrEmpty(newUser.FirstName) && !string.IsNullOrEmpty(oUser.Name)) { newUser.FirstName = oUser.Name; } //if (!string.IsNullOrEmpty(oUser.Bio)) // newUser.AuthorBio = oUser.Bio; if (!string.IsNullOrEmpty(oUser.Gender)) { switch (oUser.Gender.ToLower()) { case "male": case "nam": newUser.Gender = "M"; break; case "female": case "nữ": newUser.Gender = "F"; break; } //newUser.Gender = oUser.Gender.ToUpper(); } //if (!string.IsNullOrEmpty(oUser.Link)) // newUser.WebSiteUrl = oUser.Link; //newUser.AvatarUrl = string.Format("https://graph.facebook.com/{0}/picture?width=160&height=160", oUser.Id); newUser.Save(); //// track clientNo ip address //UserLocation userLocation = new UserLocation(newUser.UserGuid, SiteUtils.GetIP4Address()); //userLocation.SiteGuid = siteSettings.SiteGuid; //userLocation.Hostname = Page.Request.UserHostName; //userLocation.Save(); UserRegisteredEventArgs u = new UserRegisteredEventArgs(newUser); OnUserRegistered(u); CacheHelper.ClearMembershipStatisticsCache(); return(newUser); }
private void UpdateUser() { userEmail = siteUser.Email; if ( (siteUser.Email != txtEmail.Text) && (SiteUser.EmailExistsInDB(siteSettings.SiteId, txtEmail.Text)) ) { message.ErrorMessage = ResourceHelper.GetResourceString("Resource", "DuplicateEmailMessage"); return; } if ((siteSettings.AllowUserEditorPreference) && (divEditorPreference.Visible)) { siteUser.EditorPreference = ddEditorProviders.SelectedValue; } if (siteSettings.AllowUserFullNameChange) { siteUser.Name = txtName.Text; } siteUser.Email = txtEmail.Text; if (WebConfigSettings.LogIpAddressForEmailChanges) { if ((siteUser.UserId != -1) && (userEmail != siteUser.Email)) { log.Info("email for user changed from " + userEmail + " to " + siteUser.Email + " from ip address " + SiteUtils.GetIP4Address()); } } if (pnlSecurityQuestion.Visible) { siteUser.PasswordQuestion = this.txtPasswordQuestion.Text; siteUser.PasswordAnswer = this.txtPasswordAnswer.Text; } else { if (siteUser.PasswordQuestion.Length == 0) { siteUser.PasswordQuestion = ResourceHelper.GetResourceString("Resource", "ManageUsersDefaultSecurityQuestion"); siteUser.PasswordAnswer = ResourceHelper.GetResourceString("Resource", "ManageUsersDefaultSecurityAnswer"); } } if (siteUser.LiveMessengerId.Length > 0) { siteUser.EnableLiveMessengerOnProfile = chkEnableLiveMessengerOnProfile.Checked; } else { siteUser.EnableLiveMessengerOnProfile = false; } #if !MONO ISettingControl setting = timeZoneSetting as ISettingControl; if (setting != null) { siteUser.TimeZoneId = setting.GetValue(); } #endif if (siteUser.Save()) { gbProfileConfiguration profileConfig = gbProfileConfiguration.GetConfig(); foreach (gbProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions) { if ( (propertyDefinition.EditableByUser) && ( (propertyDefinition.OnlyAvailableForRoles.Length == 0) || (WebUser.IsInRoles(propertyDefinition.OnlyAvailableForRoles)) ) ) { gbProfilePropertyDefinition.SaveProperty( siteUser, pnlProfileProperties, propertyDefinition, timeOffset, timeZone); } } siteUser.UpdateLastActivityTime(); if ((userEmail != siteUser.Email) && (siteSettings.UseEmailForLogin) && (!siteSettings.UseLdapAuth)) { FormsAuthentication.SetAuthCookie(siteUser.Email, false); } ProfileUpdatedEventArgs u = new ProfileUpdatedEventArgs(siteUser, false); OnUserUpdated(u); WebUtils.SetupRedirect(this, Request.RawUrl); return; } }
private void UpdateUser() { if (siteUser == null) { return; } if ( (siteUser.Email != txtEmail.Text) && (SiteUser.EmailExistsInDB(siteSettings.SiteId, txtEmail.Text)) ) { lblErrorMessage.Text = Resource.DuplicateEmailMessage; return; } if ( (siteUser.LoginName != txtLoginName.Text) && (SiteUser.LoginExistsInDB(siteSettings.SiteId, txtLoginName.Text)) ) { lblErrorMessage.Text = Resource.DuplicateUserNameMessage; return; } siteUser.Name = txtName.Text; siteUser.LoginName = txtLoginName.Text; siteUser.Email = txtEmail.Text; if (divOpenID.Visible) { siteUser.OpenIdUri = txtOpenIDURI.Text; } if (!siteSettings.UseLdapAuth) { if (txtPassword.Text.Length > 0) { CMembershipProvider CMembership = (CMembershipProvider)Membership.Provider; siteUser.Password = CMembership.EncodePassword(txtPassword.Text, siteSettings); } } siteUser.ProfileApproved = chkProfileApproved.Checked; siteUser.ApprovedForGroups = chkApprovedForGroups.Checked; siteUser.Trusted = chkTrusted.Checked; siteUser.DisplayInMemberList = chkDisplayInMemberList.Checked; //siteUser.AvatarUrl = ddAvatars.SelectedValue; // this could also be in profile system siteUser.Comment = this.txtComment.Text; siteUser.PasswordQuestion = this.txtPasswordQuestion.Text; siteUser.PasswordAnswer = this.txtPasswordAnswer.Text; siteUser.WindowsLiveId = txtWindowsLiveID.Text; siteUser.LiveMessengerId = txtLiveMessengerCID.Text; siteUser.EnableLiveMessengerOnProfile = chkEnableLiveMessengerOnProfile.Checked; if (siteUser.Save()) { CProfileConfiguration profileConfig = CProfileConfiguration.GetConfig(); foreach (CProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions) { CProfilePropertyDefinition.SaveProperty( siteUser, pnlProfileProperties, propertyDefinition, TimeOffset); } if ((currentUser != null) && (currentUser.UserId == siteUser.UserId)) { if ((siteSettings.UseEmailForLogin) && (siteUser.Email != currentUser.Email)) { FormsAuthentication.SetAuthCookie(siteUser.Email, false); } if ((!siteSettings.UseEmailForLogin) && (siteUser.LoginName != currentUser.LoginName)) { FormsAuthentication.SetAuthCookie(siteUser.LoginName, false); } } WebUtils.SetupRedirect(this, Request.RawUrl); } }
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)); } }
private void UpdateUser() { userEmail = siteUser.Email; if ( (siteUser.Email != txtEmail.Text) && (SiteUser.EmailExistsInDB(siteSettings.SiteId, txtEmail.Text)) ) { lblErrorMessage.Text = Resource.DuplicateEmailMessage; return; } siteUser.Name = txtName.Text; siteUser.Email = txtEmail.Text; if (pnlSecurityQuestion.Visible) { siteUser.PasswordQuestion = this.txtPasswordQuestion.Text; siteUser.PasswordAnswer = this.txtPasswordAnswer.Text; } else { //in case it is ever changed later to require password question and answer after making it not required // we need to ensure there is some question and answer. if (siteUser.PasswordQuestion.Length == 0) { siteUser.PasswordQuestion = Resource.ManageUsersDefaultSecurityQuestion; siteUser.PasswordAnswer = Resource.ManageUsersDefaultSecurityAnswer; } } if (siteUser.LiveMessengerId.Length > 0) { siteUser.EnableLiveMessengerOnProfile = chkEnableLiveMessengerOnProfile.Checked; } else { siteUser.EnableLiveMessengerOnProfile = false; } if (siteSettings.AllowUserSkins) { if (ddSkins.SelectedValue != "printerfriendly") { siteUser.Skin = ddSkins.SelectedValue; } } //if ((!disableOldAvatars)&&(!WebConfigSettings.OnlyAdminsCanEditCheesyAvatars)) //{ siteUser.AvatarUrl = ddAvatars.SelectedValue; } if (siteUser.Save()) { CProfileConfiguration profileConfig = CProfileConfiguration.GetConfig(); foreach (CProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions) { if ( (propertyDefinition.EditableByUser) && ( (propertyDefinition.OnlyAvailableForRoles.Length == 0) || (WebUser.IsInRoles(propertyDefinition.OnlyAvailableForRoles)) ) ) { CProfilePropertyDefinition.SaveProperty( siteUser, pnlProfileProperties, propertyDefinition, timeOffset); } } siteUser.UpdateLastActivityTime(); if ((userEmail != siteUser.Email) && (siteSettings.UseEmailForLogin)) { FormsAuthentication.SetAuthCookie(siteUser.Email, false); } SiteUtils.SetSkinCookie(siteUser); WebUtils.SetupRedirect(this, Request.RawUrl); return; } }