📄 memberadmin.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
// 修改说明:增加昵称、磁盘限额等相关控件
// 修改人:宝玉
// 修改日期:2005-02-26
using System;
using System.ComponentModel;
using System.Drawing;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CommunityServer;
using CommunityServer.Components;
namespace CommunityServer.Controls {
public class MemberAdmin : TemplatedWebControl {
#region Child Controls
#region 新增内容
private TextBox nickname;
private RequiredFieldValidator nicknameValidator;
private TextBox databaseQuota;
private RequiredFieldValidator databaseQuotaValidator;
TextBox qq;
#endregion
TimezoneDropDownList timezone;
TextBox location;
TextBox occupation;
TextBox interests;
TextBox webAddress;
TextBox webLog;
TextBox signature;
TextBox privateEmail;
TextBox publicEmail;
TextBox msnIM;
TextBox aolIM;
TextBox yahooIM;
TextBox icq;
TextBox avatarUrl;
TextBox usernameEdit;
YesNoRadioButtonList enableAvatar;
RadioButtonList hideReadPosts;
YesNoRadioButtonList enableEmailTracking;
YesNoRadioButtonList displayInMemberList;
YesNoRadioButtonList enableHtmlEmail;
YesNoRadioButtonList enableEmail;
GenderRadioButtonList gender;
LanguageDropDownList language;
DateFormatDropDownList dateFormat;
DatePicker birthday;
Button updateButton;
Button avatarUpdateButton;
DateFilter defaultThreadView;
RangeValidator signatureMaxLengthValidator;
HtmlInputFile uploadedAvatar;
HtmlAnchor changePassword;
HtmlAnchor changePasswordAnswer;
ModerationLevelDropDownList moderationLevel;
YesNoRadioButtonList isAvatarApproved;
YesNoRadioButtonList forceLogin;
AccountStatusDropDownList accountStatus;
ThemeDropDownList theme;
YesNoRadioButtonList enablePostPreviewPopup;
HtmlTable userBanSection;
UserBanDropDownList userBanPeriod;
Label bannedUntilDate;
HtmlTable userApprovalSection;
YesNoRadioButtonList isApproved;
Literal dateCreated;
Literal lastLogin;
Literal lastActivity;
Literal userID;
Literal passwordFormat;
UserAvatar avatar;
HyperLink UserMyForumsLink;
HyperLink UserPrivateMessagesLink;
TextBox dummyTotalPosts;
UserBanReasonDropDownList userBanReason;
ExpanderPanel userBanExpander;
YesNoRadioButtonList unlockUser;
HtmlTableRow isLockedOutRow;
StatusMessage formStatus;
YesNoRadioButtonList enableEmoticons;
SortOrderDropDownList sortOrder;
#endregion
#region Skin
protected override void AttachChildControls()
{
CSContext csContext = CSContext.Current;
#region 新增内容
this.nickname = (TextBox) FindControl("Nickname");
this.nicknameValidator = (RequiredFieldValidator) FindControl("nicknameValidator");
this.nicknameValidator.ErrorMessage = ResourceManager.GetString("CreateNewAccount_nicknameValidator").Replace("'", @"\'");
this.databaseQuota = (TextBox) FindControl("DatabaseQuota");
this.databaseQuotaValidator = (RequiredFieldValidator) FindControl("databaseQuotaValidator");
this.databaseQuotaValidator.ErrorMessage = ResourceManager.GetString("EditProfile_databaseQuotaValidator");
qq = (TextBox) FindControl("QQ");
#endregion
usernameEdit = (TextBox)FindControl("UsernameEdit");
timezone = (TimezoneDropDownList)FindControl("Timezone");
location = (TextBox)FindControl("Location");
occupation = (TextBox)FindControl("Occupation");
interests = (TextBox)FindControl("Interests");
webAddress = (TextBox)FindControl("WebAddress");
webLog = (TextBox)FindControl("WebLog");
privateEmail = (TextBox)FindControl("PrivateEmail");
publicEmail = (TextBox)FindControl("PublicEmail");
msnIM = (TextBox)FindControl("MsnIM");
aolIM = (TextBox)FindControl("AolIM");
yahooIM = (TextBox)FindControl("YahooIM");
icq = (TextBox)FindControl("ICQ");
avatarUrl = (TextBox)FindControl("avatarUrl");
enableAvatar = (YesNoRadioButtonList)FindControl("EnableAvatar");
hideReadPosts = (RadioButtonList)FindControl("HideReadPosts");
signature = (TextBox)FindControl("Signature");
displayInMemberList = (YesNoRadioButtonList)FindControl("DisplayInMemberList");
updateButton = (Button)FindControl("UpdateButton");
avatarUpdateButton = (Button)FindControl("");
language = (LanguageDropDownList)FindControl("Language");
dateFormat = (DateFormatDropDownList)FindControl("DateFormat");
defaultThreadView = (DateFilter)FindControl("DefaultThreadView");
signatureMaxLengthValidator = (RangeValidator)FindControl("SignatureMaxLengthValidator");
uploadedAvatar = (HtmlInputFile)FindControl("AvatarUpload");
avatarUpdateButton = (Button)FindControl("SubmitAvatar");
gender = (GenderRadioButtonList)FindControl("Gender");
changePassword = (HtmlAnchor)FindControl("ChangePassword");
changePasswordAnswer = (HtmlAnchor)FindControl("ChangePasswordAnswer_CurrentAnswer");
birthday = (DatePicker)FindControl("BirthDate");
theme = (ThemeDropDownList)FindControl("Theme");
enableEmailTracking = (YesNoRadioButtonList)FindControl("EnableEmailTracking");
enableHtmlEmail = (YesNoRadioButtonList)FindControl("EnableHtmlEmail");
enableEmail = (YesNoRadioButtonList)FindControl("ReceiveEmails");
enableEmail.Enabled = CSContext.Current.SiteSettings.EnableEmail;
enablePostPreviewPopup = (YesNoRadioButtonList)FindControl("EnablePostPreviewPopup");
dateCreated = (Literal)FindControl("DateCreated");
lastLogin = (Literal)FindControl("LastLogin");
lastActivity = (Literal)FindControl("LastActivity");
userID = (Literal)FindControl( "UserID" );
passwordFormat = (Literal)FindControl( "PasswordFormat" );
moderationLevel = (ModerationLevelDropDownList)FindControl("ModerationLevel");
forceLogin = (YesNoRadioButtonList)FindControl("ForceLogin");
isAvatarApproved = (YesNoRadioButtonList)FindControl("IsAvatarApproved");
accountStatus = (AccountStatusDropDownList)FindControl("AccountStatus");
userBanSection = (HtmlTable)FindControl("UserBanSection");
userBanPeriod = (UserBanDropDownList)FindControl("UserBanPeriod");
userApprovalSection = (HtmlTable)FindControl("UserApprovalSection");
isApproved = (YesNoRadioButtonList)FindControl("IsApproved");
bannedUntilDate = (Label)FindControl("BannedUntilDate");
avatar = (UserAvatar)FindControl("Avatar");
UserMyForumsLink = (HyperLink)FindControl( "UserMyForumsLink" );
UserPrivateMessagesLink = (HyperLink)FindControl( "UserPrivateMessagesLink" );
// new controls
//
dummyTotalPosts = (TextBox) FindControl( "DummyTotalPosts" );
userBanReason = (UserBanReasonDropDownList) FindControl("UserBanReason");
userBanExpander = (ExpanderPanel) FindControl("UserBanExpander");
unlockUser = (YesNoRadioButtonList) FindControl("UnlockUser");
isLockedOutRow = (HtmlTableRow) FindControl("IsLockedOutRow");
formStatus = (StatusMessage) FindControl("formStatus");
enableEmoticons =(YesNoRadioButtonList) FindControl("EnableEmoticons");
FindControl("EmoticonRow").Visible = csContext.SiteSettings.EnableEmoticons;
sortOrder = (SortOrderDropDownList) FindControl("SortOrder");
InitializeChildControls();
}
private void InitializeChildControls() {
accountStatus.AutoPostBack = true;
accountStatus.SelectedIndexChanged += new EventHandler(AccountStatus_Changed);
updateButton.Click += new EventHandler(Update_Click);
avatarUpdateButton.Click += new EventHandler(UpdateAvatar_Click);
}
#endregion
protected override void OnLoad(EventArgs e) {
if ( !Page.IsPostBack ) {
DataBind();
}
base.OnLoad(e);
}
public override void DataBind() {
base.DataBind();
CSContext csContext = CSContext.Current;
User userToEdit = Users.GetUser(csContext.UserID, false, false);
User currentUser = CSContext.Current.User;
if( userToEdit.IsAdministrator && !currentUser.IsAdministrator)
throw new CSException(CSExceptionType.ModerateAccessDenied );
// Save actual account status
this.PrevAccountStatus = userToEdit.AccountStatus;
signatureMaxLengthValidator.ErrorMessage = string.Format( ResourceManager.GetString("EditProfile_SigMaxLength"), CSContext.Current.SiteSettings.UserSignatureMaxLength.ToString() );
// Change password link
changePassword.InnerText = ResourceManager.GetString("EditProfile_PasswordChange");
changePassword.HRef = Globals.GetSiteUrls().AdminUserPasswordChange(userToEdit.UserID);
// Change password answer link
if( changePasswordAnswer != null ) {
changePasswordAnswer.InnerText = ResourceManager.GetString("EditProfile_PasswordAnswerChange");
changePasswordAnswer.HRef = Globals.GetSiteUrls().AdminUserPasswordAnswerChange(userToEdit.UserID);
}
// Set form to the current values of logged on user
usernameEdit.Text = Globals.HtmlDecode(userToEdit.Username);
usernameEdit.Enabled = CSContext.Current.SiteSettings.EnableUsernameChange;
#region 新增内容 2005-02-26
this.nickname.Text = Globals.HtmlDecode(userToEdit.Nickname);
qq.Text = Globals.HtmlDecode(userToEdit.Profile.QQIM);
#endregion
if ( timezone.Items.FindByValue( userToEdit.Profile.Timezone.ToString() ) != null)
{
timezone.Items.FindByValue( userToEdit.Profile.Timezone.ToString() ).Selected = true;
}
// Find controls for Avatar/Post section
//
if ( (userToEdit.HasAvatar) && (userToEdit.EnableAvatar) && (userToEdit.IsAvatarApproved) ) {
avatar.User = userToEdit;
avatar.Visible = true;
}
// If the admin has turned on post preview popups then we can turn it on
if ( enablePostPreviewPopup != null ) {
if ( CSContext.Current.SiteSettings.EnablePostPreviewPopup ) {
enablePostPreviewPopup.SelectedValue = userToEdit.Profile.EnablePostPreviewPopup;
enablePostPreviewPopup.Enabled = true;
} else {
FindControl( "EnablePostPreviewPopupRow" ).Visible = false;
}
}
location.Text = Globals.HtmlDecode(userToEdit.Profile.Location);
occupation.Text = Globals.HtmlDecode(userToEdit.Profile.Occupation);
interests.Text = Globals.HtmlDecode(userToEdit.Profile.Interests);
webAddress.Text = Globals.HtmlDecode(userToEdit.Profile.WebAddress);
webLog.Text = Globals.HtmlDecode(userToEdit.Profile.WebLog);
signature.Text = Globals.HtmlDecode(userToEdit.Profile.Signature);
privateEmail.Text = userToEdit.Email;
publicEmail.Text = Globals.HtmlDecode(userToEdit.Profile.PublicEmail);
msnIM.Text = Globals.HtmlDecode(userToEdit.Profile.MsnIM);
aolIM.Text = Globals.HtmlDecode(userToEdit.Profile.AolIM);
yahooIM.Text = Globals.HtmlDecode(userToEdit.Profile.YahooIM);
icq.Text = Globals.HtmlDecode(userToEdit.Profile.IcqIM);
avatarUrl.Text = Globals.HtmlDecode(userToEdit.AvatarUrl);
if ( birthday != null ) {
birthday.SelectedDate = userToEdit.Birthday; // 修改
}
theme.SelectedValue = userToEdit.Theme;
// Set the gender
// 修改BUG
// gender.Items.FindByValue( ((int) userToEdit.Profile.Gender).ToString() ).Selected = true; //修改前
gender.SelectedValue = userToEdit.Profile.Gender; //修改后
// Language Drop Down List
if (language.Items.FindByValue( userToEdit.Profile.Language ) != null)
language.Items.FindByValue( userToEdit.Profile.Language ).Selected = true;
if (dateFormat.Items.FindByValue( userToEdit.Profile.DateFormat ) != null)
dateFormat.Items.FindByValue( userToEdit.Profile.DateFormat ).Selected = true;
enableAvatar.SelectedValue = userToEdit.EnableAvatar;
enableEmailTracking.SelectedValue = userToEdit.EnableThreadTracking;
enableHtmlEmail.SelectedValue = userToEdit.EnableHtmlEmail;
enableEmail.SelectedValue = userToEdit.EnableEmail;
displayInMemberList.SelectedValue = userToEdit.EnableDisplayInMemberList;
enableEmoticons.SelectedValue = userToEdit.Profile.EnableEmoticons;
if (sortOrder.Items.FindByValue( ((int)userToEdit.PostSortOrder).ToString() ) != null)
sortOrder.Items.FindByValue( ((int)userToEdit.PostSortOrder).ToString() ).Selected = true;
dateCreated.Text = CSContext.Current.User.GetTimezone( userToEdit.DateCreated ).ToString( CSContext.Current.User.Profile.DateFormat );
lastLogin.Text = CSContext.Current.User.GetTimezone( userToEdit.LastLogin ).ToString( CSContext.Current.User.Profile.DateFormat );
lastActivity.Text = CSContext.Current.User.GetTimezone( userToEdit.LastActivity ).ToString( CSContext.Current.User.Profile.DateFormat );
#region Administrator Area
userID.Text = userToEdit.UserID.ToString();
if (userToEdit.Member != null) {
unlockUser.SelectedValue = !userToEdit.Member.IsLockedOut;
isLockedOutRow.Visible = userToEdit.Member.IsLockedOut;
}
passwordFormat.Text = userToEdit.PasswordFormat.ToString();
moderationLevel.SelectedValue = userToEdit.ModerationLevel;
dummyTotalPosts.Text = userToEdit.DummyTotalPosts.ToString();
// 2005-02-26: 新增磁盘限额
this.databaseQuota.Text = userToEdit.DatabaseQuota.ToString();
forceLogin.SelectedValue = userToEdit.ForceLogin;
isAvatarApproved.SelectedValue = userToEdit.IsAvatarApproved;
// Account Status
accountStatus.SelectedValue = userToEdit.AccountStatus;
// User Banning
userBanSection.Visible = (userToEdit.AccountStatus == UserAccountStatus.Banned) ? true : false;
userBanExpander.Visible = (userToEdit.AccountStatus == UserAccountStatus.Banned) ? true : false;
userBanExpander.Collapsed = (userToEdit.AccountStatus == UserAccountStatus.Banned) ? false : true;
bannedUntilDate.Text = this.GetBannedDateValue(ref userToEdit);
// LN: 5/21/04 : Added to signal admin that a user's ban has expired.
if (userToEdit.IsBanned && DateTime.Now > userToEdit.BannedUntil) {
bannedUntilDate.Text += ResourceManager.GetString("EditProfile_BanExpired");
bannedUntilDate.ForeColor = System.Drawing.Color.Red;
}
userBanPeriod.SelectedValue = this.GetRemainingBannedDays(userToEdit.BannedUntil);
userBanReason.SelectedValue = userToEdit.BanReason;
// User Approval
userApprovalSection.Visible = (userToEdit.AccountStatus == UserAccountStatus.ApprovalPending) ? true : false;
isApproved.SelectedValue = (userToEdit.AccountStatus == UserAccountStatus.Approved) ? true : false;
#endregion
updateButton.Text = CommunityServer.Components.ResourceManager.GetString("EditProfile_Update");
avatarUpdateButton.Text = CommunityServer.Components.ResourceManager.GetString("Update");
formStatus.Visible = false;
}
#region Event Handlers
public void AccountStatus_Changed(Object sender, EventArgs e) {
User userToEdit = Users.GetUser(CSContext.Current.UserID, false, false);
// User Approval
if (userApprovalSection != null) {
// show/hide the "Approve User" section
//
switch (userToEdit.AccountStatus) {
case (UserAccountStatus.ApprovalPending):
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -