📄 useredit.aspx.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.ControlPanel.Controls;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using CommunityServer.Discussions.Components;
using TWC = Telligent.Web.UI;
using ResourceLinkButton = CommunityServer.ControlPanel.Controls.ResourceLinkButton;
using StatusMessage = CommunityServer.ControlPanel.Controls.StatusMessage;
namespace CommunityServer.ControlPanel.Membership
{
/// <summary>
/// Summary description for UserEdit.
/// </summary>
public class UserEdit : BaseMembershipPage
{
#region Child Controls
protected StatusMessage anonymousWarning;
protected MPContent TaskRegion;
protected TWC.TabbedPanes UserEditTabs;
protected TimezoneDropDownList timezone;
protected TextBox location;
protected TextBox occupation;
protected TextBox interests;
protected TextBox webAddress;
protected TextBox webLog;
protected TextBox webGallery;
protected TextBox signature;
protected TextBox privateEmail;
protected TextBox publicEmail;
protected TextBox msnIM;
protected TextBox aolIM;
protected TextBox yahooIM;
protected TextBox icq;
protected TextBox avatarUrl;
protected TextBox usernameEdit;
protected YesNoRadioButtonList enableAvatar;
protected RadioButtonList hideReadPosts;
protected YesNoRadioButtonList enableEmailTracking;
protected YesNoRadioButtonList displayInMemberList;
protected YesNoRadioButtonList enableHtmlEmail;
protected YesNoRadioButtonList enableEmail;
protected YesNoRadioButtonList enableInk;
protected GenderRadioButtonList gender;
protected LanguageDropDownList language;
protected DateFormatDropDownList dateFormat;
protected DatePickerToggle birthday;
protected ResourceLinkButton updateButton;
protected Button avatarUpdateButton;
protected DateFilter defaultThreadView;
protected RangeValidator signatureMaxLengthValidator;
protected HtmlInputFile uploadedAvatar;
protected HtmlAnchor changeUserName;
protected HtmlAnchor changePassword;
protected HtmlAnchor changeRoles;
protected ModerationLevelDropDownList moderationLevel;
protected YesNoRadioButtonList isAvatarApproved;
protected YesNoRadioButtonList forceLogin;
protected YesNoRadioButtonList isIgnored;
protected AccountStatusDropDownList accountStatus;
protected ThemeDropDownList theme;
protected YesNoRadioButtonList enablePostPreviewPopup;
protected HtmlTable userBanSection;
protected UserBanDropDownList userBanPeriod;
protected Label bannedUntilDate;
protected HtmlTable userApprovalSection;
protected YesNoRadioButtonList isApproved;
protected Literal dateCreated;
protected Literal lastLogin;
protected Literal lastActivity;
protected Literal userID;
protected UserAvatar avatar;
protected HyperLink UserMyForumsLink;
protected HyperLink UserPrivateMessagesLink;
protected TextBox dummyTotalPosts;
protected UserBanReasonDropDownList userBanReason;
protected YesNoRadioButtonList unlockUser;
protected HtmlTableRow isLockedOutRow;
protected HtmlTableRow EnablePostPreviewPopupRow;
protected StatusMessage formStatus;
protected YesNoRadioButtonList enableEmoticons;
protected SortOrderDropDownList sortOrder;
protected TextBox bio;
protected TextBox CommonName;
protected YesNoRadioButtonList enableDisplayNames;
protected YesNoRadioButtonList enableUserSignatures;
protected YesNoRadioButtonList enableUserAvtars;
protected FontSizeDropDownList FontSize;
protected DropDownList EditorList;
protected YesNoRadioButtonList EnableCollapsingPanels;
protected ControlPanelSelectedNavigation SelectedNavigation1;
protected Modal Modal1;
protected MPContent DescriptionRegion;
protected MPContainer MPContainer;
protected Literal PanelDescription;
#endregion
override protected void OnInit(EventArgs e)
{
this.accountStatus.SelectedIndexChanged += new EventHandler(this.AccountStatus_Changed);
this.updateButton.Click += new EventHandler(this.Update_Click);
this.avatarUpdateButton.Click += new EventHandler(this.UpdateAvatar_Click);
this.Load += new EventHandler(this.Page_Load);
base.OnInit(e);
}
private void Page_Load(object sender, EventArgs e)
{
if ( !Page.IsPostBack )
{
Bind();
}
}
public void Bind()
{
CSContext csContext = CSContext.Current;
User userToEdit = Users.GetUser(csContext.UserID, false, false);
User currentUser = csContext.User;
if( userToEdit.IsAdministrator && !currentUser.IsAdministrator)
throw new CSException(CSExceptionType.ModerateAccessDenied );
// Warn admins about editing the Anonymous user
if (userToEdit.IsAnonymous)
{
anonymousWarning.ResourceName = "CP_UserEdit_AnonymousWarning";
anonymousWarning.Success = false;
anonymousWarning.Visible = true;
// HACK: set this as license message to enable warning icon
anonymousWarning.IsLicenseMessage = true;
}
// Save actual account status
this.PrevAccountStatus = userToEdit.AccountStatus;
// Set Title
PanelDescription.Text = String.Format(ResourceManager.GetString("CP_UserEdit_TitleFormatString", controlPanelResourceFile), userToEdit.Username);
signatureMaxLengthValidator.ErrorMessage = string.Format( Components.ResourceManager.GetString("EditProfile_SigMaxLength"), csContext.SiteSettings.UserSignatureMaxLength.ToString() );
// Change username link
changeUserName.InnerText = Components.ResourceManager.GetString("CP_UserEdit_ChangeUserName");
changeUserName.HRef = String.Format("javascript:Telligent_Modal.Open('{0}', 500, 225, null);", Globals.GetSiteUrls().ControlPanelUserName(userToEdit.UserID));
// Change password link
changePassword.InnerText = Components.ResourceManager.GetString("CP_UserEdit_ChangePassword");
changePassword.HRef = String.Format("javascript:Telligent_Modal.Open('{0}', 500, 175, null);", Globals.GetSiteUrls().ControlPanelUserPassword(userToEdit.UserID));
// Add/Edit Roles link
changeRoles.InnerText = Components.ResourceManager.GetString("CP_UserEdit_ChangeRoles");
changeRoles.HRef = String.Format("javascript:Telligent_Modal.Open('{0}', 500, 350, null);", Globals.GetSiteUrls().ControlPanelUserRoles(userToEdit.UserID));
// Set form to the current values of logged on user
usernameEdit.Text = userToEdit.CommonNameOrUserName;
usernameEdit.Enabled = csContext.SiteSettings.EnableUsernameChange;
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 ( ForumConfiguration.Instance().EnablePostPreviewPopup )
{
enablePostPreviewPopup.SelectedValue = userToEdit.Profile.EnablePostPreviewPopup;
enablePostPreviewPopup.Enabled = true;
}
else
{
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);
webGallery.Text = Globals.HtmlDecode(userToEdit.Profile.WebGallery);
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);
bio.Text = Globals.HtmlDecode(userToEdit.Profile.Bio);
CommonName.Text = Globals.HtmlDecode(userToEdit.Profile.CommonName);
enableDisplayNames.SelectedValue = userToEdit.EnableDisplayName;
enableUserSignatures.SelectedValue = userToEdit.EnableUserSignatures;
enableUserAvtars.SelectedValue = userToEdit.EnableUserAvtars;
if ( birthday != null )
{
birthday.SelectedDate = userToEdit.Profile.BirthDate;
}
theme.SelectedValue = userToEdit.Theme;
// Set the gender
gender.Items.FindByValue( ((int) userToEdit.Profile.Gender).ToString() ).Selected = true;
// 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;
enableInk.SelectedValue = userToEdit.EnableInk;
displayInMemberList.SelectedValue = userToEdit.EnableDisplayInMemberList;
FontSize.SelectedValue = userToEdit.Profile.FontSize.ToString();
enableEmoticons.SelectedValue = userToEdit.Profile.EnableEmoticons;
if (EnableCollapsingPanels.Items.FindByValue( userToEdit.EnableCollapsingPanels.ToString() ) != null)
EnableCollapsingPanels.Items.FindByValue( userToEdit.EnableCollapsingPanels.ToString() ).Selected = true;
if (sortOrder.Items.FindByValue( ((int)userToEdit.PostSortOrder).ToString() ) != null)
sortOrder.Items.FindByValue( ((int)userToEdit.PostSortOrder).ToString() ).Selected = true;
dateCreated.Text = csContext.User.GetTimezone( userToEdit.DateCreated ).ToString( csContext.User.Profile.DateFormat );
lastLogin.Text = csContext.User.GetTimezone( userToEdit.LastLogin ).ToString( csContext.User.Profile.DateFormat );
lastActivity.Text = csContext.User.GetTimezone( userToEdit.LastActivity ).ToString( csContext.User.Profile.DateFormat );
// Editor
foreach (SelectableEditor ei in csContext.Config.Editors)
EditorList.Items.Add( new ListItem(ei.Name,ei.Name) );
ListItem li = EditorList.Items.FindByValue(userToEdit.EditorType);
if (li != null)
li.Selected = true;
BindExtendedUserControls(userToEdit);
#region Administrator Area
userID.Text = userToEdit.UserID.ToString();
if (userToEdit.Member != null)
{
unlockUser.SelectedValue = !userToEdit.Member.IsLockedOut;
isLockedOutRow.Visible = userToEdit.Member.IsLockedOut;
}
moderationLevel.SelectedValue = userToEdit.ModerationLevel;
dummyTotalPosts.Text = userToEdit.DummyTotalPosts.ToString();
forceLogin.SelectedValue = userToEdit.ForceLogin;
isAvatarApproved.SelectedValue = userToEdit.IsAvatarApproved;
isIgnored.SelectedValue = userToEdit.IsIgnored;
// Account Status
accountStatus.DataBind();
accountStatus.SelectedValue = userToEdit.AccountStatus;
// User Banning
bool isBanTabVisible = (userToEdit.AccountStatus == UserAccountStatus.Banned) ? true : false;
UserEditTabs.Panes[5].Visible = isBanTabVisible;
userBanSection.Visible = isBanTabVisible;
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 += Components.ResourceManager.GetString("EditProfile_BanExpired");
bannedUntilDate.ForeColor = 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
avatarUpdateButton.Text = 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):
userApprovalSection.Visible = true;
break;
default:
userApprovalSection.Visible = false;
break;
}
}
// User Banning (keep this code after Approval code)
if (userBanSection != null)
{
bool isBanTabVisible = (accountStatus.SelectedValue == UserAccountStatus.Banned) ? true : false;
UserEditTabs.Panes[5].Visible = isBanTabVisible;
userBanSection.Visible = isBanTabVisible;
}
}
public void UpdateAvatar_Click (Object sender, EventArgs e)
{
try
{
UpdateAvatar( CSContext.Current.UserID );
}
catch
{
throw new CSException(CSExceptionType.UnknownError);
}
Update_Click(sender, e);
}
public void Update_Click (Object sender, EventArgs e)
{
if ( AreValuesValid )
{
User userToEdit = Users.GetUserWithWriteableProfile(CSContext.Current.UserID, null,false);
if (Update( userToEdit ))
{
formStatus.Success = true;
formStatus.Visible = true;
formStatus.ResourceName = "CP_Config_OK";
}
}
}
#endregion
#region Command Implementors
protected virtual bool Update( User userToEdit )
{
bool hasBanned = false;
bool hasBanBeenUsed = false;
bool postModerationChanged = false;
bool hasModerated = false;
bool hasIgnored = false;
bool hasIgnoredChanged = false;
// Get the updated values from the form
//
CSContext cntx = CSContext.Current;
if (cntx.SiteSettings.EnableUsernameChange)
userToEdit.Username = usernameEdit.Text;
// Update gender?
if (cntx.SiteSettings.AllowGender)
{
userToEdit.Profile.Gender = (Gender) int.Parse(gender.SelectedItem.Value);
}
userToEdit.Profile.Timezone = double.Parse(timezone.SelectedItem.Value);
userToEdit.Profile.Location = location.Text;
userToEdit.Profile.Occupation = occupation.Text;
userToEdit.Profile.Interests = interests.Text;
userToEdit.Profile.WebAddress = webAddress.Text;
userToEdit.Profile.WebLog = webLog.Text;
userToEdit.Profile.WebGallery = webGallery.Text;
userToEdit.Profile.Bio = bio.Text;
userToEdit.Profile.CommonName = CommonName.Text;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -