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