1 //
2 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
3 //
4 // Authors:
5 //	Vladimir Krasnov <vladimirk@mainsoft.com>
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 //
26 
27 using System;
28 using System.Web;
29 using System.Web.UI;
30 using System.Web.Security;
31 using System.Collections;
32 using System.Collections.Specialized;
33 using System.ComponentModel;
34 using System.Text;
35 using System.Net.Mail;
36 
37 namespace System.Web.UI.WebControls
38 {
39 	[DefaultEvent ("CreatedUser")]
40 	[Designer ("System.Web.UI.Design.WebControls.CreateUserWizardDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
41 	[ToolboxData ("   ")]
42 	[Bindable (false)]
43 	public class CreateUserWizard : Wizard
44 	{
45 		public static readonly string ContinueButtonCommandName = "Continue";
46 		string _password = String.Empty;
47 		string _confirmPassword = String.Empty;
48 		MembershipProvider _provider = null;
49 		ITextControl _errorMessageLabel = null;
50 		MailDefinition _mailDefinition = null;
51 
52 		Style _textBoxStyle = null;
53 		Style _validatorTextStyle = null;
54 
55 		TableItemStyle _completeSuccessTextStyle = null;
56 		TableItemStyle _errorMessageStyle = null;
57 		TableItemStyle _hyperLinkStyle = null;
58 		TableItemStyle _instructionTextStyle = null;
59 		TableItemStyle _labelStyle = null;
60 		TableItemStyle _passwordHintStyle = null;
61 		TableItemStyle _titleTextStyle = null;
62 		Style _createUserButtonStyle;
63 		Style _continueButtonStyle;
64 
65 		static readonly object CreatedUserEvent = new object ();
66 		static readonly object CreateUserErrorEvent = new object ();
67 		static readonly object CreatingUserEvent = new object ();
68 		static readonly object ContinueButtonClickEvent = new object ();
69 		static readonly object SendingMailEvent = new object ();
70 		static readonly object SendMailErrorEvent = new object ();
71 
72 		CompleteWizardStep _completeWizardStep = null;
73 		CreateUserWizardStep _createUserWizardStep = null;
74 
CreateUserWizard()75 		public CreateUserWizard ()
76 		{
77 		}
78 
79 		#region Public Properties
80 
81 		[DefaultValue (0)]
82 		public override int ActiveStepIndex {
83 			get { return base.ActiveStepIndex; }
84 			set { base.ActiveStepIndex = value; }
85 		}
86 
87 		[DefaultValue ("")]
88 		[LocalizableAttribute (true)]
89 		[ThemeableAttribute (false)]
90 		public virtual string Answer {
91 			get {
92 				object o = ViewState ["Answer"];
93 				return (o == null) ? String.Empty : (string) o;
94 			}
95 			set {
96 				if (value == null)
97 					ViewState.Remove ("Answer");
98 				else
99 					ViewState ["Answer"] = value;
100 			}
101 		}
102 
103 		[LocalizableAttribute (true)]
104 		public virtual string AnswerLabelText {
105 			get {
106 				object o = ViewState ["AnswerLabelText"];
107 				return (o == null) ? Locale.GetText ("Security Answer:") : (string) o;
108 			}
109 			set {
110 				if (value == null)
111 					ViewState.Remove ("AnswerLabelText");
112 				else
113 					ViewState ["AnswerLabelText"] = value;
114 			}
115 		}
116 
117 		[LocalizableAttribute (true)]
118 		public virtual string AnswerRequiredErrorMessage {
119 			get {
120 				object o = ViewState ["AnswerRequiredErrorMessage"];
121 				return (o == null) ? Locale.GetText ("Security answer is required.") : (string) o;
122 			}
123 			set {
124 				if (value == null)
125 					ViewState.Remove ("AnswerRequiredErrorMessage");
126 				else
127 					ViewState ["AnswerRequiredErrorMessage"] = value;
128 			}
129 		}
130 
131 		[DefaultValue (false)]
132 		[ThemeableAttribute (false)]
133 		public virtual bool AutoGeneratePassword {
134 			get {
135 				object o = ViewState ["AutoGeneratePassword"];
136 				return (o == null) ? false : (bool) o;
137 			}
138 			set { ViewState ["AutoGeneratePassword"] = value; }
139 		}
140 
141 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
142 		[Browsable (false)]
143 		public CompleteWizardStep CompleteStep {
144 			get {
145 				if (_completeWizardStep == null) {
146 					for (int i = 0; i < WizardSteps.Count; i++)
147 						if (WizardSteps [i] is CompleteWizardStep) {
148 							_completeWizardStep = (CompleteWizardStep) WizardSteps [i];
149 
150 							if (_completeWizardStep.Wizard == null)
151 								_completeWizardStep.SetWizard (this);
152 						}
153 				}
154 				return _completeWizardStep;
155 			}
156 		}
157 
158 		[LocalizableAttribute (true)]
159 		public virtual string CompleteSuccessText {
160 			get {
161 				object o = ViewState ["CompleteSuccessText"];
162 				return (o == null) ? Locale.GetText ("Your account has been successfully created.") : (string) o;
163 			}
164 			set {
165 				if (value == null)
166 					ViewState.Remove ("CompleteSuccessText");
167 				else
168 					ViewState ["CompleteSuccessText"] = value;
169 			}
170 		}
171 
172 		[DefaultValue (null)]
173 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
174 		[NotifyParentProperty (true)]
175 		[PersistenceMode (PersistenceMode.InnerProperty)]
176 		public TableItemStyle CompleteSuccessTextStyle {
177 			get {
178 				if (_completeSuccessTextStyle == null) {
179 					_completeSuccessTextStyle = new TableItemStyle ();
180 					if (IsTrackingViewState)
181 						((IStateManager) _completeSuccessTextStyle).TrackViewState ();
182 				}
183 				return _completeSuccessTextStyle;
184 			}
185 		}
186 
187 		[Browsable (false)]
188 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
189 		public virtual string ConfirmPassword {
190 			get { return _confirmPassword; }
191 		}
192 
193 		[LocalizableAttribute (true)]
194 		public virtual string ConfirmPasswordCompareErrorMessage {
195 			get {
196 				object o = ViewState ["ConfirmPasswordCompareErrorMessage"];
197 				return (o == null) ? Locale.GetText ("The Password and Confirmation Password must match.") : (string) o;
198 			}
199 			set {
200 				if (value == null)
201 					ViewState.Remove ("ConfirmPasswordCompareErrorMessage");
202 				else
203 					ViewState ["ConfirmPasswordCompareErrorMessage"] = value;
204 			}
205 		}
206 
207 		[LocalizableAttribute (true)]
208 		public virtual string ConfirmPasswordLabelText {
209 			get {
210 				object o = ViewState ["ConfirmPasswordLabelText"];
211 				return (o == null) ? Locale.GetText ("Confirm Password:") : (string) o;
212 			}
213 			set {
214 				if (value == null)
215 					ViewState.Remove ("ConfirmPasswordLabelText");
216 				else
217 					ViewState ["ConfirmPasswordLabelText"] = value;
218 			}
219 		}
220 
221 		[LocalizableAttribute (true)]
222 		public virtual string ConfirmPasswordRequiredErrorMessage {
223 			get {
224 				object o = ViewState ["ConfirmPasswordRequiredErrorMessage"];
225 				return (o == null) ? Locale.GetText ("Confirm Password is required.") : (string) o;
226 			}
227 			set {
228 				if (value == null)
229 					ViewState.Remove ("ConfirmPasswordRequiredErrorMessage");
230 				else
231 					ViewState ["ConfirmPasswordRequiredErrorMessage"] = value;
232 			}
233 		}
234 
235 		[DefaultValue ("")]
236 		[UrlProperty]
237 		[Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
238 		public virtual string ContinueButtonImageUrl {
239 			get { return ViewState.GetString ("ContinueButtonImageUrl", String.Empty); }
240 			set { ViewState ["ContinueButtonImageUrl"] = value; }
241 		}
242 
243 		[DefaultValue (null)]
244 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
245 		[NotifyParentProperty (true)]
246 		[PersistenceMode (PersistenceMode.InnerProperty)]
247 		public Style ContinueButtonStyle {
248 			get {
249 				if (_continueButtonStyle == null) {
250 					_continueButtonStyle = new Style ();
251 					if (IsTrackingViewState)
252 						((IStateManager) _continueButtonStyle).TrackViewState ();
253 				}
254 				return _continueButtonStyle;
255 			}
256 		}
257 
258 		[LocalizableAttribute (true)]
259 		public virtual string ContinueButtonText {
260 			get { return ViewState.GetString ("ContinueButtonText", "Continue"); }
261 			set { ViewState ["ContinueButtonText"] = value; }
262 		}
263 
264 		[DefaultValue (ButtonType.Button)]
265 		public virtual ButtonType ContinueButtonType {
266 			get {
267 				object v = ViewState ["ContinueButtonType"];
268 				return v != null ? (ButtonType) v : ButtonType.Button;
269 			}
270 			set {
271 				ViewState ["ContinueButtonType"] = value;
272 			}
273 		}
274 
275 		[DefaultValue ("")]
276 		[UrlProperty]
277 		[Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
278 		[ThemeableAttribute (false)]
279 		public virtual string ContinueDestinationPageUrl {
280 			get {
281 				object o = ViewState ["ContinueDestinationPageUrl"];
282 				return (o == null) ? "" : (string) o;
283 			}
284 			set {
285 				if (value == null)
286 					ViewState.Remove ("ContinueDestinationPageUrl");
287 				else
288 					ViewState ["ContinueDestinationPageUrl"] = value;
289 			}
290 		}
291 
292 		[DefaultValue ("")]
293 		[UrlProperty]
294 		[Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
295 		public virtual string CreateUserButtonImageUrl {
296 			get { return ViewState.GetString ("CreateUserButtonImageUrl", String.Empty); }
297 			set { ViewState ["CreateUserButtonImageUrl"] = value; }
298 		}
299 
300 		[DefaultValue (null)]
301 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
302 		[NotifyParentProperty (true)]
303 		[PersistenceMode (PersistenceMode.InnerProperty)]
304 		public Style CreateUserButtonStyle {
305 			get {
306 				if (_createUserButtonStyle == null) {
307 					_createUserButtonStyle = new Style ();
308 					if (IsTrackingViewState)
309 						((IStateManager) _createUserButtonStyle).TrackViewState ();
310 				}
311 				return _createUserButtonStyle;
312 			}
313 		}
314 
315 		[LocalizableAttribute (true)]
316 		public virtual string CreateUserButtonText {
317 			get { return ViewState.GetString ("CreateUserButtonText", "Create User"); }
318 			set { ViewState ["CreateUserButtonText"] = value; }
319 		}
320 
321 		[DefaultValue (ButtonType.Button)]
322 		public virtual ButtonType CreateUserButtonType {
323 			get {
324 				object v = ViewState ["CreateUserButtonType"];
325 				return v != null ? (ButtonType) v : ButtonType.Button;
326 			}
327 			set { ViewState ["CreateUserButtonType"] = value; }
328 		}
329 
330 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
331 		[Browsable (false)]
332 		public CreateUserWizardStep CreateUserStep {
333 			get {
334 				if (_createUserWizardStep == null) {
335 					for (int i = 0; i < WizardSteps.Count; i++)
336 						if (WizardSteps [i] is CreateUserWizardStep) {
337 							_createUserWizardStep = (CreateUserWizardStep) WizardSteps [i];
338 
339 							if (_createUserWizardStep.Wizard == null)
340 								_createUserWizardStep.SetWizard (this);
341 						}
342 				}
343 				return _createUserWizardStep;
344 			}
345 		}
346 
347 		[DefaultValue (false)]
348 		[ThemeableAttribute (false)]
349 		public virtual bool DisableCreatedUser {
350 			get {
351 				object o = ViewState ["DisableCreatedUser"];
352 				return (o == null) ? false : (bool) o;
353 			}
354 			set { ViewState ["DisableCreatedUser"] = value; }
355 		}
356 
357 		[DefaultValue (false)]
358 		public override bool DisplaySideBar {
359 			get { return ViewState.GetBool ("DisplaySideBar", false); }
360 			set {
361 				ViewState ["DisplaySideBar"] = value;
362 				ChildControlsCreated = false;
363 			}
364 		}
365 
366 		[LocalizableAttribute (true)]
367 		public virtual string DuplicateEmailErrorMessage {
368 			get {
369 				object o = ViewState ["DuplicateEmailErrorMessage"];
370 				return (o == null) ? Locale.GetText ("The e-mail address that you entered is already in use. Please enter a different e-mail address.") : (string) o;
371 			}
372 			set {
373 				if (value == null)
374 					ViewState.Remove ("DuplicateEmailErrorMessage");
375 				else
376 					ViewState ["DuplicateEmailErrorMessage"] = value;
377 			}
378 		}
379 
380 		[LocalizableAttribute (true)]
381 		public virtual string DuplicateUserNameErrorMessage {
382 			get {
383 				object o = ViewState ["DuplicateUserNameErrorMessage"];
384 				return (o == null) ? Locale.GetText ("Please enter a different user name.") : (string) o;
385 			}
386 			set {
387 				if (value == null)
388 					ViewState.Remove ("DuplicateUserNameErrorMessage");
389 				else
390 					ViewState ["DuplicateUserNameErrorMessage"] = value;
391 			}
392 		}
393 
394 		[DefaultValue ("")]
395 		[UrlProperty]
396 		[Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
397 		public virtual string EditProfileIconUrl {
398 			get {
399 				object o = ViewState ["EditProfileIconUrl"];
400 				return (o == null) ? String.Empty : (string) o;
401 			}
402 			set {
403 				if (value == null)
404 					ViewState.Remove ("EditProfileIconUrl");
405 				else
406 					ViewState ["EditProfileIconUrl"] = value;
407 			}
408 		}
409 
410 		[DefaultValue ("")]
411 		[LocalizableAttribute (true)]
412 		public virtual string EditProfileText {
413 			get {
414 				object o = ViewState ["EditProfileText"];
415 				return (o == null) ? String.Empty : (string) o;
416 			}
417 			set {
418 				if (value == null)
419 					ViewState.Remove ("EditProfileText");
420 				else
421 					ViewState ["EditProfileText"] = value;
422 			}
423 		}
424 
425 		[DefaultValue ("")]
426 		[UrlProperty]
427 		[Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
428 		public virtual string EditProfileUrl {
429 			get {
430 				object o = ViewState ["EditProfileUrl"];
431 				return (o == null) ? String.Empty : (string) o;
432 			}
433 			set {
434 				if (value == null)
435 					ViewState.Remove ("EditProfileUrl");
436 				else
437 					ViewState ["EditProfileUrl"] = value;
438 			}
439 		}
440 
441 		[DefaultValue ("")]
442 		public virtual string Email {
443 			get {
444 				object o = ViewState ["Email"];
445 				return (o == null) ? String.Empty : (string) o;
446 			}
447 			set {
448 				if (value == null)
449 					ViewState.Remove ("Email");
450 				else
451 					ViewState ["Email"] = value;
452 			}
453 		}
454 
455 		[LocalizableAttribute (true)]
456 		public virtual string EmailLabelText {
457 			get {
458 				object o = ViewState ["EmailLabelText"];
459 				return (o == null) ? Locale.GetText ("E-mail:") : (string) o;
460 			}
461 			set {
462 				if (value == null)
463 					ViewState.Remove ("EmailLabelText");
464 				else
465 					ViewState ["EmailLabelText"] = value;
466 			}
467 		}
468 
469 		public virtual string EmailRegularExpression {
470 			get {
471 				object o = ViewState ["EmailRegularExpression"];
472 				return (o == null) ? String.Empty : (string) o;
473 			}
474 			set {
475 				if (value == null)
476 					ViewState.Remove ("EmailRegularExpression");
477 				else
478 					ViewState ["EmailRegularExpression"] = value;
479 			}
480 		}
481 
482 		public virtual string EmailRegularExpressionErrorMessage {
483 			get {
484 				object o = ViewState ["EmailRegularExpressionErrorMessage"];
485 				return (o == null) ? Locale.GetText ("Please enter a different e-mail.") : (string) o;
486 			}
487 			set {
488 				if (value == null)
489 					ViewState.Remove ("EmailRegularExpressionErrorMessage");
490 				else
491 					ViewState ["EmailRegularExpressionErrorMessage"] = value;
492 			}
493 		}
494 
495 		[LocalizableAttribute (true)]
496 		public virtual string EmailRequiredErrorMessage {
497 			get {
498 				object o = ViewState ["EmailRequiredErrorMessage"];
499 				return (o == null) ? Locale.GetText ("E-mail is required.") : (string) o;
500 			}
501 			set {
502 				if (value == null)
503 					ViewState.Remove ("EmailRequiredErrorMessage");
504 				else
505 					ViewState ["EmailRequiredErrorMessage"] = value;
506 			}
507 		}
508 
509 		[DefaultValue (null)]
510 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
511 		[NotifyParentProperty (true)]
512 		[PersistenceMode (PersistenceMode.InnerProperty)]
513 		public TableItemStyle ErrorMessageStyle {
514 			get {
515 				if (_errorMessageStyle == null) {
516 					_errorMessageStyle = new TableItemStyle ();
517 					if (IsTrackingViewState)
518 						((IStateManager) _errorMessageStyle).TrackViewState ();
519 				}
520 				return _errorMessageStyle;
521 			}
522 		}
523 
524 		[DefaultValue ("")]
525 		[UrlProperty]
526 		[Editor ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
527 		public virtual string HelpPageIconUrl {
528 			get {
529 				object o = ViewState ["HelpPageIconUrl"];
530 				return (o == null) ? String.Empty : (string) o;
531 			}
532 			set {
533 				if (value == null)
534 					ViewState.Remove ("HelpPageIconUrl");
535 				else
536 					ViewState ["HelpPageIconUrl"] = value;
537 			}
538 		}
539 
540 		[DefaultValue ("")]
541 		[LocalizableAttribute (true)]
542 		public virtual string HelpPageText {
543 			get {
544 				object o = ViewState ["HelpPageText"];
545 				return (o == null) ? String.Empty : (string) o;
546 			}
547 			set {
548 				if (value == null)
549 					ViewState.Remove ("HelpPageText");
550 				else
551 					ViewState ["HelpPageText"] = value;
552 			}
553 		}
554 
555 		[DefaultValue ("")]
556 		[UrlProperty]
557 		[Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
558 		public virtual string HelpPageUrl {
559 			get {
560 				object o = ViewState ["HelpPageUrl"];
561 				return (o == null) ? String.Empty : (string) o;
562 			}
563 			set {
564 				if (value == null)
565 					ViewState.Remove ("HelpPageUrl");
566 				else
567 					ViewState ["HelpPageUrl"] = value;
568 			}
569 		}
570 
571 		[DefaultValue (null)]
572 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
573 		[NotifyParentProperty (true)]
574 		[PersistenceMode (PersistenceMode.InnerProperty)]
575 		public TableItemStyle HyperLinkStyle {
576 			get {
577 				if (_hyperLinkStyle == null) {
578 					_hyperLinkStyle = new TableItemStyle ();
579 					if (IsTrackingViewState)
580 						((IStateManager) _hyperLinkStyle).TrackViewState ();
581 				}
582 				return _hyperLinkStyle;
583 			}
584 		}
585 
586 		[DefaultValue ("")]
587 		[LocalizableAttribute (true)]
588 		public virtual string InstructionText {
589 			get {
590 				object o = ViewState ["InstructionText"];
591 				return (o == null) ? String.Empty : (string) o;
592 			}
593 			set {
594 				if (value == null)
595 					ViewState.Remove ("InstructionText");
596 				else
597 					ViewState ["InstructionText"] = value;
598 			}
599 		}
600 
601 		[DefaultValue (null)]
602 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
603 		[NotifyParentProperty (true)]
604 		[PersistenceMode (PersistenceMode.InnerProperty)]
605 		public TableItemStyle InstructionTextStyle {
606 			get {
607 				if (_instructionTextStyle == null) {
608 					_instructionTextStyle = new TableItemStyle ();
609 					if (IsTrackingViewState)
610 						((IStateManager) _instructionTextStyle).TrackViewState ();
611 				}
612 				return _instructionTextStyle;
613 			}
614 		}
615 
616 		[LocalizableAttribute (true)]
617 		public virtual string InvalidAnswerErrorMessage {
618 			get {
619 				object o = ViewState ["InvalidAnswerErrorMessage"];
620 				return (o == null) ? Locale.GetText ("Please enter a different security answer.") : (string) o;
621 			}
622 			set {
623 				if (value == null)
624 					ViewState.Remove ("InvalidAnswerErrorMessage");
625 				else
626 					ViewState ["InvalidAnswerErrorMessage"] = value;
627 			}
628 		}
629 
630 		[LocalizableAttribute (true)]
631 		public virtual string InvalidEmailErrorMessage {
632 			get {
633 				object o = ViewState ["InvalidEmailErrorMessage"];
634 				return (o == null) ? Locale.GetText ("Please enter a valid e-mail address.") : (string) o;
635 			}
636 			set {
637 				if (value == null)
638 					ViewState.Remove ("InvalidEmailErrorMessage");
639 				else
640 					ViewState ["InvalidEmailErrorMessage"] = value;
641 			}
642 		}
643 
644 		[MonoTODO ("take the values from membership provider")]
645 		[LocalizableAttribute (true)]
646 		public virtual string InvalidPasswordErrorMessage {
647 			get {
648 				object o = ViewState ["InvalidPasswordErrorMessage"];
649 				return (o == null) ? Locale.GetText ("Password length minimum: {0}. Non-alphanumeric characters required: {1}.") : (string) o;
650 			}
651 			set {
652 				if (value == null)
653 					ViewState.Remove ("InvalidPasswordErrorMessage");
654 				else
655 					ViewState ["InvalidPasswordErrorMessage"] = value;
656 			}
657 		}
658 
659 		[LocalizableAttribute (true)]
660 		public virtual string InvalidQuestionErrorMessage {
661 			get {
662 				object o = ViewState ["InvalidQuestionErrorMessage"];
663 				return (o == null) ? Locale.GetText ("Please enter a different security question.") : (string) o;
664 			}
665 			set {
666 				if (value == null)
667 					ViewState.Remove ("InvalidQuestionErrorMessage");
668 				else
669 					ViewState ["InvalidQuestionErrorMessage"] = value;
670 			}
671 		}
672 
673 		[DefaultValue (null)]
674 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
675 		[NotifyParentProperty (true)]
676 		[PersistenceMode (PersistenceMode.InnerProperty)]
677 		public TableItemStyle LabelStyle {
678 			get {
679 				if (_labelStyle == null) {
680 					_labelStyle = new TableItemStyle ();
681 					if (IsTrackingViewState)
682 						((IStateManager) _labelStyle).TrackViewState ();
683 				}
684 				return _labelStyle;
685 			}
686 		}
687 
688 		[DefaultValue (true)]
689 		[ThemeableAttribute (false)]
690 		public virtual bool LoginCreatedUser {
691 			get {
692 				object o = ViewState ["LoginCreatedUser"];
693 				return (o == null) ? true : (bool) o;
694 			}
695 			set {
696 				ViewState ["LoginCreatedUser"] = value;
697 			}
698 		}
699 
700 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
701 		[NotifyParentProperty (true)]
702 		[PersistenceMode (PersistenceMode.InnerProperty)]
703 		[ThemeableAttribute (false)]
704 		public MailDefinition MailDefinition {
705 			get {
706 				if (this._mailDefinition == null) {
707 					this._mailDefinition = new MailDefinition();
708 					if (IsTrackingViewState)
709 						((IStateManager) _mailDefinition).TrackViewState ();
710 				}
711 				return _mailDefinition;
712 			}
713 		}
714 
715 		[DefaultValue ("")]
716 		[ThemeableAttribute (false)]
717 		public virtual string MembershipProvider {
718 			get {
719 				object o = ViewState ["MembershipProvider"];
720 				return (o == null) ? String.Empty : (string) o;
721 			}
722 			set {
723 				if (value == null)
724 					ViewState.Remove ("MembershipProvider");
725 				else
726 					ViewState ["MembershipProvider"] = value;
727 
728 				_provider = null;
729 			}
730 		}
731 
732 		internal virtual MembershipProvider MembershipProviderInternal {
733 			get {
734 				if (_provider == null)
735 					InitMemberShipProvider ();
736 
737 				return _provider;
738 			}
739 		}
740 
741 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
742 		[Browsable (false)]
743 		public virtual string Password {
744 			get { return _password; }
745 		}
746 
747 		[DefaultValue (null)]
748 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
749 		[NotifyParentProperty (true)]
750 		[PersistenceMode (PersistenceMode.InnerProperty)]
751 		public TableItemStyle PasswordHintStyle {
752 			get {
753 				if (_passwordHintStyle == null) {
754 					_passwordHintStyle = new TableItemStyle ();
755 					if (IsTrackingViewState)
756 						((IStateManager) _passwordHintStyle).TrackViewState ();
757 				}
758 				return _passwordHintStyle;
759 			}
760 		}
761 
762 		[LocalizableAttribute (true)]
763 		public virtual string PasswordHintText {
764 			get {
765 				object o = ViewState ["PasswordHintText"];
766 				return (o == null) ? String.Empty : (string) o;
767 			}
768 			set {
769 				if (value == null)
770 					ViewState.Remove ("PasswordHintText");
771 				else
772 					ViewState ["PasswordHintText"] = value;
773 			}
774 		}
775 
776 		[LocalizableAttribute (true)]
777 		public virtual string PasswordLabelText {
778 			get {
779 				object o = ViewState ["PasswordLabelText"];
780 				return (o == null) ? Locale.GetText ("Password:") : (string) o;
781 			}
782 			set {
783 				if (value == null)
784 					ViewState.Remove ("PasswordLabelText");
785 				else
786 					ViewState ["PasswordLabelText"] = value;
787 			}
788 		}
789 
790 		public virtual string PasswordRegularExpression {
791 			get {
792 				object o = ViewState ["PasswordRegularExpression"];
793 				return (o == null) ? String.Empty : (string) o;
794 			}
795 			set {
796 				if (value == null)
797 					ViewState.Remove ("PasswordRegularExpression");
798 				else
799 					ViewState ["PasswordRegularExpression"] = value;
800 			}
801 		}
802 
803 		public virtual string PasswordRegularExpressionErrorMessage {
804 			get {
805 				object o = ViewState ["PasswordRegularExpressionErrorMessage"];
806 				return (o == null) ? Locale.GetText ("Please enter a different password.") : (string) o;
807 			}
808 			set {
809 				if (value == null)
810 					ViewState.Remove ("PasswordRegularExpressionErrorMessage");
811 				else
812 					ViewState ["PasswordRegularExpressionErrorMessage"] = value;
813 			}
814 		}
815 
816 		[LocalizableAttribute (true)]
817 		public virtual string PasswordRequiredErrorMessage {
818 			get {
819 				object o = ViewState ["PasswordRequiredErrorMessage"];
820 				return (o == null) ? Locale.GetText ("Password is required.") : (string) o;
821 			}
822 			set {
823 				if (value == null)
824 					ViewState.Remove ("PasswordRequiredErrorMessage");
825 				else
826 					ViewState ["PasswordRequiredErrorMessage"] = value;
827 			}
828 		}
829 
830 		[DefaultValue ("")]
831 		[LocalizableAttribute (true)]
832 		[ThemeableAttribute (false)]
833 		public virtual string Question {
834 			get {
835 				object o = ViewState ["Question"];
836 				return (o == null) ? String.Empty : (string) o;
837 			}
838 			set {
839 				if (value == null)
840 					ViewState.Remove ("Question");
841 				else
842 					ViewState ["Question"] = value;
843 			}
844 		}
845 
846 		[LocalizableAttribute (true)]
847 		public virtual string QuestionLabelText {
848 			get {
849 				object o = ViewState ["QuestionLabelText"];
850 				return (o == null) ? Locale.GetText ("Security Question:") : (string) o;
851 			}
852 			set {
853 				if (value == null)
854 					ViewState.Remove ("QuestionLabelText");
855 				else
856 					ViewState ["QuestionLabelText"] = value;
857 			}
858 		}
859 
860 		[LocalizableAttribute (true)]
861 		public virtual string QuestionRequiredErrorMessage {
862 			get {
863 				object o = ViewState ["QuestionRequiredErrorMessage"];
864 				return (o == null) ? Locale.GetText ("Security question is required.") : (string) o;
865 			}
866 			set {
867 				if (value == null)
868 					ViewState.Remove ("QuestionRequiredErrorMessage");
869 				else
870 					ViewState ["QuestionRequiredErrorMessage"] = value;
871 			}
872 		}
873 
874 		[DefaultValue (true)]
875 		[ThemeableAttribute (false)]
876 		public virtual bool RequireEmail {
877 			get {
878 				object o = ViewState ["RequireEmail"];
879 				return (o == null) ? true : (bool) o;
880 			}
881 			set {
882 				ViewState ["RequireEmail"] = value;
883 			}
884 		}
885 
886 		[DefaultValue ("")]
887 		[MonoTODO ("doesnt work")]
888 		public override string SkipLinkText {
889 			get {
890 				object o = ViewState ["SkipLinkText"];
891 				return (o == null) ? String.Empty : (string) o;
892 			}
893 			set {
894 				if (value == null)
895 					ViewState.Remove ("SkipLinkText");
896 				else
897 					ViewState ["SkipLinkText"] = value;
898 			}
899 		}
900 
901 		[DefaultValue (null)]
902 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
903 		[NotifyParentProperty (true)]
904 		[PersistenceMode (PersistenceMode.InnerProperty)]
905 		public Style TextBoxStyle {
906 			get {
907 				if (_textBoxStyle == null) {
908 					_textBoxStyle = new Style ();
909 					if (IsTrackingViewState)
910 						((IStateManager) _textBoxStyle).TrackViewState ();
911 				}
912 				return _textBoxStyle;
913 			}
914 		}
915 
916 		[DefaultValue (null)]
917 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
918 		[NotifyParentProperty (true)]
919 		[PersistenceMode (PersistenceMode.InnerProperty)]
920 		public TableItemStyle TitleTextStyle {
921 			get {
922 				if (_titleTextStyle == null) {
923 					_titleTextStyle = new TableItemStyle ();
924 					if (IsTrackingViewState)
925 						((IStateManager) _titleTextStyle).TrackViewState ();
926 				}
927 				return _titleTextStyle;
928 			}
929 		}
930 
931 		[LocalizableAttribute (true)]
932 		public virtual string UnknownErrorMessage {
933 			get {
934 				object o = ViewState ["UnknownErrorMessage"];
935 				return (o == null) ? Locale.GetText ("Your account was not created. Please try again.") : (string) o;
936 			}
937 			set {
938 				if (value == null)
939 					ViewState.Remove ("UnknownErrorMessage");
940 				else
941 					ViewState ["UnknownErrorMessage"] = value;
942 			}
943 		}
944 
945 		[DefaultValue ("")]
946 		public virtual string UserName {
947 			get {
948 				object o = ViewState ["UserName"];
949 				return (o == null) ? String.Empty : (string) o;
950 			}
951 			set {
952 				if (value == null)
953 					ViewState.Remove ("UserName");
954 				else
955 					ViewState ["UserName"] = value;
956 			}
957 		}
958 
959 		[LocalizableAttribute (true)]
960 		public virtual string UserNameLabelText {
961 			get {
962 				object o = ViewState ["UserNameLabelText"];
963 				return (o == null) ? Locale.GetText ("User Name:") : (string) o;
964 			}
965 			set {
966 				if (value == null)
967 					ViewState.Remove ("UserNameLabelText");
968 				else
969 					ViewState ["UserNameLabelText"] = value;
970 			}
971 		}
972 
973 		[LocalizableAttribute (true)]
974 		public virtual string UserNameRequiredErrorMessage {
975 			get {
976 				object o = ViewState ["UserNameRequiredErrorMessage"];
977 				return (o == null) ? Locale.GetText ("User Name is required.") : (string) o;
978 			}
979 			set {
980 				if (value == null)
981 					ViewState.Remove ("UserNameRequiredErrorMessage");
982 				else
983 					ViewState ["UserNameRequiredErrorMessage"] = value;
984 			}
985 		}
986 
987 		[DefaultValue (null)]
988 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
989 		[NotifyParentProperty (true)]
990 		[PersistenceMode (PersistenceMode.InnerProperty)]
991 		public Style ValidatorTextStyle {
992 			get {
993 				if (_validatorTextStyle == null) {
994 					_validatorTextStyle = new Style ();
995 					if (IsTrackingViewState)
996 						((IStateManager) _validatorTextStyle).TrackViewState ();
997 				}
998 				return _validatorTextStyle;
999 			}
1000 		}
1001 
1002 		[Editor ("System.Web.UI.Design.WebControls.CreateUserWizardStepCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
1003 		public override WizardStepCollection WizardSteps {
1004 			get { return base.WizardSteps; }
1005 		}
1006 
1007 		#endregion
1008 
1009 		#region Protected Properties
1010 
1011 		[DefaultValue (true)]
1012 		protected internal bool QuestionAndAnswerRequired {
1013 			get { return MembershipProviderInternal.RequiresQuestionAndAnswer; }
1014 		}
1015 
1016 		public event EventHandler ContinueButtonClick {
1017 			add { Events.AddHandler (ContinueButtonClickEvent, value); }
1018 			remove { Events.RemoveHandler (ContinueButtonClickEvent, value); }
1019 		}
1020 
1021 		public event EventHandler CreatedUser {
1022 			add { Events.AddHandler (CreatedUserEvent, value); }
1023 			remove { Events.RemoveHandler (CreatedUserEvent, value); }
1024 		}
1025 
1026 		public event CreateUserErrorEventHandler CreateUserError {
1027 			add { Events.AddHandler (CreateUserErrorEvent, value); }
1028 			remove { Events.RemoveHandler (CreateUserErrorEvent, value); }
1029 		}
1030 
1031 		public event LoginCancelEventHandler CreatingUser {
1032 			add { Events.AddHandler (CreatingUserEvent, value); }
1033 			remove { Events.RemoveHandler (CreatingUserEvent, value); }
1034 		}
1035 
1036 		public event MailMessageEventHandler SendingMail {
1037 			add { Events.AddHandler (SendingMailEvent, value); }
1038 			remove { Events.RemoveHandler (SendingMailEvent, value); }
1039 		}
1040 
1041 		public event SendMailErrorEventHandler SendMailError {
1042 			add { Events.AddHandler (SendMailErrorEvent, value); }
1043 			remove { Events.RemoveHandler (SendMailErrorEvent, value); }
1044 		}
1045 
1046 
1047 		#endregion
1048 
1049 		#region Internal Properties
1050 
InstantiateTemplateStep(TemplatedWizardStep step)1051 		internal override void InstantiateTemplateStep (TemplatedWizardStep step)
1052 		{
1053 			if (step is CreateUserWizardStep)
1054 				InstantiateCreateUserWizardStep ((CreateUserWizardStep) step);
1055 			else if (step is CompleteWizardStep)
1056 				InstantiateCompleteWizardStep ((CompleteWizardStep) step);
1057 			else
1058 				base.InstantiateTemplateStep (step);
1059 		}
1060 
InstantiateCompleteWizardStep(CompleteWizardStep step)1061 		void InstantiateCompleteWizardStep (CompleteWizardStep step)
1062 		{
1063 			CompleteStepContainer contentTemplateContainer = new CompleteStepContainer (this);
1064 			if (step.ContentTemplate != null)
1065 				step.ContentTemplate.InstantiateIn (contentTemplateContainer.InnerCell);
1066 			else {
1067 				new CompleteStepTemplate (this).InstantiateIn (contentTemplateContainer.InnerCell);
1068 				contentTemplateContainer.ConfirmDefaultTemplate ();
1069 			}
1070 
1071 			step.ContentTemplateContainer = contentTemplateContainer;
1072 			step.Controls.Clear ();
1073 			step.Controls.Add (contentTemplateContainer);
1074 
1075 			BaseWizardNavigationContainer customNavigationTemplateContainer = new BaseWizardNavigationContainer ();
1076 			if (step.CustomNavigationTemplate != null) {
1077 				step.CustomNavigationTemplate.InstantiateIn (customNavigationTemplateContainer);
1078 				RegisterCustomNavigation (step, customNavigationTemplateContainer);
1079 			}
1080 			step.CustomNavigationTemplateContainer = customNavigationTemplateContainer;
1081 		}
1082 
InstantiateCreateUserWizardStep(CreateUserWizardStep step)1083 		void InstantiateCreateUserWizardStep (CreateUserWizardStep step)
1084 		{
1085 			CreateUserStepContainer contentTemplateContainer = new CreateUserStepContainer (this);
1086 			if (step.ContentTemplate != null)
1087 				step.ContentTemplate.InstantiateIn (contentTemplateContainer.InnerCell);
1088 			else {
1089 				new CreateUserStepTemplate (this).InstantiateIn (contentTemplateContainer.InnerCell);
1090 				contentTemplateContainer.ConfirmDefaultTemplate ();
1091 				contentTemplateContainer.EnsureValidatorsState ();
1092 			}
1093 
1094 			step.ContentTemplateContainer = contentTemplateContainer;
1095 			step.Controls.Clear ();
1096 			step.Controls.Add (contentTemplateContainer);
1097 
1098 			CreateUserNavigationContainer customNavigationTemplateContainer = new CreateUserNavigationContainer (this);
1099 			if (step.CustomNavigationTemplate != null)
1100 				step.CustomNavigationTemplate.InstantiateIn (customNavigationTemplateContainer);
1101 			else {
1102 				new CreateUserStepNavigationTemplate (this).InstantiateIn (customNavigationTemplateContainer);
1103 				customNavigationTemplateContainer.ConfirmDefaultTemplate ();
1104 			}
1105 			RegisterCustomNavigation (step, customNavigationTemplateContainer);
1106 
1107 			step.CustomNavigationTemplateContainer = customNavigationTemplateContainer;
1108 		}
1109 
1110 		internal override ITemplate SideBarItemTemplate {
1111 			get { return new SideBarLabelTemplate (this); }
1112 		}
1113 
1114 		#endregion
1115 
1116 		#region Protected Methods
1117 
CreateChildControls()1118 		protected internal override void CreateChildControls ()
1119 		{
1120 			if (CreateUserStep == null)
1121 				WizardSteps.AddAt (0, new CreateUserWizardStep ());
1122 
1123 			if (CompleteStep == null)
1124 				WizardSteps.AddAt (WizardSteps.Count, new CompleteWizardStep ());
1125 
1126 			base.CreateChildControls ();
1127 		}
1128 
CreateControlHierarchy()1129 		protected override void CreateControlHierarchy ()
1130 		{
1131 			base.CreateControlHierarchy ();
1132 
1133 			CreateUserStepContainer container = CreateUserStep.ContentTemplateContainer as CreateUserStepContainer;
1134 
1135 			if (container != null) {
1136 				IEditableTextControl editable;
1137 				editable = container.UserNameTextBox as IEditableTextControl;
1138 
1139 				if (editable != null)
1140 					editable.TextChanged += new EventHandler (UserName_TextChanged);
1141 
1142 				if (!AutoGeneratePassword) {
1143 					editable = container.PasswordTextBox as IEditableTextControl;
1144 
1145 					if (editable != null)
1146 						editable.TextChanged += new EventHandler (Password_TextChanged);
1147 
1148 					editable = container.ConfirmPasswordTextBox as IEditableTextControl;
1149 
1150 					if (editable != null)
1151 						editable.TextChanged += new EventHandler (ConfirmPassword_TextChanged);
1152 				}
1153 
1154 				if (RequireEmail) {
1155 					editable = container.EmailTextBox as IEditableTextControl;
1156 
1157 					if (editable != null)
1158 						editable.TextChanged += new EventHandler (Email_TextChanged);
1159 				}
1160 
1161 				if (QuestionAndAnswerRequired) {
1162 					editable = container.QuestionTextBox as IEditableTextControl;
1163 
1164 					if (editable != null)
1165 						editable.TextChanged += new EventHandler (Question_TextChanged);
1166 
1167 					editable = container.AnswerTextBox as IEditableTextControl;
1168 
1169 					if (editable != null)
1170 						editable.TextChanged += new EventHandler (Answer_TextChanged);
1171 				}
1172 
1173 				_errorMessageLabel = container.ErrorMessageLabel;
1174 			}
1175 		}
1176 
1177 		[MonoTODO ("Not Implemented")]
GetDesignModeState()1178 		protected override IDictionary GetDesignModeState ()
1179 		{
1180 			throw new NotImplementedException ();
1181 		}
1182 
OnBubbleEvent(object source, EventArgs e)1183 		protected override bool OnBubbleEvent (object source, EventArgs e)
1184 		{
1185 			CommandEventArgs args = e as CommandEventArgs;
1186 			if (e != null && args.CommandName == ContinueButtonCommandName) {
1187 				ProcessContinueEvent ();
1188 				return true;
1189 			}
1190 			return base.OnBubbleEvent (source, e);
1191 		}
1192 
ProcessContinueEvent()1193 		void ProcessContinueEvent ()
1194 		{
1195 			OnContinueButtonClick (EventArgs.Empty);
1196 
1197 			if (ContinueDestinationPageUrl.Length > 0)
1198 				Context.Response.Redirect (ContinueDestinationPageUrl);
1199 		}
1200 
OnContinueButtonClick(EventArgs e)1201 		protected virtual void OnContinueButtonClick (EventArgs e)
1202 		{
1203 			if (Events != null) {
1204 				EventHandler eh = (EventHandler) Events [ContinueButtonClickEvent];
1205 				if (eh != null)
1206 					eh (this, e);
1207 			}
1208 		}
1209 
OnCreatedUser(EventArgs e)1210 		protected virtual void OnCreatedUser (EventArgs e)
1211 		{
1212 			if (Events != null) {
1213 				EventHandler eh = (EventHandler) Events [CreatedUserEvent];
1214 				if (eh != null)
1215 					eh (this, e);
1216 			}
1217 		}
1218 
OnCreateUserError(CreateUserErrorEventArgs e)1219 		protected virtual void OnCreateUserError (CreateUserErrorEventArgs e)
1220 		{
1221 			if (Events != null) {
1222 				CreateUserErrorEventHandler eh = (CreateUserErrorEventHandler) Events [CreateUserErrorEvent];
1223 				if (eh != null)
1224 					eh (this, e);
1225 			}
1226 		}
1227 
OnCreatingUser(LoginCancelEventArgs e)1228 		protected virtual void OnCreatingUser (LoginCancelEventArgs e)
1229 		{
1230 			if (Events != null) {
1231 				LoginCancelEventHandler eh = (LoginCancelEventHandler) Events [CreatingUserEvent];
1232 				if (eh != null)
1233 					eh (this, e);
1234 			}
1235 		}
1236 
OnNextButtonClick(WizardNavigationEventArgs e)1237 		protected override void OnNextButtonClick (WizardNavigationEventArgs e)
1238 		{
1239 			if (ActiveStep == CreateUserStep) {
1240 				bool userCreated = CreateUser ();
1241 				if (!userCreated)
1242 					e.Cancel = true;
1243 				else
1244 					if (LoginCreatedUser)
1245 						Login ();
1246 			}
1247 			base.OnNextButtonClick (e);
1248 		}
1249 
OnPreRender(EventArgs e)1250 		protected internal override void OnPreRender (EventArgs e)
1251 		{
1252 			base.OnPreRender (e);
1253 		}
1254 
OnSendingMail(MailMessageEventArgs e)1255 		protected virtual void OnSendingMail (MailMessageEventArgs e)
1256 		{
1257 			if (Events != null) {
1258 				MailMessageEventHandler eh = (MailMessageEventHandler) Events [SendingMailEvent];
1259 				if (eh != null)
1260 					eh (this, e);
1261 			}
1262 		}
1263 
OnSendMailError(SendMailErrorEventArgs e)1264 		protected virtual void OnSendMailError (SendMailErrorEventArgs e)
1265 		{
1266 			if (Events != null) {
1267 				SendMailErrorEventHandler eh = (SendMailErrorEventHandler) Events [SendMailErrorEvent];
1268 				if (eh != null) eh (this, e);
1269 			}
1270 		}
1271 
LoadViewState(object savedState)1272 		protected override void LoadViewState (object savedState)
1273 		{
1274 			if (savedState == null) {
1275 				base.LoadViewState (null);
1276 				return;
1277 			}
1278 
1279 			object [] states = (object []) savedState;
1280 			base.LoadViewState (states [0]);
1281 
1282 			if (states [1] != null)
1283 				((IStateManager) TextBoxStyle).LoadViewState (states [1]);
1284 			if (states [2] != null)
1285 				((IStateManager) ValidatorTextStyle).LoadViewState (states [2]);
1286 			if (states [3] != null)
1287 				((IStateManager) CompleteSuccessTextStyle).LoadViewState (states [3]);
1288 			if (states [4] != null)
1289 				((IStateManager) ErrorMessageStyle).LoadViewState (states [4]);
1290 			if (states [5] != null)
1291 				((IStateManager) HyperLinkStyle).LoadViewState (states [5]);
1292 			if (states [6] != null)
1293 				((IStateManager) InstructionTextStyle).LoadViewState (states [6]);
1294 			if (states [7] != null)
1295 				((IStateManager) LabelStyle).LoadViewState (states [7]);
1296 			if (states [8] != null)
1297 				((IStateManager) PasswordHintStyle).LoadViewState (states [8]);
1298 			if (states [9] != null)
1299 				((IStateManager) TitleTextStyle).LoadViewState (states [9]);
1300 			if (states [10] != null)
1301 				((IStateManager) CreateUserButtonStyle).LoadViewState (states [10]);
1302 			if (states [11] != null)
1303 				((IStateManager) ContinueButtonStyle).LoadViewState (states [11]);
1304 			if (states [12] != null)
1305 				((IStateManager) MailDefinition).LoadViewState (states [12]);
1306 
1307 			((CreateUserStepContainer) CreateUserStep.ContentTemplateContainer).EnsureValidatorsState ();
1308 		}
1309 
SaveViewState()1310 		protected override object SaveViewState ()
1311 		{
1312 			object [] state = new object [13];
1313 			state [0] = base.SaveViewState ();
1314 
1315 			if (_textBoxStyle != null)
1316 				state [1] = ((IStateManager) _textBoxStyle).SaveViewState ();
1317 			if (_validatorTextStyle != null)
1318 				state [2] = ((IStateManager) _validatorTextStyle).SaveViewState ();
1319 			if (_completeSuccessTextStyle != null)
1320 				state [3] = ((IStateManager) _completeSuccessTextStyle).SaveViewState ();
1321 			if (_errorMessageStyle != null)
1322 				state [4] = ((IStateManager) _errorMessageStyle).SaveViewState ();
1323 			if (_hyperLinkStyle != null)
1324 				state [5] = ((IStateManager) _hyperLinkStyle).SaveViewState ();
1325 			if (_instructionTextStyle != null)
1326 				state [6] = ((IStateManager) _instructionTextStyle).SaveViewState ();
1327 			if (_labelStyle != null)
1328 				state [7] = ((IStateManager) _labelStyle).SaveViewState ();
1329 			if (_passwordHintStyle != null)
1330 				state [8] = ((IStateManager) _passwordHintStyle).SaveViewState ();
1331 			if (_titleTextStyle != null)
1332 				state [9] = ((IStateManager) _titleTextStyle).SaveViewState ();
1333 			if (_createUserButtonStyle != null)
1334 				state [10] = ((IStateManager) _createUserButtonStyle).SaveViewState ();
1335 			if (_continueButtonStyle != null)
1336 				state [11] = ((IStateManager) _continueButtonStyle).SaveViewState ();
1337 			if (_mailDefinition != null)
1338 				state [12] = ((IStateManager) _mailDefinition).SaveViewState ();
1339 
1340 			for (int n = 0; n < state.Length; n++)
1341 				if (state [n] != null)
1342 					return state;
1343 
1344 			return null;
1345 		}
1346 
1347 		[MonoTODO ("for design-time usage - no more details available")]
SetDesignModeState(IDictionary data)1348 		protected override void SetDesignModeState (IDictionary data)
1349 		{
1350 			base.SetDesignModeState (data);
1351 		}
1352 
TrackViewState()1353 		protected override void TrackViewState ()
1354 		{
1355 			base.TrackViewState ();
1356 			if (_textBoxStyle != null)
1357 				((IStateManager) _textBoxStyle).TrackViewState ();
1358 			if (_validatorTextStyle != null)
1359 				((IStateManager) _validatorTextStyle).TrackViewState ();
1360 			if (_completeSuccessTextStyle != null)
1361 				((IStateManager) _completeSuccessTextStyle).TrackViewState ();
1362 			if (_errorMessageStyle != null)
1363 				((IStateManager) _errorMessageStyle).TrackViewState ();
1364 			if (_hyperLinkStyle != null)
1365 				((IStateManager) _hyperLinkStyle).TrackViewState ();
1366 			if (_instructionTextStyle != null)
1367 				((IStateManager) _instructionTextStyle).TrackViewState ();
1368 			if (_labelStyle != null)
1369 				((IStateManager) _labelStyle).TrackViewState ();
1370 			if (_passwordHintStyle != null)
1371 				((IStateManager) _passwordHintStyle).TrackViewState ();
1372 			if (_titleTextStyle != null)
1373 				((IStateManager) _titleTextStyle).TrackViewState ();
1374 			if (_createUserButtonStyle != null)
1375 				((IStateManager) _createUserButtonStyle).TrackViewState ();
1376 			if (_continueButtonStyle != null)
1377 				((IStateManager) _continueButtonStyle).TrackViewState ();
1378 			if (_mailDefinition != null)
1379 				((IStateManager) _mailDefinition).TrackViewState ();
1380 		}
1381 
1382 		#endregion
1383 
1384 		#region Private event handlers
1385 
UserName_TextChanged(object sender, EventArgs e)1386 		void UserName_TextChanged (object sender, EventArgs e)
1387 		{
1388 			UserName = ((ITextControl) sender).Text;
1389 		}
1390 
Password_TextChanged(object sender, EventArgs e)1391 		void Password_TextChanged (object sender, EventArgs e)
1392 		{
1393 			_password = ((ITextControl) sender).Text;
1394 		}
1395 
ConfirmPassword_TextChanged(object sender, EventArgs e)1396 		void ConfirmPassword_TextChanged (object sender, EventArgs e)
1397 		{
1398 			_confirmPassword = ((ITextControl) sender).Text;
1399 		}
1400 
Email_TextChanged(object sender, EventArgs e)1401 		void Email_TextChanged (object sender, EventArgs e)
1402 		{
1403 			Email = ((ITextControl) sender).Text;
1404 		}
1405 
Question_TextChanged(object sender, EventArgs e)1406 		void Question_TextChanged (object sender, EventArgs e)
1407 		{
1408 			Question = ((ITextControl) sender).Text;
1409 		}
1410 
Answer_TextChanged(object sender, EventArgs e)1411 		void Answer_TextChanged (object sender, EventArgs e)
1412 		{
1413 			Answer = ((ITextControl) sender).Text;
1414 		}
1415 
1416 		#endregion
1417 
1418 		#region Private Methods
1419 
InitMemberShipProvider()1420 		void InitMemberShipProvider ()
1421 		{
1422 			string mp = MembershipProvider;
1423 			_provider = (mp.Length == 0) ? _provider = Membership.Provider : Membership.Providers [mp];
1424 			if (_provider == null)
1425 				throw new HttpException (Locale.GetText ("No provider named '{0}' could be found.", mp));
1426 		}
1427 
CreateUser()1428 		bool CreateUser ()
1429 		{
1430 			if (!Page.IsValid)
1431 				return false;
1432 
1433 			if (AutoGeneratePassword)
1434 				_password = GeneratePassword ();
1435 
1436 			OnCreatingUser (new LoginCancelEventArgs (false));
1437 
1438 			MembershipCreateStatus status;
1439 			MembershipUser newUser = MembershipProviderInternal.CreateUser (
1440 				UserName, Password, Email, Question, Answer, !DisableCreatedUser, null, out status);
1441 
1442 			if ((newUser != null) && (status == MembershipCreateStatus.Success)) {
1443 				OnCreatedUser (new EventArgs ());
1444 				SendPasswordByMail (newUser, Password);
1445 				return true;
1446 			}
1447 
1448 			switch (status) {
1449 				case MembershipCreateStatus.DuplicateUserName:
1450 					ShowErrorMessage (DuplicateUserNameErrorMessage);
1451 					break;
1452 
1453 				case MembershipCreateStatus.InvalidPassword:
1454 					ShowErrorMessage (String.Format (InvalidPasswordErrorMessage, MembershipProviderInternal.MinRequiredPasswordLength, MembershipProviderInternal.MinRequiredNonAlphanumericCharacters));
1455 					break;
1456 
1457 				case MembershipCreateStatus.DuplicateEmail:
1458 					ShowErrorMessage (DuplicateEmailErrorMessage);
1459 					break;
1460 
1461 				case MembershipCreateStatus.InvalidEmail:
1462 					ShowErrorMessage (InvalidEmailErrorMessage);
1463 					break;
1464 
1465 				case MembershipCreateStatus.InvalidQuestion:
1466 					ShowErrorMessage (InvalidQuestionErrorMessage);
1467 					break;
1468 
1469 				case MembershipCreateStatus.InvalidAnswer:
1470 					ShowErrorMessage (InvalidAnswerErrorMessage);
1471 					break;
1472 
1473 				case MembershipCreateStatus.UserRejected:
1474 				case MembershipCreateStatus.InvalidUserName:
1475 				case MembershipCreateStatus.ProviderError:
1476 				case MembershipCreateStatus.InvalidProviderUserKey:
1477 					ShowErrorMessage (UnknownErrorMessage);
1478 					break;
1479 
1480 
1481 			}
1482 
1483 			OnCreateUserError (new CreateUserErrorEventArgs (status));
1484 
1485 			return false;
1486 		}
1487 
SendPasswordByMail(MembershipUser user, string password)1488 		void SendPasswordByMail (MembershipUser user, string password)
1489 		{
1490 			if (user == null)
1491 				return;
1492 
1493 			if (_mailDefinition == null)
1494 				return;
1495 
1496 			string messageText = "A new account has been created for you. Please go to the site and log in using the following information.\nUser Name: <%USERNAME%>\nPassword: <%PASSWORD%>";
1497 
1498 			ListDictionary dictionary = new ListDictionary ();
1499 			dictionary.Add ("<%USERNAME%>", user.UserName);
1500 			dictionary.Add ("<%PASSWORD%>", password);
1501 
1502 			MailMessage message = null;
1503 
1504 			if (MailDefinition.BodyFileName.Length == 0)
1505 				message = MailDefinition.CreateMailMessage (user.Email, dictionary, messageText, this);
1506 			else
1507 				message = MailDefinition.CreateMailMessage (user.Email, dictionary, this);
1508 
1509 			if (string.IsNullOrEmpty (message.Subject))
1510 				message.Subject = "Account information";
1511 
1512 			MailMessageEventArgs args = new MailMessageEventArgs (message);
1513 			OnSendingMail (args);
1514 
1515 			SmtpClient smtpClient = new SmtpClient ();
1516 			try {
1517 				smtpClient.Send (message);
1518 			} catch (Exception e) {
1519 				SendMailErrorEventArgs mailArgs = new SendMailErrorEventArgs (e);
1520 				OnSendMailError (mailArgs);
1521 				if (!mailArgs.Handled)
1522 					throw e;
1523 			}
1524 		}
1525 
Login()1526 		void Login ()
1527 		{
1528 			bool userValidated = MembershipProviderInternal.ValidateUser (UserName, Password);
1529 			if (userValidated)
1530 				FormsAuthentication.SetAuthCookie (UserName, false);
1531 		}
1532 
ShowErrorMessage(string errorMessage)1533 		void ShowErrorMessage (string errorMessage)
1534 		{
1535 			if (_errorMessageLabel != null)
1536 				_errorMessageLabel.Text = errorMessage;
1537 		}
1538 
GeneratePassword()1539 		string GeneratePassword ()
1540 		{
1541 			return Membership.GeneratePassword (8, 3);
1542 		}
1543 
1544 		#endregion
1545 
1546 		#region SideBarLabelTemplate
1547 
1548 		class SideBarLabelTemplate : ITemplate
1549 		{
1550 			Wizard wizard;
1551 
SideBarLabelTemplate(Wizard wizard)1552 			public SideBarLabelTemplate (Wizard wizard)
1553 			{
1554 				this.wizard = wizard;
1555 			}
1556 
InstantiateIn(Control control)1557 			public void InstantiateIn (Control control)
1558 			{
1559 				Label b = new Label ();
1560 				wizard.RegisterApplyStyle (b, wizard.SideBarButtonStyle);
1561 				control.Controls.Add (b);
1562 				control.DataBinding += Bound;
1563 			}
1564 
Bound(object s, EventArgs args)1565 			void Bound (object s, EventArgs args)
1566 			{
1567 				WizardStepBase step = DataBinder.GetDataItem (s) as WizardStepBase;
1568 				if (step != null) {
1569 					Control c = (Control) s;
1570 					Label b = (Label) c.Controls [0];
1571 					b.ID = SideBarButtonID;
1572 					b.Text = step.Title;
1573 				}
1574 			}
1575 		}
1576 
1577 		#endregion
1578 
1579 		sealed class CreateUserNavigationContainer : DefaultNavigationContainer
1580 		{
1581 			CreateUserWizard _createUserWizard;
1582 
CreateUserNavigationContainer(CreateUserWizard createUserWizard)1583 			public CreateUserNavigationContainer (CreateUserWizard createUserWizard)
1584 				: base (createUserWizard)
1585 			{
1586 				_createUserWizard = createUserWizard;
1587 			}
1588 
UpdateState()1589 			protected override void UpdateState ()
1590 			{
1591 				// previous
1592 				int previous = _createUserWizard.ActiveStepIndex - 1;
1593 				if (previous >= 0 && _createUserWizard.AllowNavigationToStep (previous))
1594 					UpdateNavButtonState (Wizard.StepPreviousButtonID + Wizard.StepPreviousButtonType, Wizard.StepPreviousButtonText, Wizard.StepPreviousButtonImageUrl, Wizard.StepPreviousButtonStyle);
1595 				else
1596 					((Table) Controls [0]).Rows [0].Cells [0].Visible = false;
1597 
1598 				// create user
1599 				UpdateNavButtonState (Wizard.StepNextButtonID + _createUserWizard.CreateUserButtonType, _createUserWizard.CreateUserButtonText, _createUserWizard.CreateUserButtonImageUrl, _createUserWizard.CreateUserButtonStyle);
1600 
1601 				// cancel
1602 				if (Wizard.DisplayCancelButton)
1603 					UpdateNavButtonState (Wizard.CancelButtonID + Wizard.CancelButtonType, Wizard.CancelButtonText, Wizard.CancelButtonImageUrl, Wizard.CancelButtonStyle);
1604 				else
1605 					((Table) Controls [0]).Rows [0].Cells [2].Visible = false;
1606 			}
1607 		}
1608 
1609 		sealed class CreateUserStepNavigationTemplate : ITemplate
1610 		{
1611 			readonly CreateUserWizard _createUserWizard;
1612 
CreateUserStepNavigationTemplate(CreateUserWizard createUserWizard)1613 			public CreateUserStepNavigationTemplate (CreateUserWizard createUserWizard) {
1614 				_createUserWizard = createUserWizard;
1615 			}
1616 
1617 			#region ITemplate Members
1618 
InstantiateIn(Control container)1619 			public void InstantiateIn (Control container)
1620 			{
1621 				Table t = new Table ();
1622 				t.CellPadding = 5;
1623 				t.CellSpacing = 5;
1624 				t.Width = Unit.Percentage (100);
1625 				t.Height = Unit.Percentage (100);
1626 				TableRow row = new TableRow ();
1627 
1628 				AddButtonCell (row, _createUserWizard.CreateButtonSet (Wizard.StepPreviousButtonID, Wizard.MovePreviousCommandName, false, _createUserWizard.ID));
1629 				AddButtonCell (row, _createUserWizard.CreateButtonSet (Wizard.StepNextButtonID, Wizard.MoveNextCommandName, true, _createUserWizard.ID));
1630 				AddButtonCell (row, _createUserWizard.CreateButtonSet (Wizard.CancelButtonID, Wizard.CancelCommandName, false, _createUserWizard.ID));
1631 
1632 				t.Rows.Add (row);
1633 				container.Controls.Add (t);
1634 			}
1635 
AddButtonCell(TableRow row, params Control [] controls)1636 			void AddButtonCell (TableRow row, params Control [] controls)
1637 			{
1638 				TableCell cell = new TableCell ();
1639 				cell.HorizontalAlign = HorizontalAlign.Right;
1640 				for (int i = 0; i < controls.Length; i++)
1641 					cell.Controls.Add (controls[i]);
1642 				row.Cells.Add (cell);
1643 			}
1644 
1645 			#endregion
1646 		}
1647 
1648 		sealed class CreateUserStepContainer : DefaultContentContainer
1649 		{
1650 			CreateUserWizard _createUserWizard;
1651 
CreateUserStepContainer(CreateUserWizard createUserWizard)1652 			public CreateUserStepContainer (CreateUserWizard createUserWizard)
1653 				: base (createUserWizard)
1654 			{
1655 				_createUserWizard = createUserWizard;
1656 			}
1657 
1658 			public Control UserNameTextBox {
1659 				get {
1660 					Control c = FindControl ("UserName");
1661 					if (c == null)
1662 						throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID UserName for the username.");
1663 
1664 					return c;
1665 				}
1666 			}
1667 			public Control PasswordTextBox {
1668 				get {
1669 					Control c = FindControl ("Password");
1670 					if (c == null)
1671 						throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Password for the new password, this is required if AutoGeneratePassword = true.");
1672 
1673 					return c;
1674 				}
1675 			}
1676 			public Control ConfirmPasswordTextBox {
1677 				get {
1678 					Control c = FindControl ("Password");
1679 					return c;
1680 				}
1681 			}
1682 			public Control EmailTextBox {
1683 				get {
1684 					Control c = FindControl ("Email");
1685 					if (c == null)
1686 						throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Email for the e-mail, this is required if RequireEmail = true.");
1687 
1688 					return c;
1689 				}
1690 			}
1691 			public Control QuestionTextBox {
1692 				get {
1693 					Control c = FindControl ("Question");
1694 					if (c == null)
1695 						throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Question for the security question, this is required if your membership provider requires a question and answer.");
1696 
1697 					return c;
1698 				}
1699 			}
1700 			public Control AnswerTextBox {
1701 				get {
1702 					Control c = FindControl ("Answer");
1703 					if (c == null)
1704 						throw new HttpException ("CreateUserWizardStep.ContentTemplate does not contain an IEditableTextControl with ID Answer for the security answer, this is required if your membership provider requires a question and answer.");
1705 
1706 					return c;
1707 				}
1708 			}
1709 			public ITextControl ErrorMessageLabel {
1710 				get { return FindControl ("ErrorMessage") as ITextControl; }
1711 			}
1712 
UpdateState()1713 			protected override void UpdateState ()
1714 			{
1715 				// Row #0 - title
1716 				if (String.IsNullOrEmpty (_createUserWizard.CreateUserStep.Title))
1717 					((Table) InnerCell.Controls [0]).Rows [0].Visible = false;
1718 				else
1719 					((Table) InnerCell.Controls [0]).Rows [0].Cells [0].Text = _createUserWizard.CreateUserStep.Title;
1720 
1721 				// Row #1 - InstructionText
1722 				if (String.IsNullOrEmpty (_createUserWizard.InstructionText))
1723 					((Table) InnerCell.Controls [0]).Rows [1].Visible = false;
1724 				else
1725 					((Table) InnerCell.Controls [0]).Rows [1].Cells [0].Text = _createUserWizard.InstructionText;
1726 
1727 				// Row #2
1728 				Label UserNameLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [2].Cells [0].Controls [0];
1729 				UserNameLabel.Text = _createUserWizard.UserNameLabelText;
1730 
1731 				RequiredFieldValidator UserNameRequired = (RequiredFieldValidator) FindControl ("UserNameRequired");
1732 				UserNameRequired.ErrorMessage = _createUserWizard.UserNameRequiredErrorMessage;
1733 				UserNameRequired.ToolTip = _createUserWizard.UserNameRequiredErrorMessage;
1734 
1735 				if (_createUserWizard.AutoGeneratePassword) {
1736 					((Table) InnerCell.Controls [0]).Rows [3].Visible = false;
1737 					((Table) InnerCell.Controls [0]).Rows [4].Visible = false;
1738 					((Table) InnerCell.Controls [0]).Rows [5].Visible = false;
1739 				} else {
1740 					// Row #3
1741 					Label PasswordLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [3].Cells [0].Controls [0];
1742 					PasswordLabel.Text = _createUserWizard.PasswordLabelText;
1743 
1744 					RequiredFieldValidator PasswordRequired = (RequiredFieldValidator) FindControl ("PasswordRequired");
1745 					PasswordRequired.ErrorMessage = _createUserWizard.PasswordRequiredErrorMessage;
1746 					PasswordRequired.ToolTip = _createUserWizard.PasswordRequiredErrorMessage;
1747 
1748 					// Row #4
1749 					if (String.IsNullOrEmpty (_createUserWizard.PasswordHintText))
1750 						((Table) InnerCell.Controls [0]).Rows [4].Visible = false;
1751 					else
1752 						((Table) InnerCell.Controls [0]).Rows [4].Cells [1].Text = _createUserWizard.PasswordHintText;
1753 
1754 					// Row #5
1755 					Label ConfirmPasswordLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [5].Cells [0].Controls [0];
1756 					ConfirmPasswordLabel.Text = _createUserWizard.ConfirmPasswordLabelText;
1757 
1758 					RequiredFieldValidator ConfirmPasswordRequired = (RequiredFieldValidator) FindControl ("ConfirmPasswordRequired");
1759 					ConfirmPasswordRequired.ErrorMessage = _createUserWizard.ConfirmPasswordRequiredErrorMessage;
1760 					ConfirmPasswordRequired.ToolTip = _createUserWizard.ConfirmPasswordRequiredErrorMessage;
1761 				}
1762 
1763 				// Row #6
1764 				if (_createUserWizard.RequireEmail) {
1765 					Label EmailLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [6].Cells [0].Controls [0];
1766 					EmailLabel.Text = _createUserWizard.EmailLabelText;
1767 
1768 					RequiredFieldValidator EmailRequired = (RequiredFieldValidator) FindControl ("EmailRequired");
1769 					EmailRequired.ErrorMessage = _createUserWizard.EmailRequiredErrorMessage;
1770 					EmailRequired.ToolTip = _createUserWizard.EmailRequiredErrorMessage;
1771 				} else
1772 					((Table) InnerCell.Controls [0]).Rows [6].Visible = false;
1773 
1774 				if (_createUserWizard.QuestionAndAnswerRequired) {
1775 					// Row #7
1776 					Label QuestionLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [7].Cells [0].Controls [0];
1777 					QuestionLabel.Text = _createUserWizard.QuestionLabelText;
1778 
1779 					RequiredFieldValidator QuestionRequired = (RequiredFieldValidator) FindControl ("QuestionRequired");
1780 					QuestionRequired.ErrorMessage = _createUserWizard.QuestionRequiredErrorMessage;
1781 					QuestionRequired.ToolTip = _createUserWizard.QuestionRequiredErrorMessage;
1782 
1783 					// Row #8
1784 					Label AnswerLabel = (Label) ((Table) InnerCell.Controls [0]).Rows [8].Cells [0].Controls [0];
1785 					AnswerLabel.Text = _createUserWizard.AnswerLabelText;
1786 
1787 					RequiredFieldValidator AnswerRequired = (RequiredFieldValidator) FindControl ("AnswerRequired");
1788 					AnswerRequired.ErrorMessage = _createUserWizard.AnswerRequiredErrorMessage;
1789 					AnswerRequired.ToolTip = _createUserWizard.AnswerRequiredErrorMessage;
1790 				} else {
1791 					((Table) InnerCell.Controls [0]).Rows [7].Visible = false;
1792 					((Table) InnerCell.Controls [0]).Rows [8].Visible = false;
1793 				}
1794 
1795 				// Row #9
1796 				if (_createUserWizard.AutoGeneratePassword)
1797 					((Table) InnerCell.Controls [0]).Rows [9].Visible = false;
1798 				else {
1799 					CompareValidator PasswordCompare = (CompareValidator) FindControl ("PasswordCompare");
1800 					PasswordCompare.ErrorMessage = _createUserWizard.ConfirmPasswordCompareErrorMessage;
1801 				}
1802 
1803 				// Row #10
1804 				if (_createUserWizard.AutoGeneratePassword || String.IsNullOrEmpty (_createUserWizard.PasswordRegularExpression))
1805 					((Table) InnerCell.Controls [0]).Rows [10].Visible = false;
1806 				else {
1807 					RegularExpressionValidator PasswordRegEx = (RegularExpressionValidator) FindControl ("PasswordRegEx");
1808 					PasswordRegEx.ValidationExpression = _createUserWizard.PasswordRegularExpression;
1809 					PasswordRegEx.ErrorMessage = _createUserWizard.PasswordRegularExpressionErrorMessage;
1810 				}
1811 
1812 				// Row #11
1813 				if (!_createUserWizard.RequireEmail || String.IsNullOrEmpty (_createUserWizard.EmailRegularExpression))
1814 					((Table) InnerCell.Controls [0]).Rows [11].Visible = false;
1815 				else {
1816 					RegularExpressionValidator EmailRegEx = (RegularExpressionValidator) FindControl ("EmailRegEx");
1817 					EmailRegEx.ErrorMessage = _createUserWizard.EmailRegularExpressionErrorMessage;
1818 					EmailRegEx.ValidationExpression = _createUserWizard.EmailRegularExpression;
1819 				}
1820 
1821 				// Row #12
1822 				if (String.IsNullOrEmpty (ErrorMessageLabel.Text))
1823 					((Table) InnerCell.Controls [0]).Rows [12].Visible = false;
1824 
1825 				// Row #13
1826 				// HelpPageIconUrl
1827 				Image img = (Image) ((Table) InnerCell.Controls [0]).Rows [13].Cells [0].Controls [0];
1828 				if (String.IsNullOrEmpty (_createUserWizard.HelpPageIconUrl))
1829 					img.Visible = false;
1830 				else {
1831 					img.ImageUrl = _createUserWizard.HelpPageIconUrl;
1832 					img.AlternateText = _createUserWizard.HelpPageText;
1833 				}
1834 
1835 				// HelpPageText
1836 				HyperLink link = (HyperLink) ((Table) InnerCell.Controls [0]).Rows [13].Cells [0].Controls [1];
1837 				if (String.IsNullOrEmpty (_createUserWizard.HelpPageText))
1838 					link.Visible = false;
1839 				else {
1840 					link.Text = _createUserWizard.HelpPageText;
1841 					link.NavigateUrl = _createUserWizard.HelpPageUrl;
1842 				}
1843 
1844 				((Table) InnerCell.Controls [0]).Rows [13].Visible = img.Visible || link.Visible;
1845 
1846 			}
1847 
EnsureValidatorsState()1848 			public void EnsureValidatorsState ()
1849 			{
1850 				if (!IsDefaultTemplate)
1851 					return;
1852 
1853 				((RequiredFieldValidator) FindControl ("PasswordRequired")).Enabled = !_createUserWizard.AutoGeneratePassword;
1854 				((RequiredFieldValidator) FindControl ("ConfirmPasswordRequired")).Enabled = !_createUserWizard.AutoGeneratePassword;
1855 				((CompareValidator) FindControl ("PasswordCompare")).Enabled = !_createUserWizard.AutoGeneratePassword;
1856 				RegularExpressionValidator PasswordRegEx = (RegularExpressionValidator) FindControl ("PasswordRegEx");
1857 				PasswordRegEx.Enabled = !_createUserWizard.AutoGeneratePassword && !String.IsNullOrEmpty (_createUserWizard.PasswordRegularExpression);
1858 				PasswordRegEx.ValidationExpression = _createUserWizard.PasswordRegularExpression;
1859 
1860 				((RequiredFieldValidator) FindControl ("EmailRequired")).Enabled = _createUserWizard.RequireEmail;
1861 				RegularExpressionValidator EmailRegEx = (RegularExpressionValidator) FindControl ("EmailRegEx");
1862 				EmailRegEx.Enabled = _createUserWizard.RequireEmail && !String.IsNullOrEmpty (_createUserWizard.EmailRegularExpression);
1863 				EmailRegEx.ValidationExpression = _createUserWizard.EmailRegularExpression;
1864 
1865 				((RequiredFieldValidator) FindControl ("QuestionRequired")).Enabled = _createUserWizard.QuestionAndAnswerRequired;
1866 				((RequiredFieldValidator) FindControl ("AnswerRequired")).Enabled = _createUserWizard.QuestionAndAnswerRequired;
1867 			}
1868 		}
1869 
1870 		sealed class CreateUserStepTemplate : ITemplate
1871 		{
1872 			readonly CreateUserWizard _createUserWizard;
1873 
CreateUserStepTemplate(CreateUserWizard createUserWizard)1874 			public CreateUserStepTemplate (CreateUserWizard createUserWizard)
1875 			{
1876 				_createUserWizard = createUserWizard;
1877 			}
1878 
1879 			#region ITemplate Members
1880 
CreateRow(Control c0, Control c1, Control c2, Style s0, Style s1)1881 			TableRow CreateRow (Control c0, Control c1, Control c2, Style s0, Style s1)
1882 			{
1883 				TableRow row = new TableRow ();
1884 				TableCell cell0 = new TableCell ();
1885 				TableCell cell1 = new TableCell ();
1886 
1887 				if (c0 != null)
1888 					cell0.Controls.Add (c0);
1889 				row.Controls.Add (cell0);
1890 
1891 				if ((c1 != null) && (c2 != null)) {
1892 					cell1.Controls.Add (c1);
1893 					cell1.Controls.Add (c2);
1894 					cell0.HorizontalAlign = HorizontalAlign.Right;
1895 
1896 					if (s0 != null)
1897 						_createUserWizard.RegisterApplyStyle (cell0, s0);
1898 					if (s1 != null)
1899 						_createUserWizard.RegisterApplyStyle (cell1, s1);
1900 
1901 					row.Controls.Add (cell1);
1902 				} else {
1903 					cell0.ColumnSpan = 2;
1904 					cell0.HorizontalAlign = HorizontalAlign.Center;
1905 					if (s0 != null)
1906 						_createUserWizard.RegisterApplyStyle (cell0, s0);
1907 				}
1908 				return row;
1909 			}
1910 
InstantiateIn(Control container)1911 			public void InstantiateIn (Control container)
1912 			{
1913 				Table table = new Table ();
1914 				table.ControlStyle.Width = Unit.Percentage (100);
1915 				table.ControlStyle.Height = Unit.Percentage (100);
1916 
1917 				// Row #0
1918 				table.Controls.Add (CreateRow (null, null, null, _createUserWizard.TitleTextStyle, null));
1919 
1920 				// Row #1
1921 				table.Controls.Add (CreateRow (null, null, null, _createUserWizard.InstructionTextStyle, null));
1922 
1923 				// Row #2
1924 				TextBox UserName = new TextBox ();
1925 				UserName.ID = "UserName";
1926 				_createUserWizard.RegisterApplyStyle (UserName, _createUserWizard.TextBoxStyle);
1927 
1928 				Label UserNameLabel = new Label ();
1929 				UserNameLabel.AssociatedControlID = "UserName";
1930 
1931 				RequiredFieldValidator UserNameRequired = new RequiredFieldValidator ();
1932 				UserNameRequired.ID = "UserNameRequired";
1933 				// alternatively we can create only required validators
1934 				// and reinstantiate collection when relevant property changes
1935 				UserNameRequired.EnableViewState = false;
1936 				UserNameRequired.ControlToValidate = "UserName";
1937 				UserNameRequired.Text = "*";
1938 				UserNameRequired.ValidationGroup = _createUserWizard.ID;
1939 				_createUserWizard.RegisterApplyStyle (UserNameRequired, _createUserWizard.ValidatorTextStyle);
1940 
1941 				table.Controls.Add (CreateRow (UserNameLabel, UserName, UserNameRequired, _createUserWizard.LabelStyle, null));
1942 
1943 				// Row #3
1944 				TextBox Password = new TextBox ();
1945 				Password.ID = "Password";
1946 				Password.TextMode = TextBoxMode.Password;
1947 				_createUserWizard.RegisterApplyStyle (Password, _createUserWizard.TextBoxStyle);
1948 
1949 				Label PasswordLabel = new Label ();
1950 				PasswordLabel.AssociatedControlID = "Password";
1951 
1952 				RequiredFieldValidator PasswordRequired = new RequiredFieldValidator ();
1953 				PasswordRequired.ID = "PasswordRequired";
1954 				PasswordRequired.EnableViewState = false;
1955 				PasswordRequired.ControlToValidate = "Password";
1956 				PasswordRequired.Text = "*";
1957 				//PasswordRequired.EnableViewState = false;
1958 				PasswordRequired.ValidationGroup = _createUserWizard.ID;
1959 				_createUserWizard.RegisterApplyStyle (PasswordRequired, _createUserWizard.ValidatorTextStyle);
1960 
1961 				table.Controls.Add (CreateRow (PasswordLabel, Password, PasswordRequired, _createUserWizard.LabelStyle, null));
1962 
1963 				// Row #4
1964 				table.Controls.Add (CreateRow (new LiteralControl (String.Empty), new LiteralControl (String.Empty), new LiteralControl (String.Empty), null, _createUserWizard.PasswordHintStyle));
1965 
1966 				// Row #5
1967 				TextBox ConfirmPassword = new TextBox ();
1968 				ConfirmPassword.ID = "ConfirmPassword";
1969 				ConfirmPassword.TextMode = TextBoxMode.Password;
1970 				_createUserWizard.RegisterApplyStyle (ConfirmPassword, _createUserWizard.TextBoxStyle);
1971 
1972 				Label ConfirmPasswordLabel = new Label ();
1973 				ConfirmPasswordLabel.AssociatedControlID = "ConfirmPassword";
1974 
1975 				RequiredFieldValidator ConfirmPasswordRequired = new RequiredFieldValidator ();
1976 				ConfirmPasswordRequired.ID = "ConfirmPasswordRequired";
1977 				ConfirmPasswordRequired.EnableViewState = false;
1978 				ConfirmPasswordRequired.ControlToValidate = "ConfirmPassword";
1979 				ConfirmPasswordRequired.Text = "*";
1980 				ConfirmPasswordRequired.ValidationGroup = _createUserWizard.ID;
1981 				_createUserWizard.RegisterApplyStyle (ConfirmPasswordRequired, _createUserWizard.ValidatorTextStyle);
1982 
1983 				table.Controls.Add (CreateRow (ConfirmPasswordLabel, ConfirmPassword, ConfirmPasswordRequired, _createUserWizard.LabelStyle, null));
1984 
1985 				// Row #6
1986 				TextBox Email = new TextBox ();
1987 				Email.ID = "Email";
1988 				_createUserWizard.RegisterApplyStyle (Email, _createUserWizard.TextBoxStyle);
1989 
1990 				Label EmailLabel = new Label ();
1991 				EmailLabel.AssociatedControlID = "Email";
1992 
1993 				RequiredFieldValidator EmailRequired = new RequiredFieldValidator ();
1994 				EmailRequired.ID = "EmailRequired";
1995 				EmailRequired.EnableViewState = false;
1996 				EmailRequired.ControlToValidate = "Email";
1997 				EmailRequired.Text = "*";
1998 				EmailRequired.ValidationGroup = _createUserWizard.ID;
1999 				_createUserWizard.RegisterApplyStyle (EmailRequired, _createUserWizard.ValidatorTextStyle);
2000 
2001 				table.Controls.Add (CreateRow (EmailLabel, Email, EmailRequired, _createUserWizard.LabelStyle, null));
2002 
2003 				// Row #7
2004 				TextBox Question = new TextBox ();
2005 				Question.ID = "Question";
2006 				_createUserWizard.RegisterApplyStyle (Question, _createUserWizard.TextBoxStyle);
2007 
2008 				Label QuestionLabel = new Label ();
2009 				QuestionLabel.AssociatedControlID = "Question";
2010 
2011 				RequiredFieldValidator QuestionRequired = new RequiredFieldValidator ();
2012 				QuestionRequired.ID = "QuestionRequired";
2013 				QuestionRequired.EnableViewState = false;
2014 				QuestionRequired.ControlToValidate = "Question";
2015 				QuestionRequired.Text = "*";
2016 				QuestionRequired.ValidationGroup = _createUserWizard.ID;
2017 				_createUserWizard.RegisterApplyStyle (QuestionRequired, _createUserWizard.ValidatorTextStyle);
2018 
2019 				table.Controls.Add (CreateRow (QuestionLabel, Question, QuestionRequired, _createUserWizard.LabelStyle, null));
2020 
2021 				// Row #8
2022 				TextBox Answer = new TextBox ();
2023 				Answer.ID = "Answer";
2024 				_createUserWizard.RegisterApplyStyle (Answer, _createUserWizard.TextBoxStyle);
2025 
2026 				Label AnswerLabel = new Label ();
2027 				AnswerLabel.AssociatedControlID = "Answer";
2028 
2029 				RequiredFieldValidator AnswerRequired = new RequiredFieldValidator ();
2030 				AnswerRequired.ID = "AnswerRequired";
2031 				AnswerRequired.EnableViewState = false;
2032 				AnswerRequired.ControlToValidate = "Answer";
2033 				AnswerRequired.Text = "*";
2034 				AnswerRequired.ValidationGroup = _createUserWizard.ID;
2035 				_createUserWizard.RegisterApplyStyle (AnswerRequired, _createUserWizard.ValidatorTextStyle);
2036 
2037 				table.Controls.Add (CreateRow (AnswerLabel, Answer, AnswerRequired, _createUserWizard.LabelStyle, null));
2038 
2039 				// Row #9
2040 				CompareValidator PasswordCompare = new CompareValidator ();
2041 				PasswordCompare.ID = "PasswordCompare";
2042 				PasswordCompare.EnableViewState = false;
2043 				PasswordCompare.ControlToCompare = "Password";
2044 				PasswordCompare.ControlToValidate = "ConfirmPassword";
2045 				PasswordCompare.Display = ValidatorDisplay.Static;
2046 				PasswordCompare.ValidationGroup = _createUserWizard.ID;
2047 				PasswordCompare.Display = ValidatorDisplay.Dynamic;
2048 				_createUserWizard.RegisterApplyStyle (PasswordCompare, _createUserWizard.ValidatorTextStyle);
2049 
2050 				table.Controls.Add (CreateRow (PasswordCompare, null, null, null, null));
2051 
2052 				// Row #10
2053 				RegularExpressionValidator PasswordRegEx = new RegularExpressionValidator ();
2054 				PasswordRegEx.ID = "PasswordRegEx";
2055 				PasswordRegEx.EnableViewState = false;
2056 				PasswordRegEx.ControlToValidate = "Password";
2057 				PasswordRegEx.Display = ValidatorDisplay.Static;
2058 				PasswordRegEx.ValidationGroup = _createUserWizard.ID;
2059 				PasswordRegEx.Display = ValidatorDisplay.Dynamic;
2060 				_createUserWizard.RegisterApplyStyle (PasswordRegEx, _createUserWizard.ValidatorTextStyle);
2061 
2062 				table.Controls.Add (CreateRow (PasswordRegEx, null, null, null, null));
2063 
2064 				// Row #11
2065 				RegularExpressionValidator EmailRegEx = new RegularExpressionValidator ();
2066 				EmailRegEx.ID = "EmailRegEx";
2067 				EmailRegEx.EnableViewState = false;
2068 				EmailRegEx.ControlToValidate = "Email";
2069 				EmailRegEx.Display = ValidatorDisplay.Static;
2070 				EmailRegEx.ValidationGroup = _createUserWizard.ID;
2071 				EmailRegEx.Display = ValidatorDisplay.Dynamic;
2072 				_createUserWizard.RegisterApplyStyle (EmailRegEx, _createUserWizard.ValidatorTextStyle);
2073 
2074 				table.Controls.Add (CreateRow (EmailRegEx, null, null, null, null));
2075 
2076 				// Row #12
2077 				Label ErrorMessage = new Label ();
2078 				ErrorMessage.ID = "ErrorMessage";
2079 				ErrorMessage.EnableViewState = false;
2080 				_createUserWizard.RegisterApplyStyle (ErrorMessage, _createUserWizard.ValidatorTextStyle);
2081 
2082 				table.Controls.Add (CreateRow (ErrorMessage, null, null, null, null));
2083 
2084 				// Row #13
2085 				TableRow row13 = CreateRow (new Image (), null, null, null, null);
2086 
2087 				HyperLink HelpLink = new HyperLink ();
2088 				HelpLink.ID = "HelpLink";
2089 				_createUserWizard.RegisterApplyStyle (HelpLink, _createUserWizard.HyperLinkStyle);
2090 				row13.Cells [0].Controls.Add (HelpLink);
2091 
2092 				row13.Cells [0].HorizontalAlign = HorizontalAlign.Left;
2093 				table.Controls.Add (row13);
2094 
2095 				//
2096 				container.Controls.Add (table);
2097 			}
2098 
2099 			#endregion
2100 		}
2101 
2102 		sealed class CompleteStepContainer : DefaultContentContainer
2103 		{
2104 			CreateUserWizard _createUserWizard;
2105 
CompleteStepContainer(CreateUserWizard createUserWizard)2106 			public CompleteStepContainer (CreateUserWizard createUserWizard)
2107 				: base (createUserWizard)
2108 			{
2109 				_createUserWizard = createUserWizard;
2110 			}
2111 
UpdateState()2112 			protected override void UpdateState ()
2113 			{
2114 				// title
2115 				if (String.IsNullOrEmpty (_createUserWizard.CompleteStep.Title))
2116 					((Table) InnerCell.Controls [0]).Rows [0].Visible = false;
2117 				else
2118 					((Table) InnerCell.Controls [0]).Rows [0].Cells [0].Text = _createUserWizard.CompleteStep.Title;
2119 
2120 				// CompleteSuccessText
2121 				if (String.IsNullOrEmpty (_createUserWizard.CompleteSuccessText))
2122 					((Table) InnerCell.Controls [0]).Rows [1].Visible = false;
2123 				else
2124 					((Table) InnerCell.Controls [0]).Rows [1].Cells [0].Text = _createUserWizard.CompleteSuccessText;
2125 
2126 				// ContinueButton
2127 				UpdateNavButtonState ("ContinueButton" + _createUserWizard.ContinueButtonType, _createUserWizard.ContinueButtonText, _createUserWizard.ContinueButtonImageUrl, _createUserWizard.ContinueButtonStyle);
2128 
2129 				// EditProfileIconUrl
2130 				Image img = (Image) ((Table) InnerCell.Controls [0]).Rows [3].Cells [0].Controls [0];
2131 				if (String.IsNullOrEmpty (_createUserWizard.EditProfileIconUrl))
2132 					img.Visible = false;
2133 				else {
2134 					img.ImageUrl = _createUserWizard.EditProfileIconUrl;
2135 					img.AlternateText = _createUserWizard.EditProfileText;
2136 				}
2137 
2138 				// EditProfileText
2139 				HyperLink link = (HyperLink) ((Table) InnerCell.Controls [0]).Rows [3].Cells [0].Controls [1];
2140 				if (String.IsNullOrEmpty (_createUserWizard.EditProfileText))
2141 					link.Visible = false;
2142 				else {
2143 					link.Text = _createUserWizard.EditProfileText;
2144 					link.NavigateUrl = _createUserWizard.EditProfileUrl;
2145 				}
2146 
2147 				((Table) InnerCell.Controls [0]).Rows [3].Visible = img.Visible || link.Visible;
2148 			}
2149 
UpdateNavButtonState(string id, string text, string image, Style style)2150 			void UpdateNavButtonState (string id, string text, string image, Style style)
2151 			{
2152 				WebControl b = (WebControl) FindControl (id);
2153 				foreach (Control c in b.Parent.Controls)
2154 					c.Visible = b == c;
2155 
2156 				((IButtonControl) b).Text = text;
2157 				ImageButton imgbtn = b as ImageButton;
2158 				if (imgbtn != null)
2159 					imgbtn.ImageUrl = image;
2160 
2161 				b.ApplyStyle (style);
2162 			}
2163 		}
2164 
2165 		sealed class CompleteStepTemplate : ITemplate
2166 		{
2167 			readonly CreateUserWizard _createUserWizard;
2168 
CompleteStepTemplate(CreateUserWizard createUserWizard)2169 			public CompleteStepTemplate (CreateUserWizard createUserWizard)
2170 			{
2171 				_createUserWizard = createUserWizard;
2172 			}
2173 
2174 			#region ITemplate Members
2175 
InstantiateIn(Control container)2176 			public void InstantiateIn (Control container)
2177 			{
2178 				Table table = new Table ();
2179 
2180 				// Row #0
2181 				TableRow row0 = new TableRow ();
2182 				TableCell cell00 = new TableCell ();
2183 
2184 				cell00.HorizontalAlign = HorizontalAlign.Center;
2185 				cell00.ColumnSpan = 2;
2186 				_createUserWizard.RegisterApplyStyle (cell00, _createUserWizard.TitleTextStyle);
2187 				row0.Cells.Add (cell00);
2188 
2189 				// Row #1
2190 				TableRow row1 = new TableRow ();
2191 				TableCell cell10 = new TableCell ();
2192 
2193 				cell10.HorizontalAlign = HorizontalAlign.Center;
2194 				_createUserWizard.RegisterApplyStyle (cell10, _createUserWizard.CompleteSuccessTextStyle);
2195 				row1.Cells.Add (cell10);
2196 
2197 				// Row #2
2198 				TableRow row2 = new TableRow ();
2199 				TableCell cell20 = new TableCell ();
2200 
2201 				cell20.HorizontalAlign = HorizontalAlign.Right;
2202 				cell20.ColumnSpan = 2;
2203 				row2.Cells.Add (cell20);
2204 
2205 				Control [] b = _createUserWizard.CreateButtonSet ("ContinueButton", CreateUserWizard.ContinueButtonCommandName, false, _createUserWizard.ID);
2206 				for (int i = 0; i < b.Length; i++)
2207 					cell20.Controls.Add (b [i]);
2208 
2209 				// Row #3
2210 				TableRow row3 = new TableRow ();
2211 				TableCell cell30 = new TableCell ();
2212 
2213 				cell30.Controls.Add (new Image ());
2214 				HyperLink link = new HyperLink ();
2215 				link.ID = "EditProfileLink";
2216 				_createUserWizard.RegisterApplyStyle (link, _createUserWizard.HyperLinkStyle);
2217 				cell30.Controls.Add (link);
2218 				row3.Cells.Add (cell30);
2219 
2220 				// table
2221 				table.Rows.Add (row0);
2222 				table.Rows.Add (row1);
2223 				table.Rows.Add (row2);
2224 				table.Rows.Add (row3);
2225 
2226 				container.Controls.Add (table);
2227 			}
2228 
2229 			#endregion
2230 		}
2231 	}
2232 }
2233