📄 memberadmin.cs
字号:
userApprovalSection.Visible = true;
break;
default:
userApprovalSection.Visible = false;
break;
}
}
// User Banning (keep this code after Approval code)
if (userBanSection != null) {
userBanSection.Visible = (accountStatus.SelectedValue == UserAccountStatus.Banned) ? true : false;
userBanExpander.Visible = (accountStatus.SelectedValue == UserAccountStatus.Banned) ? true : false;
userBanExpander.Collapsed = false;
}
}
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 ))
Globals.RedirectSiteUrl("admin_User_List");
}
}
#endregion
#region Command Implementors
protected virtual bool Update( User userToEdit ) {
bool hasBanned = false;
bool hasBanBeenUsed = false;
bool postModerationChanged = false;
bool hasModerated = false;
// Get the updated values from the form
//
if (CSContext.Current.SiteSettings.EnableUsernameChange)
userToEdit.Username = usernameEdit.Text;
// Update gender?
// 修改为控件默认属性
if (CSContext.Current.SiteSettings.AllowGender)
userToEdit.Profile.Gender = gender.SelectedValue;
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.Signature = signature.Text;
if(CSContext.Current.SiteSettings.EnableCensorship)
{
userToEdit.Profile.SignatureFormatted = Transforms.CensorPost(signature.Text);
}
else
{
userToEdit.Profile.SignatureFormatted = signature.Text;
}
#region 新增内容
userToEdit.Nickname = nickname.Text.Trim();
userToEdit.Profile.QQIM = qq.Text.Trim();
try
{
userToEdit.DatabaseQuota = int.Parse(databaseQuota.Text); // 新增内容——用户磁盘限额
}
catch{
}
#endregion
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( !CSContext.Current.SiteSettings.EnableEmail ) {
userToEdit.EnableThreadTracking = false;
userToEdit.EnableEmail = false;
}
userToEdit.EnableDisplayInMemberList = displayInMemberList.SelectedValue;
userToEdit.EnableHtmlEmail = enableHtmlEmail.SelectedValue;
userToEdit.Profile.Language = language.SelectedItem.Value;
if (enablePostPreviewPopup != null && CSContext.Current.SiteSettings.EnablePostPreviewPopup) {
userToEdit.Profile.EnablePostPreviewPopup = enablePostPreviewPopup.SelectedValue;
}
if (birthday != null)
{
userToEdit.Profile.BirthDate = birthday.SelectedDate;
userToEdit.Birthday = 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;
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;
}
}
#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;
}
// 昵称不能重复
else if (ex.CreateUserStatus == CreateUserStatus.DuplicateNickname)
{
formStatus.Success = false;
formStatus.Visible = true;
formStatus.ResourceName = "EditProfile_DuplicateNickname";
return false;
}
throw;
}
// Log Audit: ban/unban, moderate/unmoderate
//
Audit.SaveUserAuditEvent( ModerateUserSetting.UserEdited, userToEdit, CSContext.Current.User.UserID );
if (hasBanBeenUsed) {
if (hasBanned)
Audit.SaveUserAuditEvent( ModerateUserSetting.UserBanned, userToEdit, CSContext.Current.User.UserID );
else
Audit.SaveUserAuditEvent( ModerateUserSetting.UserUnbanned, userToEdit, CSContext.Current.User.UserID );
}
if (postModerationChanged) {
if (hasModerated)
Audit.SaveUserAuditEvent( ModerateUserSetting.UserModerated, userToEdit, CSContext.Current.User.UserID );
else
Audit.SaveUserAuditEvent( ModerateUserSetting.UserUnmoderated, userToEdit, CSContext.Current.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, CSContext.Current.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 && diff <= (int) UserBanPeriod.Permanent) {
daysNo = UserBanPeriod.Permanent;
}
return daysNo;
}
private string GetBannedDateValue(ref User userToEdit) {
if(userToEdit != null && userToEdit.IsBanned)
return Formatter.FormatDate(userToEdit.BannedUntil, true);
else
return ResourceManager.GetString("NotSet");
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -