CreateUserWizard.cs 67 KB

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