⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 useredit.aspx.cs

📁 community server 源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
			userToEdit.EnableDisplayName = enableDisplayNames.SelectedValue;
			userToEdit.EnableUserAvtars = enableUserAvtars.SelectedValue;
			userToEdit.EnableUserSignatures = enableUserSignatures.SelectedValue;


			if( cntx.SiteSettings.EnableCensorship ) 
			{
				userToEdit.Profile.Signature = Transforms.CensorPost( signature.Text );
			} 
			else 
			{
				userToEdit.Profile.Signature = signature.Text;
			}
			
			userToEdit.Email = privateEmail.Text;
			userToEdit.Profile.PublicEmail = publicEmail.Text;
			userToEdit.Profile.MsnIM = msnIM.Text;
			userToEdit.Profile.AolIM = aolIM.Text;
			userToEdit.Profile.YahooIM = yahooIM.Text;
			userToEdit.Profile.IcqIM = icq.Text;
			userToEdit.AvatarUrl = avatarUrl.Text;
			userToEdit.Profile.DateFormat = dateFormat.SelectedItem.Value;
			userToEdit.EnableAvatar = enableAvatar.SelectedValue;
			userToEdit.Profile.EnableEmoticons = enableEmoticons.SelectedValue;

			if (int.Parse(sortOrder.SelectedItem.Value) == 1)
				userToEdit.PostSortOrder = SortOrder.Descending;
			else
				userToEdit.PostSortOrder = SortOrder.Ascending;
			
			userToEdit.EnableThreadTracking = enableEmailTracking.SelectedValue;
			userToEdit.EnableEmail = enableEmail.SelectedValue;
			if( !cntx.SiteSettings.EnableEmail ) 
			{
				userToEdit.EnableThreadTracking = false;
				userToEdit.EnableEmail = false;
			}
			userToEdit.EnableInk = enableInk.SelectedValue;
			userToEdit.EnableDisplayInMemberList = displayInMemberList.SelectedValue;
			userToEdit.EnableHtmlEmail = enableHtmlEmail.SelectedValue;

			userToEdit.Profile.Language = language.SelectedItem.Value;

			if (enablePostPreviewPopup != null && ForumConfiguration.Instance().EnablePostPreviewPopup)  
			{  				
				userToEdit.Profile.EnablePostPreviewPopup = enablePostPreviewPopup.SelectedValue;
			}

			userToEdit.Profile.FontSize = int.Parse(FontSize.SelectedValue);
			userToEdit.EditorType = EditorList.SelectedValue;
			userToEdit.EnableCollapsingPanels = bool.Parse( EnableCollapsingPanels.SelectedItem.Value );
       
			if (birthday != null)
				userToEdit.Profile.BirthDate = birthday.SelectedDate;

			userToEdit.Theme = theme.SelectedValue;
            
			// Detect if moderationlevel has changed: moderated <=> unmoderated
			//
			if (userToEdit.ModerationLevel != moderationLevel.SelectedValue) 
			{
				if (moderationLevel.SelectedValue == ModerationLevel.Moderated && 
					userToEdit.ModerationLevel == ModerationLevel.Unmoderated) 
				{
					postModerationChanged = true;
					hasModerated = true;
				}
				if (moderationLevel.SelectedValue == ModerationLevel.Unmoderated &&
					userToEdit.ModerationLevel == ModerationLevel.Moderated) 
				{ 
					postModerationChanged = true;
					hasModerated = false;
				}
			}

			userToEdit.ModerationLevel = moderationLevel.SelectedValue;
        
			// Detect if selected user has been banned
			//
			if (userToEdit.IsBanned && accountStatus.SelectedValue == UserAccountStatus.Approved) 
			{
				hasBanned = false;
				hasBanBeenUsed = true;
			}             
			if (!userToEdit.IsBanned && accountStatus.SelectedValue == UserAccountStatus.Banned) 
			{ 
				hasBanned = true;
				hasBanBeenUsed = true;
			}

			userToEdit.AccountStatus = accountStatus.SelectedValue;
			userToEdit.IsAvatarApproved = isAvatarApproved.SelectedValue;
			userToEdit.ForceLogin = forceLogin.SelectedValue;
			
			if (userToEdit.IsIgnored != isIgnored.SelectedValue)
			{
				userToEdit.IsIgnored = isIgnored.SelectedValue;
				hasIgnoredChanged = true;
			}
			if (hasIgnoredChanged && isIgnored.SelectedValue == true)
			{
				hasIgnored = true;
			}
			
			try 
			{
				userToEdit.DummyTotalPosts = Int32.Parse( dummyTotalPosts.Text.Trim() );
			} 
			catch 
			{ 
				userToEdit.DummyTotalPosts = userToEdit.TotalPosts;
			}

			// User Banning
			if (accountStatus.SelectedValue == UserAccountStatus.Banned)
				userToEdit.BannedUntil = DateTime.Now.AddDays((int) userBanPeriod.SelectedValue);
			else
				userToEdit.BannedUntil = DateTime.Now;
			userToEdit.BanReason = userBanReason.SelectedValue;
            
			// User Approval
			if (userApprovalSection.Visible == true && 
				accountStatus.SelectedValue == UserAccountStatus.ApprovalPending) 
			{

				if (isApproved.SelectedValue == true) 
				{
					// Change status to Approved
					userToEdit.AccountStatus = UserAccountStatus.Approved;
				}

				if (isApproved.SelectedValue == false) 
				{
					// Change status to Disapproved
					userToEdit.AccountStatus = UserAccountStatus.Disapproved;
				}
			}

			SetExtendedUserData(userToEdit);

			#region TODO
			/* TODO
			// Does the user have a user uploaded avatar?
			//
			if (uploadedAvatar.PostedFile.ContentLength > 0) {
				Stream fs = uploadedAvatar.PostedFile.InputStream;

				// Is the avatar an allowed size?
				//
				if (PostedFile.ContentLength > CSContext.Current.SiteSettings.AvatarMaxSize) {
				}

				// Is the avatar within the allowed dimensions?
				//
				fs = ForumImage.ResizeImage(fs, CSContext.Current.SiteSettings.AvatarHeight, CSContext.Current.SiteSettings.AvatarWidth);

				// Add the avatar to the database
				//
				ForumImage.AddUserAvatar(fs, userToEdit.Username);

				// Does the new avatar require approval
				//
				if (CSContext.Current.SiteSettings.EnableAvatarRequireApproval)
					userToEdit.IsAvatarApproved = false;
				else
					userToEdit.IsAvatarApproved = true;

				userToEdit.AvatarUrl = Globals.GetSiteUrls().ForumImage(userToEdit.Username);
			} */
			#endregion

			// Update the user
			try 
			{
				Users.UpdateUser(userToEdit);

			}
			catch (CSException ex) 
			{
				// Check to see if the MemberRole component threw a duplicate email exception. If so we want to handle it gracefully.
				if (ex.CreateUserStatus == CreateUserStatus.DuplicateEmailAddress)
				{
					// Notify that update was not successful because of duplicate email
					formStatus.Visible = true;
					formStatus.Success = false;
					formStatus.ResourceName = "EditProfile_DuplicateEmail";
					return false;
				}

				throw;
			}


			// Log Audit: ban/unban, moderate/unmoderate ignore/unignore
			//
			Audit.SaveUserAuditEvent( ModerateUserSetting.UserEdited, userToEdit, cntx.User.UserID ); 
           
			if (hasBanBeenUsed) 
			{ 
				if (hasBanned)
					Audit.SaveUserAuditEvent( ModerateUserSetting.UserBanned, userToEdit, cntx.User.UserID );
				else
					Audit.SaveUserAuditEvent( ModerateUserSetting.UserUnbanned, userToEdit, cntx.User.UserID );
			}
			if (postModerationChanged) 
			{ 
				if (hasModerated)
					Audit.SaveUserAuditEvent( ModerateUserSetting.UserModerated, userToEdit, cntx.User.UserID );
				else
					Audit.SaveUserAuditEvent( ModerateUserSetting.UserUnmoderated, userToEdit, cntx.User.UserID );
			}
			if (hasIgnoredChanged)
			{
				if (hasIgnored)
				{
					Audit.SaveUserAuditEvent(ModerateUserSetting.UserIgnored, userToEdit, cntx.User.UserID );
				}
				else
				{
					Audit.SaveUserAuditEvent(ModerateUserSetting.UserUnignored, userToEdit, cntx.User.UserID );
				}
			}
            
			// Unlock user profile
			//
			if (userToEdit.Member != null && userToEdit.Member.IsLockedOut && 
				unlockUser.SelectedValue == true) 
			{ 
				userToEdit.Member.UnlockUser();
			}

			// Send notification emails after the update took place
			//

			// User Approval
			if( this.PrevAccountStatus == UserAccountStatus.ApprovalPending &&
				userToEdit.AccountStatus == UserAccountStatus.Approved )  
			{

				Emails.UserAccountApproved(userToEdit);
			}

			if( this.PrevAccountStatus == UserAccountStatus.ApprovalPending &&
				userToEdit.AccountStatus == UserAccountStatus.Disapproved ) 
			{

				Emails.UserAccountRejected(userToEdit, cntx.User);
			}

         
			// Notify the End of Update
			return true;

			//throw new CSException(CSExceptionType.UserProfileUpdated);

		}

		protected virtual void UpdateAvatar( Int32 userID ) 
		{
			Resources.UpdateAvatar( userID, uploadedAvatar.PostedFile.InputStream );
			avatarUrl.Text = "users/avatar.aspx?userid=" + userID.ToString();
		}

		protected virtual Boolean AreValuesValid 
		{
			get 
			{
				// Check the max length on the signature
				//
				if (signature.Text.ToString().Length > CSContext.Current.SiteSettings.UserSignatureMaxLength) 
				{
					signatureMaxLengthValidator.IsValid = false;
					return false;
				} 
				else 
				{
					signatureMaxLengthValidator.IsValid = true;
					return true;
				}
			}
		}
		#endregion

		#region Helper Properties & Methods

		[
			DefaultValue( UserAccountStatus.Approved ),
		]
		public virtual UserAccountStatus PrevAccountStatus 
		{
			get 
			{
				Object state = ViewState["PrevAccountStatus"];
				if ( state != null ) 
				{
					return (UserAccountStatus)state;
				}
				return UserAccountStatus.Approved;
			}
			set 
			{
				ViewState["PrevAccountStatus"] = value;
			}
		}

		private UserBanPeriod GetRemainingBannedDays(DateTime bannedUntil) 
		{

			UserBanPeriod daysNo = UserBanPeriod.Permanent;
			if(DateTime.Now > bannedUntil)
				return daysNo;

			int diff = ((TimeSpan) (bannedUntil - DateTime.Now)).Days;
			if(diff <= (int) UserBanPeriod.OneDay) 
			{
				daysNo = UserBanPeriod.OneDay;
			}
			else if(diff > (int) UserBanPeriod.OneDay && diff <= (int) UserBanPeriod.ThreeDays) 
			{
				daysNo = UserBanPeriod.ThreeDays;
			}
			else if(diff > (int) UserBanPeriod.ThreeDays && diff <= (int) UserBanPeriod.FiveDays) 
			{
				daysNo = UserBanPeriod.FiveDays;
			}
			else if(diff > (int) UserBanPeriod.FiveDays && diff <= (int) UserBanPeriod.OneWeek) 
			{
				daysNo = UserBanPeriod.OneWeek;
			}
			else if(diff > (int) UserBanPeriod.OneWeek && diff <= (int) UserBanPeriod.TwoWeeks) 
			{
				daysNo = UserBanPeriod.TwoWeeks;
			}
			else if(diff > (int) UserBanPeriod.TwoWeeks && diff <= (int) UserBanPeriod.OneMonth) 
			{
				daysNo = UserBanPeriod.OneMonth;
			}
			else if(diff > (int) UserBanPeriod.OneMonth) 
			{
				daysNo = UserBanPeriod.Permanent;
			}

			return daysNo;
		}

		/// <summary>
		/// Format banned date.
		/// </summary>
		private string GetBannedDateValue(ref User userToEdit) 
		{
			if (userToEdit != null && userToEdit.IsBanned) 
			{
				CSContext cntx = CSContext.Current;
				string dateFormat = cntx.User.Profile.DateFormat;
				string timeFormat = cntx.SiteSettings.TimeFormat;

				return userToEdit.BannedUntil.ToString( dateFormat + " " + timeFormat );

				/* 
				 * Don't convert to GMT anymore.
				 * 
				return Formatter.FormatDate(userToEdit.BannedUntil, true);
				*/
			} 
			else
				return ResourceManager.GetString("NotSet");
		}

		private void BindExtendedUserControls(User userToEdit)
		{
			foreach (string controlName in ExtendedUserData.Fields)
			{
				Control c  = TaskRegion.FindControl(controlName);
				if (c != null)
				{
					string value = userToEdit.GetExtendedAttribute(c.ID);

					if (c is TextBox)
						((TextBox)c).Text = value;
					else if ((c is CheckBox) && (value != string.Empty))
						((CheckBox)c).Checked = bool.Parse(value);
					else if ((c is ListControl) && (((ListControl)c).Items.FindByValue(value) != null))
						((ListControl)c).SelectedValue = value;
				}
			}
		}

		private void InitializeComponent()
		{
		
		}

		private void SetExtendedUserData(User userToEdit)
		{
			foreach (string controlName in ExtendedUserData.Fields)
			{
				Control c  = TaskRegion.FindControl(controlName);
				if (c != null)
				{
					string value = null;

					if (c is TextBox)
						value = ((TextBox)c).Text;
					else if (c is ListControl)
						value = ((ListControl)c).SelectedValue;
					else if (c is CheckBox)
						value = ((CheckBox)c).Checked.ToString();

					if (value != null)
						userToEdit.SetExtendedAttribute(c.ID, value);
				}
			}
		}
		#endregion

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -