private void CreateUser(string windowsLiveId) { SiteUser newUser = new SiteUser(siteSettings); newUser.WindowsLiveId = windowsLiveId; newUser.Name = txtUserName.Text; newUser.LoginName = txtUserName.Text; newUser.Email = txtEmail.Text; CMembershipProvider CMembership = (CMembershipProvider)Membership.Provider; newUser.Password = CMembership.EncodePassword(SiteUser.CreateRandomPassword(7), siteSettings); //newUser.Password = SiteUser.CreateRandomPassword(7); newUser.PasswordQuestion = Resource.ManageUsersDefaultSecurityQuestion; newUser.PasswordAnswer = Resource.ManageUsersDefaultSecurityAnswer; newUser.Save(); if (siteSettings.UseSecureRegistration) { newUser.SetRegistrationConfirmationGuid(Guid.NewGuid()); } CProfileConfiguration profileConfig = CProfileConfiguration.GetConfig(); // set default values first foreach (CProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions) { CProfilePropertyDefinition.SavePropertyDefault( newUser, propertyDefinition); } foreach (CProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions) { if (propertyDefinition.RequiredForRegistration) { CProfilePropertyDefinition.SaveProperty( newUser, pnlRequiredProfileProperties, propertyDefinition, timeOffset); } } // track user 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.TouchMembershipStatisticsCacheDependencyFile(); NewsletterHelper.ClaimExistingSubscriptions(newUser); DoUserLogin(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; } }
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); } }
private void CreateUser( string openId, string email, string loginName, string name) { SiteUser newUser = new SiteUser(siteSettings); newUser.Email = email; 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++; } if ((name == null) || (name.Length == 0)) { name = loginName; } newUser.LoginName = loginName; newUser.Name = name; //newUser.Password = SiteUser.CreateRandomPassword(7); CMembershipProvider CMembership = (CMembershipProvider)Membership.Provider; newUser.Password = CMembership.EncodePassword(SiteUser.CreateRandomPassword(7), siteSettings); newUser.PasswordQuestion = Resource.ManageUsersDefaultSecurityQuestion; newUser.PasswordAnswer = Resource.ManageUsersDefaultSecurityAnswer; newUser.OpenIdUri = openId; newUser.Save(); if (siteSettings.UseSecureRegistration) { newUser.SetRegistrationConfirmationGuid(Guid.NewGuid()); } CProfileConfiguration profileConfig = CProfileConfiguration.GetConfig(); // set default values first foreach (CProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions) { CProfilePropertyDefinition.SavePropertyDefault( newUser, propertyDefinition); } foreach (CProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions) { if (propertyDefinition.RequiredForRegistration) { CProfilePropertyDefinition.SaveProperty( newUser, pnlRequiredProfileProperties, propertyDefinition, timeOffset); } } // track user 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.TouchMembershipStatisticsCacheDependencyFile(); NewsletterHelper.ClaimExistingSubscriptions(newUser); DoUserLogin(newUser); }