[Bindable (false)]
public class PasswordRecovery : CompositeControl
{
+ static readonly object answerLookupErrorEvent = new object ();
+ static readonly object sendingMailEvent = new object ();
+ static readonly object sendMailErrorEvent = new object ();
+ static readonly object userLookupErrorEvent = new object ();
+ static readonly object verifyingAnswerEvent = new object ();
+ static readonly object verifyingUserEvent = new object ();
+
public static readonly string SubmitButtonCommandName = "Submit";
TableItemStyle _failureTextStyle;
string _username = null;
string _answer = null;
+ EventHandlerList events = new EventHandlerList ();
+
+#region Events
+ public event EventHandler AnswerLookupError {
+ add { events.AddHandler (answerLookupErrorEvent, value); }
+ remove { events.RemoveHandler (answerLookupErrorEvent, value); }
+ }
+
+ public event MailMessageEventHandler SendingMail {
+ add { events.AddHandler (sendingMailEvent, value); }
+ remove { events.RemoveHandler (sendingMailEvent, value); }
+ }
+
+ public event SendMailErrorEventHandler SendMailError {
+ add { events.AddHandler (sendMailErrorEvent, value); }
+ remove { events.RemoveHandler (sendMailErrorEvent, value); }
+ }
+
+ public event EventHandler UserLookupError {
+ add { events.AddHandler (userLookupErrorEvent, value); }
+ remove { events.RemoveHandler (userLookupErrorEvent, value); }
+ }
+
+ public event LoginCancelEventHandler VerifyingAnswer {
+ add { events.AddHandler (verifyingAnswerEvent, value); }
+ remove { events.RemoveHandler (verifyingAnswerEvent, value); }
+ }
+
+ public event LoginCancelEventHandler VerifyingUser {
+ add { events.AddHandler (verifyingUserEvent, value); }
+ remove { events.RemoveHandler (verifyingUserEvent, value); }
+ }
+#endregion
+
public PasswordRecovery ()
{
}
public Control QuestionTemplateContainer
{
- get
- {
- if (_questionTemplateContainer == null)
+ get {
+ if (_questionTemplateContainer == null) {
_questionTemplateContainer = new QuestionContainer (this);
+ ITemplate template = QuestionTemplate;
+ if (template != null)
+ _questionTemplateContainer.InstantiateTemplate (template);
+ }
+
return _questionTemplateContainer;
}
}
public Control SuccessTemplateContainer
{
- get
- {
- if (_successTemplateContainer == null)
+ get {
+ if (_successTemplateContainer == null) {
_successTemplateContainer = new SuccessContainer (this);
+ ITemplate template = SuccessTemplate;
+ if (template != null)
+ _successTemplateContainer.InstantiateTemplate (template);
+ }
+
return _successTemplateContainer;
}
}
{
get
{
- if (_userNameTemplateContainer == null)
+ if (_userNameTemplateContainer == null) {
_userNameTemplateContainer = new UserNameContainer (this);
+ ITemplate template = UserNameTemplate;
+ if (template != null)
+ _userNameTemplateContainer.InstantiateTemplate (template);
+ }
+
return _userNameTemplateContainer;
}
}
#endregion
- #region Events
-
- public event EventHandler AnswerLookupError;
- public event MailMessageEventHandler SendingMail;
- public event SendMailErrorEventHandler SendMailError;
- public event EventHandler UserLookupError;
- public event LoginCancelEventHandler VerifyingAnswer;
- public event LoginCancelEventHandler VerifyingUser;
-
- #endregion
-
protected internal override void CreateChildControls ()
{
ITemplate userNameTemplate = UserNameTemplate;
- if (userNameTemplate == null)
+ if (userNameTemplate == null) {
userNameTemplate = new UserNameDefaultTemplate (this);
- ((UserNameContainer) UserNameTemplateContainer).InstantiateTemplate (userNameTemplate);
-
+ ((UserNameContainer) UserNameTemplateContainer).InstantiateTemplate (userNameTemplate);
+ }
+
ITemplate questionTemplate = QuestionTemplate;
- if (questionTemplate == null)
+ if (questionTemplate == null) {
questionTemplate = new QuestionDefaultTemplate (this);
- ((QuestionContainer) QuestionTemplateContainer).InstantiateTemplate (questionTemplate);
+ ((QuestionContainer) QuestionTemplateContainer).InstantiateTemplate (questionTemplate);
+ }
ITemplate successTemplate = SuccessTemplate;
- if (successTemplate == null)
+ if (successTemplate == null) {
successTemplate = new SuccessDefaultTemplate (this);
- ((SuccessContainer) SuccessTemplateContainer).InstantiateTemplate (successTemplate);
+ ((SuccessContainer) SuccessTemplateContainer).InstantiateTemplate (successTemplate);
+ }
Controls.AddAt (0, UserNameTemplateContainer);
Controls.AddAt (1, QuestionTemplateContainer);
((UserNameContainer) UserNameTemplateContainer).FailureTextLiteral.Text = UserNameFailureText;
return;
}
-
+
+ if (!MembershipProviderInternal.RequiresQuestionAndAnswer) {
+ GenerateAndSendEmail ();
+
+ _currentStep = PasswordReciveryStep.StepSuccess;
+ return;
+ }
+
Question = user.PasswordQuestion;
_currentStep = PasswordReciveryStep.StepAnswer;
return;
}
- private void ProcessUserAnswer ()
+ void ProcessUserAnswer ()
{
LoginCancelEventArgs args = new LoginCancelEventArgs ();
OnVerifyingAnswer (args);
return;
}
+ GenerateAndSendEmail ();
+
+ _currentStep = PasswordReciveryStep.StepSuccess;
+ return;
+ }
+
+ void GenerateAndSendEmail ()
+ {
string newPassword = "";
try {
if (MembershipProviderInternal.EnablePasswordRetrieval) {
}
SendPasswordByMail (UserName, newPassword);
-
- _currentStep = PasswordReciveryStep.StepSuccess;
- return;
}
- private void InitMemberShipProvider ()
+ void InitMemberShipProvider ()
{
string mp = MembershipProvider;
_provider = (mp.Length == 0) ? _provider = Membership.Provider : Membership.Providers [mp];
throw new HttpException (Locale.GetText ("No provider named '{0}' could be found.", mp));
}
- private void SendPasswordByMail (string username, string password)
+ void SendPasswordByMail (string username, string password)
{
MembershipUser user = MembershipProviderInternal.GetUser (UserName, false);
if (user == null)
return;
+ // DO NOT change format of the message - it has to be exactly the same as in
+ // .NET as some software (e.g. YetAnotherForum) depends on it.
string messageText = "Please return to the site and log in using the following information.\n" +
- "User Name: <%USERNAME%>\nPassword: <%PASSWORD%>";
+ "User Name: <%USERNAME%>\nPassword: <%PASSWORD%>\n";
- ListDictionary dictionary = new ListDictionary ();
+ ListDictionary dictionary = new ListDictionary (StringComparer.OrdinalIgnoreCase);
dictionary.Add ("<%USERNAME%>", username);
+ dictionary.Add ("<% UserName %>", username);
dictionary.Add ("<%PASSWORD%>", password);
+ dictionary.Add ("<% Password %>", password);
MailMessage message = null;
protected virtual void OnSendingMail (MailMessageEventArgs e)
{
- if (SendingMail != null)
- SendingMail (this, e);
+ MailMessageEventHandler eh = events [sendingMailEvent] as MailMessageEventHandler;
+ if (eh != null)
+ eh (this, e);
}
protected virtual void OnSendMailError (SendMailErrorEventArgs e)
{
- if (SendMailError != null)
- SendMailError (this, e);
+ SendMailErrorEventHandler eh = events [sendingMailEvent] as SendMailErrorEventHandler;
+ if (eh != null)
+ eh (this, e);
}
protected virtual void OnUserLookupError (EventArgs e)
{
- if (UserLookupError != null)
- UserLookupError (this, e);
+ EventHandler eh = events [userLookupErrorEvent] as EventHandler;
+ if (eh != null)
+ eh (this, e);
}
protected virtual void OnVerifyingAnswer (LoginCancelEventArgs e)
{
- if (VerifyingAnswer != null)
- VerifyingAnswer (this, e);
+ LoginCancelEventHandler eh = events [verifyingAnswerEvent] as LoginCancelEventHandler;
+ if (eh != null)
+ eh (this, e);
}
protected virtual void OnVerifyingUser (LoginCancelEventArgs e)
{
- if (VerifyingUser != null)
- VerifyingUser (this, e);
+ LoginCancelEventHandler eh = events [verifyingUserEvent] as LoginCancelEventHandler;
+ if (eh != null)
+ eh (this, e);
}
#endregion
#region Private Event Handlers
- private void UserName_TextChanged (object sender, EventArgs e)
+ void UserName_TextChanged (object sender, EventArgs e)
{
UserName = ((ITextControl) sender).Text;
}
- private void Answer_TextChanged (object sender, EventArgs e)
+ void Answer_TextChanged (object sender, EventArgs e)
{
_answer = ((ITextControl) sender).Text;
}
template.InstantiateIn (_containerCell);
}
- private void InitTable ()
+ void InitTable ()
{
Attributes.Add ("ID", _owner.ID);
}
}
- private enum PasswordReciveryStep
+ enum PasswordReciveryStep
{
StepUserName,
StepAnswer,