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 PopulateControls() { if (!siteSettings.RequiresQuestionAndAnswer) { divSecurityQuestion.Visible = false; divSecurityAnswer.Visible = false; } if ((siteUser != null) && (siteUser.UserId > -1)) { spnTitle.InnerText = Resource.ManageUsersTitleLabel + " " + siteUser.Name; txtName.Text = siteUser.Name; this.txtLoginName.Text = siteUser.LoginName; lnkAvatarUpload.ClientClick = "return GB_showPage('" + Page.Server.HtmlEncode(string.Format(CultureInfo.InvariantCulture, Resource.UploadAvatarForUserFormat, siteUser.Name)) + "', this.href, GBCallback)"; txtEmail.Text = siteUser.Email; txtOpenIDURI.Text = siteUser.OpenIdUri; txtWindowsLiveID.Text = siteUser.WindowsLiveId; txtLiveMessengerCID.Text = siteUser.LiveMessengerId; chkEnableLiveMessengerOnProfile.Checked = siteUser.EnableLiveMessengerOnProfile; gravatar1.Email = siteUser.Email; gravatar1.MaxAllowedRating = MaxAllowedGravatarRating; if (siteUser.LastActivityDate > DateTime.MinValue) { this.lblLastActivityDate.Text = siteUser.LastActivityDate.AddHours(TimeOffset).ToString(); } if (siteUser.LastLoginDate > DateTime.MinValue) { this.lblLastLoginDate.Text = siteUser.LastLoginDate.AddHours(TimeOffset).ToString(); } if (siteUser.LastPasswordChangedDate > DateTime.MinValue) { this.lblLastPasswordChangeDate.Text = siteUser.LastPasswordChangedDate.AddHours(TimeOffset).ToString(); } if (siteUser.LastLockoutDate > DateTime.MinValue) { this.lblLastLockoutDate.Text = siteUser.LastLockoutDate.AddHours(TimeOffset).ToString(); } this.lblFailedPasswordAttemptCount.Text = siteUser.FailedPasswordAttemptCount.ToString(); this.lblFailedPasswordAnswerAttemptCount.Text = siteUser.FailedPasswordAnswerAttemptCount.ToString(); this.chkIsLockedOut.Checked = siteUser.IsLockedOut; btnLockUser.Visible = !siteUser.IsLockedOut; btnUnlockUser.Visible = siteUser.IsLockedOut; if (siteSettings.UseSecureRegistration) { if (siteUser.RegisterConfirmGuid == Guid.Empty) { chkEmailIsConfirmed.Checked = true; btnConfirmEmail.Enabled = false; } } else { divEmailConfirm.Visible = false; } this.txtComment.Text = siteUser.Comment; this.txtPasswordQuestion.Text = siteUser.PasswordQuestion; this.txtPasswordAnswer.Text = siteUser.PasswordAnswer; if (!siteSettings.UseLdapAuth) { if (siteSettings.PasswordFormat == 0) { //Clear this.txtPassword.Text = siteUser.Password; } else if (siteSettings.PasswordFormat == 2) { try { CMembershipProvider CMembership = (CMembershipProvider)Membership.Provider; this.txtPassword.Text = CMembership.UnencodePassword(siteUser.Password, MembershipPasswordFormat.Encrypted); } catch (FormatException ex) { log.Error("Error decoding password for user " + siteUser.Email + " on manage users page.", ex); // TODO: should we generate a random password and fix it here? } } } lblCreatedDate.Text = siteUser.DateCreated.AddHours(TimeOffset).ToString(); lblUserGuid.Text = siteUser.UserGuid.ToString(); lblTotalPosts.Text = siteUser.TotalPosts.ToString(); lnkUserPosts.UserId = siteUser.UserId; lnkUserPosts.TotalPosts = siteUser.TotalPosts; lnkUnsubscribeFromGroups.NavigateUrl = SiteRoot + "/Groups/UnsubscribeGroup.aspx?ue=" + Page.Server.UrlEncode(siteUser.Email); chkProfileApproved.Checked = siteUser.ProfileApproved; chkApprovedForGroups.Checked = siteUser.ApprovedForGroups; chkTrusted.Checked = siteUser.Trusted; chkDisplayInMemberList.Checked = siteUser.DisplayInMemberList; //ListItem listItem; if ((!allowGravatars) && (!disableAvatars)) { if (siteUser.AvatarUrl.Length > 0) { //listItem = ddAvatars.Items.FindByValue(siteUser.AvatarUrl); //if (listItem != null) //{ // ddAvatars.ClearSelection(); // listItem.Selected = true; //} imgAvatar.Src = ImageSiteRoot + "/Data/Sites/" + siteSettings.SiteId.ToInvariantString() + "/useravatars/" + siteUser.AvatarUrl; } else { imgAvatar.Src = ImageSiteRoot + "/Data/SiteImages/1x1.gif"; } } using (IDataReader reader = SiteUser.GetRolesByUser(siteSettings.SiteId, siteUser.UserId)) { userRoles.DataSource = reader; userRoles.DataBind(); } using (IDataReader reader = Role.GetRolesUserIsNotIn(siteSettings.SiteId, siteUser.UserId)) { allRoles.DataSource = reader; allRoles.DataBind(); } if (allRoles.Items.Count == 0) { allRoles.Enabled = false; addExisting.Enabled = false; addExisting.Text = Resource.ManageUsersUserIsInAllRolesMessage; } List <UserLocation> userLocations = UserLocation.GetByUser(siteUser.UserGuid); grdUserLocation.DataSource = userLocations; grdUserLocation.DataBind(); } else { spnTitle.InnerText = Resource.ManageUsersAddUserLabel; HideExtendedProfileControls(); } }
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); }