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