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