📄 changepasswordanswer.cs
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
// Copyright (c) Telligent Systems Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CommunityServer;
using CommunityServer.Components;
using System.ComponentModel;
using System.IO;
namespace CommunityServer.Controls {
/// <summary>
/// This Web control helps to change old user's secret question and answer.
/// </summary>
[
ParseChildren(true)
]
public class ChangePasswordAnswer : SkinnedWebControl {
#region Member variables and contructor
CSContext csContext = CSContext.Current;
string skinFilename = "Skin-ChangePasswordAnswer.ascx";
TextBox currentAnswer;
TextBox newAnswer1;
TextBox newAnswer2;
RequiredFieldValidator newAnswerValidator;
CompareValidator newAnswerCompareVadlidator;
RequiredFieldValidator validateAnswer2;
Button changeAnswerButton;
RegularExpressionValidator answerRegexValidator;
RegularExpressionValidator answer1RegrexValidator;
Label currentQuestion;
QuestionsDropDownList newQuestion;
Label userName;
Panel showCurrentPasswordAnswer;
User user = null;
// *********************************************************************
// ChangePassword
//
/// <summary>
/// Constructor
/// </summary>
// ***********************************************************************/
public ChangePasswordAnswer() : base()
{
// Assign a default template name
if (SkinFilename == null)
SkinFilename = skinFilename;
if (csContext.UserID > 0 && csContext.User.IsForumAdministrator) {
// Change passwd from admin
user = Users.GetUser(csContext.UserID, true);
}
else {
// Change the user's password
user = csContext.User;
}
}
#endregion
#region Initialize skin
// *********************************************************************
// Initializeskin
//
/// <summary>
/// Initialize the control template and populate the control with values
/// </summary>
// ***********************************************************************/
override protected void InitializeSkin(Control skin) {
userName = (Label) skin.FindControl("UserName");
if (csContext.UserID > 0 && csContext.User.IsForumAdministrator) {
userName.Text = "- (" + user.Username + ")";
}
// Find the textbox controls
//
if ( (user.UserID != CSContext.Current.User.UserID) && (csContext.User.IsForumAdministrator || csContext.User.IsAdministrator) ) {
showCurrentPasswordAnswer = (Panel) skin.FindControl("showCurrentPasswordAnswer");
showCurrentPasswordAnswer.Visible = false;
} else {
showCurrentPasswordAnswer = (Panel) skin.FindControl("showCurrentPasswordAnswer");
showCurrentPasswordAnswer.Visible = true;
currentQuestion = (Label) skin.FindControl("CurrentQuestion");
currentAnswer = (TextBox) skin.FindControl("Answer");
answerRegexValidator = (RegularExpressionValidator) skin.FindControl("AnswerRegexValidator");
answerRegexValidator.ErrorMessage = ResourceManager.GetString("ChangePasswordAnswer_RegExInvalidAnswer");
}
// Find the textbox controls
//
newAnswer1 = (TextBox) skin.FindControl("NewAnswer1");
newAnswer2 = (TextBox) skin.FindControl("NewAnswer2");
// Find the validators
//
newAnswerValidator = (RequiredFieldValidator) skin.FindControl("ValidateAnswer1");
newAnswerValidator.ErrorMessage = ResourceManager.GetString("ChangePasswordAnswer_NewAnswerRequired");
answer1RegrexValidator = (RegularExpressionValidator) skin.FindControl("Answer1RegrexValidator");
answer1RegrexValidator.ErrorMessage = ResourceManager.GetString("ChangePasswordAnswer_RegExInvalidAnswer1");
newAnswerCompareVadlidator = (CompareValidator) skin.FindControl("CompareAnswer");
newAnswerCompareVadlidator.ErrorMessage = ResourceManager.GetString("ChangePasswordAnswer_ReEnterNewAnswerRequired");
validateAnswer2 = (RequiredFieldValidator) skin.FindControl("ValidateAnswer2");
validateAnswer2.ErrorMessage = ResourceManager.GetString("ChangePasswordAnswer_ReEnterAnswerRequired");
newQuestion = (QuestionsDropDownList) skin.FindControl("NewQuestion");
try {
if (user.PasswordQuestion == string.Empty ||
user.PasswordQuestion == null) {
showCurrentPasswordAnswer.Visible = false;
currentQuestion.Text = ResourceManager.GetString("ChangePasswordAnswer_NotAvailable");
currentQuestion.ForeColor = System.Drawing.Color.Red;
} else {
currentQuestion.Text = user.PasswordQuestion;
currentQuestion.Font.Bold = true;
}
} catch {}
changeAnswerButton = (Button) skin.FindControl("ChangeAnswerButton");
changeAnswerButton.Text = ResourceManager.GetString("ChangePasswordAnswer_ChangeAnswer");
changeAnswerButton.Click += new EventHandler(ChangePasswordAnswer_Click);
// panic code :D
if (csContext.User.IsForumAdministrator && csContext.UserID == 0)
changeAnswerButton.Enabled = false;
}
#endregion
#region Events
void ChangePasswordAnswer_Click (Object sender, EventArgs e) {
bool status = false;
string currAnswer = "";
if (currentAnswer != null)
if (currentAnswer.Text != "")
currAnswer = currentAnswer.Text;
if (!Page.IsValid)
return;
if (user != null)
status = user.ChangePasswordAnswer(currAnswer, newQuestion.SelectedValue, newAnswer1.Text);
if (status) {
throw new CSException(CSExceptionType.UserPasswordAnswerChangeSuccess);
} else {
throw new CSException(CSExceptionType.UserPasswordAnswerChangeFailed);
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -