Merge pull request #1506 from akoeplinger/fix-paste-test
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / ChangePassword.cs
1 //
2 // System.Web.UI.WebControls.ChangePassword.cs
3 //
4 // Authors:
5 //      Igor Zelmanovich (igorz@mainsoft.com)
6 //      Vladimir Krasnov (vladimirk@mainsoft.com)
7 //
8 // (C) 2006 Mainsoft, Inc (http://www.mainsoft.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.Web.Security;
32 using System.Collections.Generic;
33 using System.Collections.Specialized;
34 using System.Drawing;
35 using System.Text;
36 using System.ComponentModel;
37 using System.Collections;
38 using System.Net.Mail;
39
40 namespace System.Web.UI.WebControls
41 {
42         [Bindable (true)]
43         [DefaultEvent ("ChangedPassword")]
44         [Designer ("System.Web.UI.Design.WebControls.ChangePasswordDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
45         public class ChangePassword : CompositeControl, INamingContainer
46                 , IRenderOuterTable
47         {
48                 static readonly object cancelButtonClickEvent = new object ();
49                 static readonly object changedPasswordEvent = new object ();
50                 static readonly object changePasswordErrorEvent = new object ();
51                 static readonly object changingPasswordEvent = new object ();
52                 static readonly object continueButtonClickEvent = new object ();
53                 static readonly object sendingMailEvent = new object ();
54                 static readonly object sendMailErrorEvent = new object ();
55                 
56                 public static readonly string CancelButtonCommandName = "Cancel";
57                 public static readonly string ChangePasswordButtonCommandName = "ChangePassword";
58                 public static readonly string ContinueButtonCommandName = "Continue";
59                 bool renderOuterTable = true;
60                 Style _cancelButtonStyle = null;
61                 Style _changePasswordButtonStyle = null;
62                 Style _continueButtonStyle = null;
63                 TableItemStyle _failureTextStyle = null;
64                 TableItemStyle _hyperLinkStyle = null;
65                 TableItemStyle _instructionTextStyle = null;
66                 TableItemStyle _labelStyle = null;
67                 TableItemStyle _passwordHintStyle = null;
68                 TableItemStyle _successTextStyle = null;
69                 Style _textBoxStyle = null;
70                 TableItemStyle _titleTextStyle = null;
71                 Style _validatorTextStyle = null;
72
73                 MailDefinition _mailDefinition = null;
74                 MembershipProvider _provider = null;
75
76                 ITemplate _changePasswordTemplate = null;
77                 ITemplate _successTemplate = null;
78
79                 Control _changePasswordTemplateContainer = null;
80                 Control _successTemplateContainer = null;
81
82                 string _username = null;
83                 string _currentPassword = null;
84                 string _newPassword = null;
85                 string _newPasswordConfirm = null;
86
87                 bool _showContinue = false;
88
89                 EventHandlerList events = new EventHandlerList ();
90                 
91 #region Public Events
92                 public event EventHandler CancelButtonClick {
93                         add { events.AddHandler (cancelButtonClickEvent, value); }
94                         remove { events.RemoveHandler (cancelButtonClickEvent, value); }
95                 }
96                 
97                 public event EventHandler ChangedPassword {
98                         add { events.AddHandler (changedPasswordEvent, value); }
99                         remove { events.RemoveHandler (changedPasswordEvent, value); }
100                 }
101                 
102                 public event EventHandler ChangePasswordError {
103                         add { events.AddHandler (changePasswordErrorEvent, value); }
104                         remove { events.RemoveHandler (changePasswordErrorEvent, value); }
105                 }
106                 
107                 public event LoginCancelEventHandler ChangingPassword {
108                         add { events.AddHandler (changingPasswordEvent, value); }
109                         remove { events.RemoveHandler (changingPasswordEvent, value); }
110                 }
111                 
112                 public event EventHandler ContinueButtonClick {
113                         add { events.AddHandler (continueButtonClickEvent, value); }
114                         remove { events.RemoveHandler (continueButtonClickEvent, value); }
115                 }
116                 
117                 public event MailMessageEventHandler SendingMail {
118                         add { events.AddHandler (sendingMailEvent, value); }
119                         remove { events.RemoveHandler (sendingMailEvent, value); }
120                 }
121                 
122                 public event SendMailErrorEventHandler SendMailError {
123                         add { events.AddHandler (sendMailErrorEvent, value); }
124                         remove { events.RemoveHandler (sendMailErrorEvent, value); }
125                 }
126 #endregion
127                         
128                 #region Public Properties
129
130                 [DefaultValue (1)]
131                 public virtual int BorderPadding {
132                         get { return ViewState.GetInt ("BorderPadding", 1); }
133                         set {
134                                 if (value < -1)
135                                         throw new ArgumentOutOfRangeException ();
136                                 ViewState ["BorderPadding"] = value;
137                         }
138                 }
139
140                 [DefaultValue ("")]
141                 [UrlProperty]
142                 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
143                 public virtual string CancelButtonImageUrl {
144                         get { return ViewState.GetString ("CancelButtonImageUrl", String.Empty); }
145                         set { ViewState ["CancelButtonImageUrl"] = value; }
146                 }
147
148                 [DefaultValue (null)]
149                 [PersistenceMode (PersistenceMode.InnerProperty)]
150                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
151                 [NotifyParentProperty (true)]
152                 public Style CancelButtonStyle {
153                         get {
154                                 if (_cancelButtonStyle == null) {
155                                         _cancelButtonStyle = new Style ();
156                                         if (IsTrackingViewState)
157                                                 _cancelButtonStyle.TrackViewState ();
158                                 }
159                                 return _cancelButtonStyle;
160                         }
161                 }
162
163                 [Localizable (true)]
164                 public virtual string CancelButtonText {
165                         get { return ViewState.GetString ("CancelButtonText", "Cancel"); }
166                         set { ViewState ["CancelButtonText"] = value; }
167                 }
168
169                 [DefaultValue (ButtonType.Button)]
170                 public virtual ButtonType CancelButtonType {
171                         get { return ViewState ["CancelButtonType"] == null ? ButtonType.Button : (ButtonType) ViewState ["CancelButtonType"]; }
172                         set { ViewState ["CancelButtonType"] = value; }
173                 }
174
175                 [Themeable (false)]
176                 [DefaultValue ("")]
177                 [UrlProperty]
178                 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
179                 public virtual string CancelDestinationPageUrl {
180                         get { return ViewState.GetString ("CancelDestinationPageUrl", String.Empty); }
181                         set { ViewState ["CancelDestinationPageUrl"] = value; }
182                 }
183
184                 [DefaultValue ("")]
185                 [UrlProperty]
186                 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
187                 public virtual string ChangePasswordButtonImageUrl {
188                         get { return ViewState.GetString ("ChangePasswordButtonImageUrl", String.Empty); }
189                         set { ViewState ["ChangePasswordButtonImageUrl"] = value; }
190                 }
191
192                 [DefaultValue ("")]
193                 [PersistenceMode (PersistenceMode.InnerProperty)]
194                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
195                 [NotifyParentProperty (true)]
196                 public Style ChangePasswordButtonStyle {
197                         get {
198                                 if (_changePasswordButtonStyle == null) {
199                                         _changePasswordButtonStyle = new Style ();
200                                         if (IsTrackingViewState)
201                                                 _changePasswordButtonStyle.TrackViewState ();
202                                 }
203                                 return _changePasswordButtonStyle;
204                         }
205                 }
206
207                 [Localizable (true)]
208                 public virtual string ChangePasswordButtonText {
209                         get { return ViewState.GetString ("ChangePasswordButtonText", "Change Password"); }
210                         set { ViewState ["ChangePasswordButtonText"] = value; }
211                 }
212
213                 [DefaultValue (ButtonType.Button)]
214                 public virtual ButtonType ChangePasswordButtonType {
215                         get { return ViewState ["ChangePasswordButtonType"] == null ? ButtonType.Button : (ButtonType) ViewState ["ChangePasswordButtonType"]; }
216                         set { ViewState ["ChangePasswordButtonType"] = value; }
217                 }
218
219                 [Localizable (true)]
220                 public virtual string ChangePasswordFailureText {
221                         get { return ViewState.GetString ("ChangePasswordFailureText", "Your attempt to change passwords was unsuccessful. Please try again."); }
222                         set { ViewState ["ChangePasswordFailureText"] = value; }
223                 }
224
225                 [Browsable (false)]
226                 [PersistenceMode (PersistenceMode.InnerProperty)]
227                 [TemplateContainer (typeof (ChangePassword))]
228                 public virtual ITemplate ChangePasswordTemplate {
229                         get { return _changePasswordTemplate; }
230                         set { _changePasswordTemplate = value; }
231                 }
232
233                 [Browsable (false)]
234                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
235                 public Control ChangePasswordTemplateContainer {
236                         get {
237                                 if (_changePasswordTemplateContainer == null)
238                                         _changePasswordTemplateContainer = new ChangePasswordContainer (this);
239                                 return _changePasswordTemplateContainer;
240                         }
241                 }
242
243                 [Localizable (true)]
244                 public virtual string ChangePasswordTitleText {
245                         get { return ViewState.GetString ("ChangePasswordTitleText", "Change Your Password"); }
246                         set { ViewState ["ChangePasswordTitleText"] = value; }
247                 }
248
249                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
250                 [Browsable (false)]
251                 [Themeable (false)]
252                 [Filterable (false)]
253                 public virtual string ConfirmNewPassword {
254                         get { return _newPasswordConfirm != null ? _newPasswordConfirm : String.Empty; }
255                 }
256
257                 [Localizable (true)]
258                 public virtual string ConfirmNewPasswordLabelText {
259                         get { return ViewState.GetString ("ConfirmNewPasswordLabelText", "Confirm New Password:"); }
260                         set { ViewState ["ConfirmNewPasswordLabelText"] = value; }
261                 }
262
263                 [Localizable (true)]
264                 public virtual string ConfirmPasswordCompareErrorMessage {
265                         get { return ViewState.GetString ("ConfirmPasswordCompareErrorMessage", "The Confirm New Password must match the New Password entry."); }
266                         set { ViewState ["ConfirmPasswordCompareErrorMessage"] = value; }
267                 }
268
269                 [Localizable (true)]
270                 public virtual string ConfirmPasswordRequiredErrorMessage {
271                         get { return ViewState.GetString ("ConfirmPasswordRequiredErrorMessage", "Confirm New Password is required."); }
272                         set { ViewState ["ConfirmPasswordRequiredErrorMessage"] = value; }
273                 }
274
275                 [DefaultValue ("")]
276                 [UrlProperty]
277                 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
278                 public virtual string ContinueButtonImageUrl {
279                         get { return ViewState.GetString ("ContinueButtonImageUrl", String.Empty); }
280                         set { ViewState ["ContinueButtonImageUrl"] = value; }
281                 }
282
283                 [DefaultValue (null)]
284                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
285                 [NotifyParentProperty (true)]
286                 [PersistenceMode (PersistenceMode.InnerProperty)]
287                 public Style ContinueButtonStyle {
288                         get {
289                                 if (_continueButtonStyle == null) {
290                                         _continueButtonStyle = new Style ();
291                                         if (IsTrackingViewState)
292                                                 _continueButtonStyle.TrackViewState ();
293                                 }
294                                 return _continueButtonStyle;
295                         }
296                 }
297
298                 [Localizable (true)]
299                 public virtual string ContinueButtonText {
300                         get { return ViewState.GetString ("ContinueButtonText", "Continue"); }
301                         set { ViewState ["ContinueButtonText"] = value; }
302                 }
303
304                 [DefaultValue (ButtonType.Button)]
305                 public virtual ButtonType ContinueButtonType {
306                         get { return ViewState ["ContinueButtonType"] == null ? ButtonType.Button : (ButtonType) ViewState ["ContinueButtonType"]; }
307                         set { ViewState ["ContinueButtonType"] = value; }
308                 }
309
310                 [Themeable (false)]
311                 [DefaultValue ("")]
312                 [UrlProperty]
313                 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
314                 public virtual string ContinueDestinationPageUrl {
315                         get { return ViewState.GetString ("ContinueDestinationPageUrl", String.Empty); }
316                         set { ViewState ["ContinueDestinationPageUrl"] = value; }
317                 }
318
319                 [DefaultValue ("")]
320                 [UrlProperty]
321                 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
322                 public virtual string CreateUserIconUrl {
323                         get { return ViewState.GetString ("CreateUserIconUrl", String.Empty); }
324                         set { ViewState ["CreateUserIconUrl"] = value; }
325                 }
326
327                 [DefaultValue ("")]
328                 [Localizable (true)]
329                 public virtual string CreateUserText {
330                         get { return ViewState.GetString ("CreateUserText", String.Empty); }
331                         set { ViewState ["CreateUserText"] = value; }
332                 }
333
334                 [DefaultValue ("")]
335                 [UrlProperty]
336                 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
337                 public virtual string CreateUserUrl {
338                         get { return ViewState.GetString ("CreateUserUrl", String.Empty); }
339                         set { ViewState ["CreateUserUrl"] = value; }
340                 }
341
342                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
343                 [Browsable (false)]
344                 [Themeable (false)]
345                 [Filterable (false)]
346                 public virtual string CurrentPassword {
347                         get { return _currentPassword != null ? _currentPassword : String.Empty; }
348                 }
349
350                 [DefaultValue (false)]
351                 public virtual bool DisplayUserName {
352                         get { return ViewState.GetBool ("DisplayUserName", false); }
353                         set { ViewState ["DisplayUserName"] = value; }
354                 }
355
356                 [DefaultValue ("")]
357                 [UrlProperty]
358                 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
359                 public virtual string EditProfileIconUrl {
360                         get { return ViewState.GetString ("EditProfileIconUrl", String.Empty); }
361                         set { ViewState ["EditProfileIconUrl"] = value; }
362                 }
363
364                 [Localizable (true)]
365                 [DefaultValue ("")]
366                 public virtual string EditProfileText {
367                         get { return ViewState.GetString ("EditProfileText", String.Empty); }
368                         set { ViewState ["EditProfileText"] = value; }
369                 }
370
371                 [DefaultValue ("")]
372                 [UrlProperty]
373                 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
374                 public virtual string EditProfileUrl {
375                         get { return ViewState.GetString ("EditProfileUrl", String.Empty); }
376                         set { ViewState ["EditProfileUrl"] = value; }
377                 }
378
379                 [DefaultValue (null)]
380                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
381                 [NotifyParentProperty (true)]
382                 [PersistenceMode (PersistenceMode.InnerProperty)]
383                 public TableItemStyle FailureTextStyle {
384                         get {
385                                 if (_failureTextStyle == null) {
386                                         _failureTextStyle = new TableItemStyle ();
387                                         if (IsTrackingViewState)
388                                                 _failureTextStyle.TrackViewState ();
389                                 }
390                                 return _failureTextStyle;
391                         }
392                 }
393
394                 [DefaultValue ("")]
395                 [UrlProperty]
396                 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
397                 public virtual string HelpPageIconUrl {
398                         get { return ViewState.GetString ("HelpPageIconUrl", String.Empty); }
399                         set { ViewState ["HelpPageIconUrl"] = value; }
400                 }
401
402                 [DefaultValue ("")]
403                 [Localizable (true)]
404                 public virtual string HelpPageText {
405                         get { return ViewState.GetString ("HelpPageText", String.Empty); }
406                         set { ViewState ["HelpPageText"] = value; }
407                 }
408
409                 [DefaultValue ("")]
410                 [UrlProperty]
411                 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
412                 public virtual string HelpPageUrl {
413                         get { return ViewState.GetString ("HelpPageUrl", String.Empty); }
414                         set { ViewState ["HelpPageUrl"] = value; }
415                 }
416
417                 [DefaultValue (null)]
418                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
419                 [NotifyParentProperty (true)]
420                 [PersistenceMode (PersistenceMode.InnerProperty)]
421                 public TableItemStyle HyperLinkStyle {
422                         get {
423                                 if (_hyperLinkStyle == null) {
424                                         _hyperLinkStyle = new TableItemStyle ();
425                                         if (IsTrackingViewState)
426                                                 _hyperLinkStyle.TrackViewState ();
427                                 }
428                                 return _hyperLinkStyle;
429                         }
430                 }
431
432                 [DefaultValue ("")]
433                 [Localizable (true)]
434                 public virtual string InstructionText {
435                         get { return ViewState.GetString ("InstructionText", String.Empty); }
436                         set { ViewState ["InstructionText"] = value; }
437                 }
438
439                 [DefaultValue (null)]
440                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
441                 [NotifyParentProperty (true)]
442                 [PersistenceMode (PersistenceMode.InnerProperty)]
443                 public TableItemStyle InstructionTextStyle {
444                         get {
445                                 if (_instructionTextStyle == null) {
446                                         _instructionTextStyle = new TableItemStyle ();
447                                         if (IsTrackingViewState)
448                                                 _instructionTextStyle.TrackViewState ();
449                                 }
450                                 return _instructionTextStyle;
451                         }
452                 }
453
454                 [DefaultValue (null)]
455                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
456                 [NotifyParentProperty (true)]
457                 [PersistenceMode (PersistenceMode.InnerProperty)]
458                 public TableItemStyle LabelStyle {
459                         get {
460                                 if (_labelStyle == null) {
461                                         _labelStyle = new TableItemStyle ();
462                                         if (IsTrackingViewState)
463                                                 _labelStyle.TrackViewState ();
464                                 }
465                                 return _labelStyle;
466                         }
467                 }
468
469                 [Themeable (false)]
470                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
471                 [NotifyParentProperty (true)]
472                 [PersistenceMode (PersistenceMode.InnerProperty)]
473                 public MailDefinition MailDefinition {
474                         get {
475                                 if (_mailDefinition == null) {
476                                         _mailDefinition = new MailDefinition ();
477                                         if (IsTrackingViewState)
478                                                 ((IStateManager) _mailDefinition).TrackViewState ();
479                                 }
480                                 return _mailDefinition;
481                         }
482                 }
483
484                 [Themeable (false)]
485                 [DefaultValue ("")]
486                 public virtual string MembershipProvider {
487                         get {
488                                 object o = ViewState ["MembershipProvider"];
489                                 return (o == null) ? String.Empty : (string) o;
490                         }
491                         
492                         set {
493                                 if (value == null)
494                                         ViewState.Remove ("MembershipProvider");
495                                 else
496                                         ViewState ["MembershipProvider"] = value;
497
498                                 _provider = null;
499                         }
500                 }
501
502                 [Filterable (false)]
503                 [Browsable (false)]
504                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
505                 [Themeable (false)]
506                 public virtual string NewPassword {
507                         get { return _newPassword != null ? _newPassword : String.Empty; }
508                 }
509
510                 [Localizable (true)]
511                 public virtual string NewPasswordLabelText {
512                         get { return ViewState.GetString ("NewPasswordLabelText", "New Password:"); }
513                         set { ViewState ["NewPasswordLabelText"] = value; }
514                 }
515
516                 public virtual string NewPasswordRegularExpression {
517                         get { return ViewState.GetString ("NewPasswordRegularExpression", String.Empty); }
518                         set { ViewState ["NewPasswordRegularExpression"] = value; }
519                 }
520
521                 public virtual string NewPasswordRegularExpressionErrorMessage {
522                         get { return ViewState.GetString ("NewPasswordRegularExpressionErrorMessage", String.Empty); }
523                         set { ViewState ["NewPasswordRegularExpressionErrorMessage"] = value; }
524                 }
525
526                 [Localizable (true)]
527                 public virtual string NewPasswordRequiredErrorMessage {
528                         get { return ViewState.GetString ("NewPasswordRequiredErrorMessage", "New Password is required."); }
529                         set { ViewState ["NewPasswordRequiredErrorMessage"] = value; }
530                 }
531
532                 [DefaultValue (null)]
533                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
534                 [NotifyParentProperty (true)]
535                 [PersistenceMode (PersistenceMode.InnerProperty)]
536                 public TableItemStyle PasswordHintStyle {
537                         get {
538                                 if (_passwordHintStyle == null) {
539                                         _passwordHintStyle = new TableItemStyle ();
540                                         if (IsTrackingViewState)
541                                                 _passwordHintStyle.TrackViewState ();
542                                 }
543                                 return _passwordHintStyle;
544                         }
545                 }
546
547                 [DefaultValue ("")]
548                 [Localizable (true)]
549                 public virtual string PasswordHintText {
550                         get { return ViewState.GetString ("PasswordHintText", String.Empty); }
551                         set { ViewState ["PasswordHintText"] = value; }
552                 }
553
554                 [Localizable (true)]
555                 public virtual string PasswordLabelText {
556                         get { return ViewState.GetString ("PasswordLabelText", "Password:"); }
557                         set { ViewState ["PasswordLabelText"] = value; }
558                 }
559
560                 [DefaultValue ("")]
561                 [UrlProperty]
562                 [Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
563                 public virtual string PasswordRecoveryIconUrl {
564                         get { return ViewState.GetString ("PasswordRecoveryIconUrl", String.Empty); }
565                         set { ViewState ["PasswordRecoveryIconUrl"] = value; }
566                 }
567
568                 [DefaultValue ("")]
569                 [Localizable (true)]
570                 public virtual string PasswordRecoveryText {
571                         get { return ViewState.GetString ("PasswordRecoveryText", String.Empty); }
572                         set { ViewState ["PasswordRecoveryText"] = value; }
573                 }
574
575                 [DefaultValue ("")]
576                 [UrlProperty]
577                 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
578                 public virtual string PasswordRecoveryUrl {
579                         get { return ViewState.GetString ("PasswordRecoveryUrl", String.Empty); }
580                         set { ViewState ["PasswordRecoveryUrl"] = value; }
581                 }
582
583                 [Localizable (true)]
584                 public virtual string PasswordRequiredErrorMessage {
585                         get { return ViewState.GetString ("PasswordRequiredErrorMessage", String.Empty); }
586                         set { ViewState ["PasswordRequiredErrorMessage"] = value; }
587                 }
588                 // LAMESPEC: MSDN claims it's present in 3.5, but it's not
589                 [DefaultValue (true)]
590                 public virtual bool RenderOuterTable {
591                         get { return renderOuterTable; }
592                         set { renderOuterTable = value; }
593                 }
594                 [DefaultValue ("")]
595                 [UrlProperty]
596                 [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
597                 [Themeable (false)]
598                 public virtual string SuccessPageUrl {
599                         get { return ViewState.GetString ("SuccessPageUrl", String.Empty); }
600                         set { ViewState ["SuccessPageUrl"] = value; }
601                 }
602
603                 [PersistenceMode (PersistenceMode.InnerProperty)]
604                 [TemplateContainer (typeof (ChangePassword))]
605                 [Browsable (false)]
606                 public virtual ITemplate SuccessTemplate {
607                         get { return _successTemplate; }
608                         set { _successTemplate = value; }
609                 }
610
611                 [Browsable (false)]
612                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
613                 public Control SuccessTemplateContainer {
614                         get {
615                                 if (_successTemplateContainer == null)
616                                         _successTemplateContainer = new SuccessContainer (this);
617                                 return _successTemplateContainer;
618                         }
619
620                 }
621
622                 [Localizable (true)]
623                 public virtual string SuccessText {
624                         get { return ViewState.GetString ("SuccessText", "Your password has been changed!"); }
625                         set { ViewState ["SuccessText"] = value; }
626                 }
627
628                 [DefaultValue (null)]
629                 [NotifyParentProperty (true)]
630                 [PersistenceMode (PersistenceMode.InnerProperty)]
631                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
632                 public TableItemStyle SuccessTextStyle {
633                         get {
634                                 if (_successTextStyle == null) {
635                                         _successTextStyle = new TableItemStyle ();
636                                         if (IsTrackingViewState)
637                                                 _successTextStyle.TrackViewState ();
638                                 }
639                                 return _successTextStyle;
640                         }
641                 }
642
643                 [Localizable (true)]
644                 public virtual string SuccessTitleText {
645                         get { return ViewState.GetString ("SuccessTitleText", "Change Password Complete"); }
646                         set { ViewState ["SuccessTitleText"] = value; }
647                 }
648
649                 [DefaultValue (null)]
650                 [NotifyParentProperty (true)]
651                 [PersistenceMode (PersistenceMode.InnerProperty)]
652                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
653                 public Style TextBoxStyle {
654                         get {
655                                 if (_textBoxStyle == null) {
656                                         _textBoxStyle = new Style ();
657                                         if (IsTrackingViewState)
658                                                 _textBoxStyle.TrackViewState ();
659                                 }
660                                 return _textBoxStyle;
661                         }
662                 }
663
664                 [DefaultValue (null)]
665                 [NotifyParentProperty (true)]
666                 [PersistenceMode (PersistenceMode.InnerProperty)]
667                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
668                 public TableItemStyle TitleTextStyle {
669                         get {
670                                 if (_titleTextStyle == null) {
671                                         _titleTextStyle = new TableItemStyle ();
672                                         if (IsTrackingViewState)
673                                                 _titleTextStyle.TrackViewState ();
674                                 }
675                                 return _titleTextStyle;
676                         }
677                 }
678
679                 [DefaultValue ("")]
680                 public virtual string UserName {
681                         get {
682                                 if (_username == null && HttpContext.Current.Request.IsAuthenticated)
683                                         _username = HttpContext.Current.User.Identity.Name;
684
685                                 return _username != null ? _username : String.Empty;
686                         }
687                         set { _username = value; }
688                 }
689
690                 [Localizable (true)]
691                 public virtual string UserNameLabelText {
692                         get { return ViewState.GetString ("UserNameLabelText", "User Name:"); }
693                         set { ViewState ["UserNameLabelText"] = value; }
694                 }
695
696                 [Localizable (true)]
697                 public virtual string UserNameRequiredErrorMessage {
698                         get { return ViewState.GetString ("UserNameRequiredErrorMessage", "User Name is required."); }
699                         set { ViewState ["UserNameRequiredErrorMessage"] = value; }
700                 }
701
702                 [DefaultValue (null)]
703                 [NotifyParentProperty (true)]
704                 [PersistenceMode (PersistenceMode.InnerProperty)]
705                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
706                 public Style ValidatorTextStyle {
707                         get {
708                                 if (_validatorTextStyle == null) {
709                                         _validatorTextStyle = new Style ();
710                                         if (IsTrackingViewState)
711                                                 _validatorTextStyle.TrackViewState ();
712                                 }
713                                 return _validatorTextStyle;
714                         }
715                 }
716
717                 #endregion
718
719                 #region Protected Methods
720
721                 protected internal override void CreateChildControls ()
722                 {
723                         Controls.Clear ();
724
725                         ITemplate cpTemplate = ChangePasswordTemplate;
726                         if (cpTemplate == null)
727                                 cpTemplate = new ChangePasswordDeafultTemplate (this);
728                         ((ChangePasswordContainer) ChangePasswordTemplateContainer).InstantiateTemplate (cpTemplate);
729
730                         ITemplate sTemplate = SuccessTemplate;
731                         if (sTemplate == null)
732                                 sTemplate = new SuccessDefaultTemplate (this);
733                         ((SuccessContainer) SuccessTemplateContainer).InstantiateTemplate (sTemplate);
734
735                         Controls.AddAt (0, ChangePasswordTemplateContainer);
736                         Controls.AddAt (1, SuccessTemplateContainer);
737
738                         IEditableTextControl editable;
739
740                         ChangePasswordContainer container = (ChangePasswordContainer) ChangePasswordTemplateContainer;
741                         if (DisplayUserName) {
742                                 editable = container.UserNameTextBox;
743                                 if (editable != null)
744                                         editable.TextChanged += new EventHandler (UserName_TextChanged);
745                         }
746
747                         editable = container.CurrentPasswordTextBox;
748                         if (editable != null)
749                                 editable.TextChanged += new EventHandler (CurrentPassword_TextChanged);
750
751                         editable = container.NewPasswordTextBox;
752                         if (editable != null)
753                                 editable.TextChanged += new EventHandler (NewPassword_TextChanged);
754
755                         editable = container.ConfirmNewPasswordTextBox;
756                         if (editable != null)
757                                 editable.TextChanged += new EventHandler (NewPasswordConfirm_TextChanged);
758                 }
759
760                 protected internal override void Render (HtmlTextWriter writer)
761                 {
762                         VerifyInlinePropertiesNotSet ();
763                         for (int i = 0; i < Controls.Count; i++)
764                                 if (Controls [i].Visible)
765                                         Controls [i].Render (writer);
766                 }
767
768                 #endregion
769
770                 #region Private Methods
771
772                 [MonoTODO ("Not implemented")]
773                 protected override void SetDesignModeState (IDictionary data)
774                 {
775                         throw new NotImplementedException ();
776                 }
777
778                 void InitMemberShipProvider ()
779                 {
780                         string mp = MembershipProvider;
781                         _provider = (mp.Length == 0) ? Membership.Provider : Membership.Providers [mp];
782                         if (_provider == null)
783                                 throw new HttpException (Locale.GetText ("No provider named '{0}' could be found.", mp));
784                 }
785
786                 void ProcessChangePasswordEvent (CommandEventArgs args)
787                 {
788                         if (!Page.IsValid)
789                                 return;
790
791                         LoginCancelEventArgs loginCancelEventArgs = new LoginCancelEventArgs ();
792                         OnChangingPassword (loginCancelEventArgs);
793                         if (loginCancelEventArgs.Cancel)
794                                 return;
795
796                         bool res = false;
797                         try {
798                                 res = MembershipProviderInternal.ChangePassword (UserName, CurrentPassword, NewPassword);
799                         } catch {
800                         }
801                         
802                         if (res) {
803                                 OnChangedPassword (args);
804                                 _showContinue = true;
805
806                                 if (_mailDefinition != null)
807                                         SendMail (UserName, NewPassword);
808                         } else {
809                                 OnChangePasswordError (EventArgs.Empty);
810                                 string lastError = string.Format (
811                                         "Password incorrect or New Password invalid. New Password length minimum: {0}. Non-alphanumeric characters required: {1}.",
812                                         MembershipProviderInternal.MinRequiredPasswordLength,
813                                         MembershipProviderInternal.MinRequiredNonAlphanumericCharacters);
814
815                                 ChangePasswordContainer container = (ChangePasswordContainer) ChangePasswordTemplateContainer;
816                                 container.FailureTextLiteral.Text = lastError;
817                                 _showContinue = false;
818                         }
819
820                         return;
821                 }
822                 
823                 void ProcessCancelEvent (CommandEventArgs args)
824                 {
825                         OnCancelButtonClick (args);
826
827                         if (ContinueDestinationPageUrl.Length > 0)
828                                 Context.Response.Redirect (ContinueDestinationPageUrl);
829
830                         return;
831                 }
832
833                 void ProcessContinueEvent (CommandEventArgs args)
834                 {
835                         OnContinueButtonClick (args);
836
837                         if (ContinueDestinationPageUrl.Length > 0)
838                                 Context.Response.Redirect (ContinueDestinationPageUrl);
839
840                         return;
841                 }
842
843                 void SendMail (string username, string password)
844                 {
845                         MembershipUser user = MembershipProviderInternal.GetUser (UserName, false);
846                         if (user == null)
847                                 return;
848
849                         ListDictionary dictionary = new ListDictionary ();
850                         dictionary.Add ("<%USERNAME%>", username);
851                         dictionary.Add ("<%PASSWORD%>", password);
852
853                         MailMessage message = MailDefinition.CreateMailMessage (user.Email, dictionary, this);
854
855                         MailMessageEventArgs args = new MailMessageEventArgs (message);
856                         OnSendingMail (args);
857
858                         SmtpClient smtpClient = new SmtpClient ();
859                         try {
860                                 smtpClient.Send (message);
861                         } catch (Exception e) {
862                                 SendMailErrorEventArgs mailArgs = new SendMailErrorEventArgs (e);
863                                 OnSendMailError (mailArgs);
864                                 if (!mailArgs.Handled)
865                                         throw e;
866                         }
867                 }
868
869                 #endregion
870
871                 #region Properties
872
873                 protected override HtmlTextWriterTag TagKey {
874                         get { return HtmlTextWriterTag.Table; }
875                 }
876
877                 internal virtual MembershipProvider MembershipProviderInternal {
878                         get {
879                                 if (_provider == null)
880                                         InitMemberShipProvider ();
881
882                                 return _provider;
883                         }
884                 }
885
886                 #endregion
887
888                 #region View and Control State
889
890                 protected internal override void LoadControlState (object savedState)
891                 {
892                         if (savedState == null)
893                                 return;
894                         object [] state = (object []) savedState;
895                         base.LoadControlState (state [0]);
896
897                         _showContinue = (bool) state [1];
898                         _username = (string) state [2];
899                 }
900
901                 protected internal override object SaveControlState ()
902                 {
903                         object state = base.SaveControlState ();
904                         return new object [] { state, _showContinue, _username };
905                 }
906
907                 protected override void LoadViewState (object savedState)
908                 {
909                         if (savedState == null)
910                                 return;
911
912                         object [] states = (object []) savedState;
913                         base.LoadViewState (states [0]);
914
915                         if (states [1] != null)
916                                 CancelButtonStyle.LoadViewState (states [1]);
917                         if (states [2] != null)
918                                 ChangePasswordButtonStyle.LoadViewState (states [2]);
919                         if (states [3] != null)
920                                 ContinueButtonStyle.LoadViewState (states [3]);
921
922                         if (states [4] != null)
923                                 FailureTextStyle.LoadViewState (states [4]);
924                         if (states [5] != null)
925                                 HyperLinkStyle.LoadViewState (states [5]);
926                         if (states [6] != null)
927                                 InstructionTextStyle.LoadViewState (states [6]);
928
929                         if (states [7] != null)
930                                 LabelStyle.LoadViewState (states [7]);
931                         if (states [8] != null)
932                                 PasswordHintStyle.LoadViewState (states [8]);
933                         if (states [9] != null)
934                                 SuccessTextStyle.LoadViewState (states [9]);
935
936                         if (states [10] != null)
937                                 TextBoxStyle.LoadViewState (states [10]);
938                         if (states [11] != null)
939                                 TitleTextStyle.LoadViewState (states [11]);
940                         if (states [12] != null)
941                                 ValidatorTextStyle.LoadViewState (states [12]);
942
943                         if (states [13] != null)
944                                 ((IStateManager) MailDefinition).LoadViewState (states [13]);
945                 }
946
947                 protected override object SaveViewState ()
948                 {
949                         object [] states = new object [14];
950                         states [0] = base.SaveViewState ();
951
952                         if (_cancelButtonStyle != null)
953                                 states [1] = _cancelButtonStyle.SaveViewState ();
954                         if (_changePasswordButtonStyle != null)
955                                 states [2] = _changePasswordButtonStyle.SaveViewState ();
956                         if (_continueButtonStyle != null)
957                                 states [3] = _continueButtonStyle.SaveViewState ();
958
959                         if (_failureTextStyle != null)
960                                 states [4] = _failureTextStyle.SaveViewState ();
961                         if (_hyperLinkStyle != null)
962                                 states [5] = _hyperLinkStyle.SaveViewState ();
963                         if (_instructionTextStyle != null)
964                                 states [6] = _instructionTextStyle.SaveViewState ();
965
966                         if (_labelStyle != null)
967                                 states [7] = _labelStyle.SaveViewState ();
968                         if (_passwordHintStyle != null)
969                                 states [8] = _passwordHintStyle.SaveViewState ();
970                         if (_successTextStyle != null)
971                                 states [9] = _successTextStyle.SaveViewState ();
972
973                         if (_textBoxStyle != null)
974                                 states [10] = _textBoxStyle.SaveViewState ();
975                         if (_titleTextStyle != null)
976                                 states [11] = _titleTextStyle.SaveViewState ();
977                         if (_validatorTextStyle != null)
978                                 states [12] = _validatorTextStyle.SaveViewState ();
979
980                         if (_mailDefinition != null)
981                                 states [13] = ((IStateManager) _mailDefinition).SaveViewState ();
982
983                         for (int i = 0; i < states.Length; i++) {
984                                 if (states [i] != null)
985                                         return states;
986                         }
987                         return null;
988                 }
989
990                 protected override void TrackViewState ()
991                 {
992                         base.TrackViewState ();
993
994                         if (_cancelButtonStyle != null)
995                                 _cancelButtonStyle.TrackViewState ();
996                         if (_changePasswordButtonStyle != null)
997                                 _changePasswordButtonStyle.TrackViewState ();
998                         if (_continueButtonStyle != null)
999                                 _continueButtonStyle.TrackViewState ();
1000
1001                         if (_failureTextStyle != null)
1002                                 _failureTextStyle.TrackViewState ();
1003                         if (_hyperLinkStyle != null)
1004                                 _hyperLinkStyle.TrackViewState ();
1005                         if (_instructionTextStyle != null)
1006                                 _instructionTextStyle.TrackViewState ();
1007
1008                         if (_labelStyle != null)
1009                                 _labelStyle.TrackViewState ();
1010                         if (_passwordHintStyle != null)
1011                                 _passwordHintStyle.TrackViewState ();
1012                         if (_successTextStyle != null)
1013                                 _successTextStyle.TrackViewState ();
1014
1015                         if (_textBoxStyle != null)
1016                                 _textBoxStyle.TrackViewState ();
1017                         if (_titleTextStyle != null)
1018                                 _titleTextStyle.TrackViewState ();
1019                         if (_validatorTextStyle != null)
1020                                 _validatorTextStyle.TrackViewState ();
1021
1022                         if (_mailDefinition != null)
1023                                 ((IStateManager) _mailDefinition).TrackViewState ();
1024                 }
1025
1026                 #endregion
1027
1028                 #region Event Handlers
1029
1030                 protected override bool OnBubbleEvent (object source, EventArgs e)
1031                 {
1032                         CommandEventArgs args = e as CommandEventArgs;
1033                         if (e != null) {
1034                                 if (args.CommandName == ChangePasswordButtonCommandName) {
1035                                         ProcessChangePasswordEvent (args);
1036                                         return true;
1037                                 }
1038
1039                                 if (args.CommandName == CancelButtonCommandName) {
1040                                         ProcessCancelEvent (args);
1041                                         return true;
1042                                 }
1043
1044                                 if (args.CommandName == ContinueButtonCommandName) {
1045                                         ProcessContinueEvent (args);
1046                                         return true;
1047                                 }
1048                         }
1049                         return base.OnBubbleEvent (source, e);
1050                 }
1051
1052                 protected virtual void OnCancelButtonClick (EventArgs e)
1053                 {
1054                         EventHandler eh = events [cancelButtonClickEvent] as EventHandler;
1055                         if (eh != null)
1056                                 eh (this, e);
1057                 }
1058
1059                 protected virtual void OnChangedPassword (EventArgs e)
1060                 {
1061                         EventHandler eh = events [changedPasswordEvent] as EventHandler;
1062                         if (eh != null)
1063                                 eh (this, e);
1064                 }
1065
1066                 protected virtual void OnChangePasswordError (EventArgs e)
1067                 {
1068                         EventHandler eh = events [changePasswordErrorEvent] as EventHandler;
1069                         if (eh != null)
1070                                 eh (this, e);
1071                 }
1072
1073                 protected virtual void OnChangingPassword (LoginCancelEventArgs e)
1074                 {
1075                         LoginCancelEventHandler eh = events [changingPasswordEvent] as LoginCancelEventHandler;
1076                         if (eh != null)
1077                                 eh (this, e);
1078                 }
1079
1080                 protected virtual void OnContinueButtonClick (EventArgs e)
1081                 {
1082                         EventHandler eh = events [continueButtonClickEvent] as EventHandler;
1083                         if (eh != null)
1084                                 eh (this, e);
1085                 }
1086
1087                 protected internal override void OnInit (EventArgs e)
1088                 {
1089                         Page.RegisterRequiresControlState (this);
1090                         base.OnInit (e);
1091                 }
1092
1093                 protected internal override void OnPreRender (EventArgs e)
1094                 {
1095                         ChangePasswordTemplateContainer.Visible = !_showContinue;
1096                         SuccessTemplateContainer.Visible = _showContinue;
1097                         base.OnPreRender (e);
1098                 }
1099
1100                 protected virtual void OnSendingMail (MailMessageEventArgs e)
1101                 {
1102                         MailMessageEventHandler eh = events [sendingMailEvent] as MailMessageEventHandler;
1103                         if (eh != null)
1104                                 eh (this, e);
1105                 }
1106
1107                 protected virtual void OnSendMailError (SendMailErrorEventArgs e)
1108                 {
1109                         SendMailErrorEventHandler eh = events [sendMailErrorEvent] as SendMailErrorEventHandler;
1110                         if (eh != null)
1111                                 eh (this, e);
1112                 }
1113
1114                 void UserName_TextChanged (object sender, EventArgs e)
1115                 {
1116                         UserName = ((ITextControl) sender).Text;
1117                 }
1118
1119                 void CurrentPassword_TextChanged (object sender, EventArgs e)
1120                 {
1121                         _currentPassword = ((ITextControl) sender).Text;
1122                 }
1123
1124                 void NewPassword_TextChanged (object sender, EventArgs e)
1125                 {
1126                         _newPassword = ((ITextControl) sender).Text;
1127                 }
1128
1129                 void NewPasswordConfirm_TextChanged (object sender, EventArgs e)
1130                 {
1131                         _newPasswordConfirm = ((ITextControl) sender).Text;
1132                 }
1133
1134                 #endregion
1135
1136                 class BaseChangePasswordContainer : Control, INamingContainer, INonBindingContainer
1137                 {
1138                         protected readonly ChangePassword _owner = null;
1139                         bool renderOuterTable;
1140                         Table _table = null;
1141                         TableCell _containerCell = null;
1142
1143                         public BaseChangePasswordContainer (ChangePassword owner)
1144                         {
1145                                 if (owner == null)
1146                                         throw new ArgumentNullException ("owner");
1147                                 
1148                                 _owner = owner;
1149                                 renderOuterTable = _owner.RenderOuterTable;
1150
1151                                 if (renderOuterTable)
1152                                         InitTable ();
1153                         }
1154
1155                         public void InstantiateTemplate (ITemplate template)
1156                         {
1157                                 if (!_owner.RenderOuterTable)
1158                                         template.InstantiateIn (this);
1159                                 else
1160                                         template.InstantiateIn (_containerCell);
1161                         }
1162
1163                         void InitTable ()
1164                         {
1165                                 _table = new Table ();
1166                                 string id = _owner.ID;
1167                                 if (!String.IsNullOrEmpty (id))
1168                                         _table.Attributes.Add ("id", _owner.ID);
1169
1170                                 _table.CellSpacing = 0;
1171                                 _table.CellPadding = _owner.BorderPadding;
1172
1173                                 _containerCell = new TableCell ();
1174
1175                                 TableRow row = new TableRow ();
1176                                 row.Cells.Add (_containerCell);
1177                                 _table.Rows.Add (row);
1178
1179                                 Controls.AddAt (0, _table);
1180                         }
1181
1182                         protected internal override void OnPreRender (EventArgs e)
1183                         {
1184                                 if (_table != null)
1185                                         _table.ApplyStyle (_owner.ControlStyle);
1186                                 base.OnPreRender (e);
1187                         }
1188                         
1189                         protected override void EnsureChildControls ()
1190                         {
1191                                 base.EnsureChildControls ();
1192
1193                                 // it's the owner who adds controls, not us
1194                                 if (_owner != null)
1195                                         _owner.EnsureChildControls ();
1196                         }
1197                 }
1198
1199                 sealed class ChangePasswordContainer : BaseChangePasswordContainer
1200                 {
1201                         public ChangePasswordContainer (ChangePassword owner) : base (owner)
1202                         {
1203                                 ID = "ChangePasswordContainerID";
1204                         }
1205
1206                         // Requried controls
1207                         public IEditableTextControl UserNameTextBox {
1208                                 get {
1209                                         Control c = FindControl ("UserName");
1210                                         if (c == null)
1211                                                 throw new HttpException ("ChangePasswordTemplate does not contain an IEditableTextControl with ID UserName for the username, this is required if DisplayUserName=true.");
1212                                         return c as IEditableTextControl;
1213                                 }
1214                         }
1215                         
1216                         public IEditableTextControl CurrentPasswordTextBox {
1217                                 get {
1218                                         Control c = FindControl ("CurrentPassword");
1219                                         if (c == null)
1220                                                 throw new HttpException ("ChangePasswordTemplate does not contain an IEditableTextControl with ID CurrentPassword for the current password.");
1221                                         return c as IEditableTextControl;
1222                                 }
1223                         }
1224                         
1225                         public IEditableTextControl NewPasswordTextBox {
1226                                 get {
1227                                         Control c = FindControl ("NewPassword");
1228                                         if (c == null)
1229                                                 throw new HttpException ("ChangePasswordTemplate does not contain an IEditableTextControl with ID NewPassword for the new password.");
1230                                         return c as IEditableTextControl;
1231                                 }
1232                         }
1233
1234                         // Optional controls
1235                         public IEditableTextControl ConfirmNewPasswordTextBox {
1236                                 get { return FindControl ("ConfirmNewPassword") as IEditableTextControl; }
1237                         }
1238                         
1239                         public Control CancelButton {
1240                                 get { return FindControl ("Cancel"); }
1241                         }
1242                         
1243                         public Control ChangePasswordButton {
1244                                 get { return FindControl ("ChangePassword"); }
1245                         }
1246                         
1247                         public ITextControl FailureTextLiteral {
1248                                 get { return FindControl ("FailureText") as ITextControl; }
1249                         }
1250                 }
1251
1252                 sealed class ChangePasswordDeafultTemplate : ITemplate
1253                 {
1254                         readonly ChangePassword _owner = null;
1255
1256                         internal ChangePasswordDeafultTemplate (ChangePassword cPassword)
1257                         {
1258                                 _owner = cPassword;
1259                         }
1260
1261                         TableRow CreateRow (Control c0, Control c1, Control c2, Style s0, Style s1)
1262                         {
1263                                 TableRow row = new TableRow ();
1264                                 TableCell cell0 = new TableCell ();
1265                                 TableCell cell1 = new TableCell ();
1266
1267                                 cell0.Controls.Add (c0);
1268                                 row.Controls.Add (cell0);
1269
1270                                 if ((c1 != null) && (c2 != null)) {
1271                                         cell1.Controls.Add (c1);
1272                                         cell1.Controls.Add (c2);
1273                                         cell0.HorizontalAlign = HorizontalAlign.Right;
1274
1275                                         if (s0 != null)
1276                                                 cell0.ApplyStyle (s0);
1277                                         if (s1 != null)
1278                                                 cell1.ApplyStyle (s1);
1279
1280                                         row.Controls.Add (cell1);
1281                                 } else {
1282                                         cell0.ColumnSpan = 2;
1283                                         cell0.HorizontalAlign = HorizontalAlign.Center;
1284                                         if (s0 != null)
1285                                                 cell0.ApplyStyle (s0);
1286                                 }
1287                                 return row;
1288                         }
1289
1290                         bool AddLink (string pageUrl, string linkText, string linkIcon, WebControl container)
1291                         {
1292                                 bool added = false;
1293                                 if (linkIcon.Length > 0) {
1294                                         Image img = new Image ();
1295                                         img.ImageUrl = linkIcon;
1296                                         container.Controls.Add (img);
1297                                         added = true;
1298                                 }
1299                                 if (linkText.Length > 0) {
1300                                         HyperLink link = new HyperLink ();
1301                                         link.NavigateUrl = pageUrl;
1302                                         link.Text = linkText;
1303                                         link.ControlStyle.CopyTextStylesFrom (container.ControlStyle);
1304                                         container.Controls.Add (link);
1305                                         added = true;
1306                                 }
1307                                 return added;
1308                         }
1309
1310                         public void InstantiateIn (Control container)
1311                         {
1312                                 Table table = new Table ();
1313                                 table.CellPadding = 0;
1314                                 Style ownerStyle = _owner.ControlStyle;
1315                                 Style tableStyle = table.ControlStyle;
1316                                 FontInfo ownerFont = ownerStyle.Font;
1317                                 
1318                                 tableStyle.Font.CopyFrom (ownerFont);
1319                                 ownerFont.ClearDefaults ();
1320
1321                                 Color ownerForeColor = ownerStyle.ForeColor;
1322                                 if (ownerForeColor != Color.Empty) {
1323                                         tableStyle.ForeColor = ownerForeColor;
1324                                         ownerStyle.RemoveBit ((int)global::System.Web.UI.WebControls.Style.Styles.ForeColor);
1325                                 }
1326                                 // Row #0
1327                                 table.Controls.Add (
1328                                         CreateRow (new LiteralControl (_owner.ChangePasswordTitleText),
1329                                         null, null, _owner.TitleTextStyle, null));
1330
1331                                 // Row #1
1332                                 if (_owner.InstructionText.Length > 0) {
1333                                         table.Controls.Add (
1334                                                 CreateRow (new LiteralControl (_owner.InstructionText),
1335                                                 null, null, _owner.InstructionTextStyle, null));
1336                                 }
1337
1338                                 // Row #2
1339                                 if (_owner.DisplayUserName) {
1340                                         TextBox UserName = new TextBox ();
1341                                         UserName.ID = "UserName";
1342                                         UserName.Text = _owner.UserName;
1343                                         UserName.ApplyStyle (_owner.TextBoxStyle);
1344
1345                                         Label UserNameLabel = new Label ();
1346                                         UserNameLabel.ID = "UserNameLabel";
1347                                         UserNameLabel.AssociatedControlID = "UserName";
1348                                         UserNameLabel.Text = _owner.UserNameLabelText;
1349
1350                                         RequiredFieldValidator UserNameRequired = new RequiredFieldValidator ();
1351                                         UserNameRequired.ID = "UserNameRequired";
1352                                         UserNameRequired.ControlToValidate = "UserName";
1353                                         UserNameRequired.ErrorMessage = _owner.UserNameRequiredErrorMessage;
1354                                         UserNameRequired.ToolTip = _owner.UserNameRequiredErrorMessage;
1355                                         UserNameRequired.Text = "*";
1356                                         UserNameRequired.ValidationGroup = _owner.ID;
1357                                         UserNameRequired.ApplyStyle (_owner.ValidatorTextStyle);
1358
1359                                         table.Controls.Add (CreateRow (UserNameLabel, UserName, UserNameRequired, _owner.LabelStyle, null));
1360                                 }
1361
1362                                 // Row #3
1363                                 TextBox CurrentPassword = new TextBox ();
1364                                 CurrentPassword.ID = "CurrentPassword";
1365                                 CurrentPassword.TextMode = TextBoxMode.Password;
1366                                 CurrentPassword.ApplyStyle (_owner.TextBoxStyle);
1367
1368                                 Label CurrentPasswordLabel = new Label ();
1369                                 CurrentPasswordLabel.ID = "CurrentPasswordLabel";
1370                                 CurrentPasswordLabel.AssociatedControlID = "CurrentPasswordLabel";
1371                                 CurrentPasswordLabel.Text = _owner.PasswordLabelText;
1372
1373                                 RequiredFieldValidator CurrentPasswordRequired = new RequiredFieldValidator ();
1374                                 CurrentPasswordRequired.ID = "CurrentPasswordRequired";
1375                                 CurrentPasswordRequired.ControlToValidate = "CurrentPassword";
1376                                 CurrentPasswordRequired.ErrorMessage = _owner.PasswordRequiredErrorMessage;
1377                                 CurrentPasswordRequired.ToolTip = _owner.PasswordRequiredErrorMessage;
1378                                 CurrentPasswordRequired.Text = "*";
1379                                 CurrentPasswordRequired.ValidationGroup = _owner.ID;
1380                                 CurrentPasswordRequired.ApplyStyle (_owner.ValidatorTextStyle);
1381
1382                                 table.Controls.Add (CreateRow (CurrentPasswordLabel, CurrentPassword, CurrentPasswordRequired, _owner.LabelStyle, null));
1383
1384                                 // Row #4
1385                                 TextBox NewPassword = new TextBox ();
1386                                 NewPassword.ID = "NewPassword";
1387                                 NewPassword.TextMode = TextBoxMode.Password;
1388                                 NewPassword.ApplyStyle (_owner.TextBoxStyle);
1389
1390                                 Label NewPasswordLabel = new Label ();
1391                                 NewPasswordLabel.ID = "NewPasswordLabel";
1392                                 NewPasswordLabel.AssociatedControlID = "NewPassword";
1393                                 NewPasswordLabel.Text = _owner.NewPasswordLabelText;
1394
1395                                 RequiredFieldValidator NewPasswordRequired = new RequiredFieldValidator ();
1396                                 NewPasswordRequired.ID = "NewPasswordRequired";
1397                                 NewPasswordRequired.ControlToValidate = "NewPassword";
1398                                 NewPasswordRequired.ErrorMessage = _owner.PasswordRequiredErrorMessage;
1399                                 NewPasswordRequired.ToolTip = _owner.PasswordRequiredErrorMessage;
1400                                 NewPasswordRequired.Text = "*";
1401                                 NewPasswordRequired.ValidationGroup = _owner.ID;
1402                                 NewPasswordRequired.ApplyStyle (_owner.ValidatorTextStyle);
1403
1404                                 table.Controls.Add (CreateRow (NewPasswordLabel, NewPassword, NewPasswordRequired, _owner.LabelStyle, null));
1405
1406                                 // Row #5
1407                                 if (_owner.PasswordHintText.Length > 0) {
1408                                         table.Controls.Add (
1409                                                 CreateRow (new LiteralControl (String.Empty),
1410                                                         new LiteralControl (_owner.PasswordHintText),
1411                                                         new LiteralControl (String.Empty),
1412                                                         null, _owner.PasswordHintStyle));
1413                                 }
1414
1415                                 // Row #6
1416                                 TextBox ConfirmNewPassword = new TextBox ();
1417                                 ConfirmNewPassword.ID = "ConfirmNewPassword";
1418                                 ConfirmNewPassword.TextMode = TextBoxMode.Password;
1419                                 ConfirmNewPassword.ApplyStyle (_owner.TextBoxStyle);
1420
1421                                 Label ConfirmNewPasswordLabel = new Label ();
1422                                 ConfirmNewPasswordLabel.ID = "ConfirmNewPasswordLabel";
1423                                 ConfirmNewPasswordLabel.AssociatedControlID = "ConfirmNewPasswordLabel";
1424                                 ConfirmNewPasswordLabel.Text = _owner.ConfirmNewPasswordLabelText;
1425
1426                                 RequiredFieldValidator ConfirmNewPasswordRequired = new RequiredFieldValidator ();
1427                                 ConfirmNewPasswordRequired.ID = "ConfirmNewPasswordRequired";
1428                                 ConfirmNewPasswordRequired.ControlToValidate = "ConfirmNewPassword";
1429                                 ConfirmNewPasswordRequired.ErrorMessage = _owner.PasswordRequiredErrorMessage;
1430                                 ConfirmNewPasswordRequired.ToolTip = _owner.PasswordRequiredErrorMessage;
1431                                 ConfirmNewPasswordRequired.Text = "*";
1432                                 ConfirmNewPasswordRequired.ValidationGroup = _owner.ID;
1433                                 ConfirmNewPasswordRequired.ApplyStyle (_owner.ValidatorTextStyle);
1434
1435                                 table.Controls.Add (CreateRow (ConfirmNewPasswordLabel, ConfirmNewPassword, ConfirmNewPasswordRequired, _owner.LabelStyle, null));
1436
1437                                 // Row #7
1438                                 CompareValidator NewPasswordCompare = new CompareValidator ();
1439                                 NewPasswordCompare.ID = "NewPasswordCompare";
1440                                 NewPasswordCompare.ControlToCompare = "NewPassword";
1441                                 NewPasswordCompare.ControlToValidate = "ConfirmNewPassword";
1442                                 NewPasswordCompare.Display = ValidatorDisplay.Dynamic;
1443                                 NewPasswordCompare.ErrorMessage = _owner.ConfirmPasswordCompareErrorMessage;
1444                                 NewPasswordCompare.ValidationGroup = _owner.ID;
1445
1446                                 table.Controls.Add (CreateRow (NewPasswordCompare, null, null, null, null));
1447
1448                                 // Row #8
1449                                 Literal FailureTextLiteral = new Literal ();
1450                                 FailureTextLiteral.ID = "FailureText";
1451                                 FailureTextLiteral.EnableViewState = false;
1452
1453                                 if (_owner.FailureTextStyle.ForeColor.IsEmpty)
1454                                         _owner.FailureTextStyle.ForeColor = System.Drawing.Color.Red;
1455
1456                                 table.Controls.Add (CreateRow (FailureTextLiteral, null, null, _owner.FailureTextStyle, null));
1457
1458                                 // Row #9
1459                                 WebControl ChangePasswordButton = null;
1460                                 switch (_owner.ChangePasswordButtonType) {
1461                                         case ButtonType.Button:
1462                                                 ChangePasswordButton = new Button ();
1463                                                 break;
1464                                         case ButtonType.Image:
1465                                                 ChangePasswordButton = new ImageButton ();
1466                                                 break;
1467                                         case ButtonType.Link:
1468                                                 ChangePasswordButton = new LinkButton ();
1469                                                 break;
1470                                 }
1471
1472                                 ChangePasswordButton.ID = "ChangePasswordPushButton";
1473                                 ChangePasswordButton.ApplyStyle (_owner.ChangePasswordButtonStyle);
1474                                 ((IButtonControl) ChangePasswordButton).CommandName = ChangePassword.ChangePasswordButtonCommandName;
1475                                 ((IButtonControl) ChangePasswordButton).Text = _owner.ChangePasswordButtonText;
1476                                 ((IButtonControl) ChangePasswordButton).ValidationGroup = _owner.ID;
1477
1478                                 WebControl CancelButton = null;
1479                                 switch (_owner.CancelButtonType) {
1480                                         case ButtonType.Button:
1481                                                 CancelButton = new Button ();
1482                                                 break;
1483                                         case ButtonType.Image:
1484                                                 CancelButton = new ImageButton ();
1485                                                 break;
1486                                         case ButtonType.Link:
1487                                                 CancelButton = new LinkButton ();
1488                                                 break;
1489                                 }
1490
1491                                 CancelButton.ID = "CancelPushButton";
1492                                 CancelButton.ApplyStyle (_owner.CancelButtonStyle);
1493                                 ((IButtonControl) CancelButton).CommandName = ChangePassword.CancelButtonCommandName;
1494                                 ((IButtonControl) CancelButton).Text = _owner.CancelButtonText;
1495                                 ((IButtonControl) CancelButton).CausesValidation = false;
1496
1497                                 table.Controls.Add (CreateRow (ChangePasswordButton, CancelButton, new LiteralControl (String.Empty), null, null));
1498
1499                                 // Row #10
1500                                 TableRow linksRow = new TableRow ();
1501                                 TableCell linksCell = new TableCell ();
1502                                 linksCell.ColumnSpan = 2;
1503                                 linksCell.ControlStyle.CopyFrom (_owner.HyperLinkStyle);
1504
1505                                 linksRow.Cells.Add (linksCell);
1506
1507                                 if (AddLink (_owner.HelpPageUrl, _owner.HelpPageText, _owner.HelpPageIconUrl, linksCell))
1508                                         linksCell.Controls.Add (new LiteralControl ("<br/>"));
1509
1510                                 if (AddLink (_owner.CreateUserUrl, _owner.CreateUserText, _owner.CreateUserIconUrl, linksCell))
1511                                         linksCell.Controls.Add (new LiteralControl ("<br/>"));
1512
1513                                 if (AddLink (_owner.PasswordRecoveryUrl, _owner.PasswordRecoveryText, _owner.PasswordRecoveryIconUrl, linksCell))
1514                                         linksCell.Controls.Add (new LiteralControl ("<br/>"));
1515
1516                                 AddLink (_owner.EditProfileUrl, _owner.EditProfileText, _owner.EditProfileIconUrl, linksCell);
1517
1518                                 table.Controls.Add (linksRow);
1519
1520                                 container.Controls.Add (table);
1521                         }
1522                 }
1523
1524                 sealed class SuccessDefaultTemplate : ITemplate
1525                 {
1526                         readonly ChangePassword _cPassword = null;
1527
1528                         internal SuccessDefaultTemplate (ChangePassword cPassword)
1529                         {
1530                                 _cPassword = cPassword;
1531                         }
1532
1533                         TableRow CreateRow (Control c0, Style s0, HorizontalAlign align)
1534                         {
1535                                 TableRow row = new TableRow ();
1536                                 TableCell cell0 = new TableCell ();
1537
1538                                 cell0.Controls.Add (c0);
1539                                 cell0.HorizontalAlign = align;
1540                                 if (s0 != null)
1541                                         cell0.ApplyStyle (s0);
1542
1543                                 row.Controls.Add (cell0);
1544                                 return row;
1545                         }
1546
1547                         public void InstantiateIn (Control container)
1548                         {
1549                                 Table table = new Table ();
1550                                 table.ControlStyle.Width = Unit.Percentage (100);
1551                                 table.ControlStyle.Height = Unit.Percentage (100);
1552
1553                                 // Row #0
1554                                 table.Controls.Add (
1555                                         CreateRow (new LiteralControl (_cPassword.SuccessTitleText), _cPassword.TitleTextStyle, HorizontalAlign.Center));
1556
1557                                 // Row #1
1558                                 table.Controls.Add (
1559                                         CreateRow (new LiteralControl (_cPassword.SuccessText), _cPassword.SuccessTextStyle, HorizontalAlign.Center));
1560
1561                                 // Row #3
1562                                 WebControl ContinueButton = null;
1563                                 switch (_cPassword.ChangePasswordButtonType) {
1564                                         case ButtonType.Button:
1565                                                 ContinueButton = new Button ();
1566                                                 break;
1567                                         case ButtonType.Image:
1568                                                 ContinueButton = new ImageButton ();
1569                                                 break;
1570                                         case ButtonType.Link:
1571                                                 ContinueButton = new LinkButton ();
1572                                                 break;
1573                                 }
1574
1575                                 ContinueButton.ID = "ContinuePushButton";
1576                                 ContinueButton.ApplyStyle (_cPassword.ContinueButtonStyle);
1577                                 ((IButtonControl) ContinueButton).CommandName = ChangePassword.ContinueButtonCommandName;
1578                                 ((IButtonControl) ContinueButton).Text = _cPassword.ContinueButtonText;
1579                                 ((IButtonControl) ContinueButton).CausesValidation = false;
1580
1581                                 table.Controls.Add (
1582                                         CreateRow (ContinueButton, null, HorizontalAlign.Right));
1583
1584                                 container.Controls.Add (table);
1585                         }
1586                 }
1587
1588                 sealed class SuccessContainer : BaseChangePasswordContainer
1589                 {
1590                         public SuccessContainer (ChangePassword owner) : base (owner)
1591                         {
1592                                 ID = "SuccessContainerID";
1593                         }
1594
1595                         public Control ChangePasswordButton
1596                         {
1597                                 get { return FindControl ("Continue"); }
1598                         }
1599                 }
1600         }
1601 }
1602