PasswordRecovery.cs 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. //
  2. // System.Web.UI.WebControls.PasswordRecovery.cs
  3. //
  4. // Authors:
  5. // Vladimir Krasnov ([email protected])
  6. //
  7. // (C) 2006 Mainsoft, Inc (http://www.mainsoft.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if NET_2_0
  29. using System;
  30. using System.Net.Mail;
  31. using System.Collections;
  32. using System.Collections.Specialized;
  33. using System.ComponentModel;
  34. using System.Drawing.Design;
  35. using System.Web;
  36. using System.Web.UI;
  37. using System.Web.Security;
  38. namespace System.Web.UI.WebControls
  39. {
  40. [Bindable (false)]
  41. public class PasswordRecovery : CompositeControl
  42. {
  43. static readonly object answerLookupErrorEvent = new object ();
  44. static readonly object sendingMailEvent = new object ();
  45. static readonly object sendMailErrorEvent = new object ();
  46. static readonly object userLookupErrorEvent = new object ();
  47. static readonly object verifyingAnswerEvent = new object ();
  48. static readonly object verifyingUserEvent = new object ();
  49. public static readonly string SubmitButtonCommandName = "Submit";
  50. TableItemStyle _failureTextStyle;
  51. TableItemStyle _hyperLinkStyle;
  52. TableItemStyle _instructionTextStyle;
  53. TableItemStyle _labelStyle;
  54. Style _submitButtonStyle;
  55. TableItemStyle _successTextStyle;
  56. Style _textBoxStyle;
  57. TableItemStyle _titleTextStyle;
  58. Style _validatorTextStyle;
  59. MailDefinition _mailDefinition;
  60. MembershipProvider _provider = null;
  61. ITemplate _questionTemplate = null;
  62. ITemplate _successTemplate = null;
  63. ITemplate _userNameTemplate = null;
  64. QuestionContainer _questionTemplateContainer = null;
  65. SuccessContainer _successTemplateContainer = null;
  66. UserNameContainer _userNameTemplateContainer = null;
  67. PasswordReciveryStep _currentStep = PasswordReciveryStep.StepUserName;
  68. string _username = null;
  69. string _answer = null;
  70. EventHandlerList events = new EventHandlerList ();
  71. #region Events
  72. public event EventHandler AnswerLookupError {
  73. add { events.AddHandler (answerLookupErrorEvent, value); }
  74. remove { events.RemoveHandler (answerLookupErrorEvent, value); }
  75. }
  76. public event MailMessageEventHandler SendingMail {
  77. add { events.AddHandler (sendingMailEvent, value); }
  78. remove { events.RemoveHandler (sendingMailEvent, value); }
  79. }
  80. public event SendMailErrorEventHandler SendMailError {
  81. add { events.AddHandler (sendMailErrorEvent, value); }
  82. remove { events.RemoveHandler (sendMailErrorEvent, value); }
  83. }
  84. public event EventHandler UserLookupError {
  85. add { events.AddHandler (userLookupErrorEvent, value); }
  86. remove { events.RemoveHandler (userLookupErrorEvent, value); }
  87. }
  88. public event LoginCancelEventHandler VerifyingAnswer {
  89. add { events.AddHandler (verifyingAnswerEvent, value); }
  90. remove { events.RemoveHandler (verifyingAnswerEvent, value); }
  91. }
  92. public event LoginCancelEventHandler VerifyingUser {
  93. add { events.AddHandler (verifyingUserEvent, value); }
  94. remove { events.RemoveHandler (verifyingUserEvent, value); }
  95. }
  96. #endregion
  97. public PasswordRecovery ()
  98. {
  99. }
  100. [Themeable (false)]
  101. public virtual string Answer
  102. {
  103. get { return _answer != null ? _answer : string.Empty; }
  104. }
  105. [Localizable (true)]
  106. public virtual string AnswerLabelText
  107. {
  108. get { return ViewState.GetString ("AnswerLabelText", "Answer:"); }
  109. set { ViewState ["AnswerLabelText"] = value; }
  110. }
  111. [Localizable (true)]
  112. public virtual string AnswerRequiredErrorMessage
  113. {
  114. get { return ViewState.GetString ("AnswerRequiredErrorMessage", "Answer is required."); }
  115. set { ViewState ["AnswerRequiredErrorMessage"] = value; }
  116. }
  117. public virtual int BorderPadding
  118. {
  119. get { return ViewState.GetInt ("BorderPadding", 1); }
  120. set
  121. {
  122. if (value < -1)
  123. throw new ArgumentOutOfRangeException ();
  124. ViewState ["BorderPadding"] = value;
  125. }
  126. }
  127. [Localizable (true)]
  128. public virtual string GeneralFailureText
  129. {
  130. get { return ViewState.GetString ("GeneralFailureText", "Your attempt to retrieve your password was not successful. Please try again."); }
  131. set { ViewState ["GeneralFailureText"] = value; }
  132. }
  133. public virtual string HelpPageIconUrl
  134. {
  135. get { return ViewState.GetString ("HelpPageIconUrl", String.Empty); }
  136. set { ViewState ["HelpPageIconUrl"] = value; }
  137. }
  138. [Localizable (true)]
  139. public virtual string HelpPageText
  140. {
  141. get { return ViewState.GetString ("HelpPageText", String.Empty); }
  142. set { ViewState ["HelpPageText"] = value; }
  143. }
  144. public virtual string HelpPageUrl
  145. {
  146. get { return ViewState.GetString ("HelpPageUrl", String.Empty); }
  147. set { ViewState ["HelpPageUrl"] = value; }
  148. }
  149. [Themeable (false)]
  150. public MailDefinition MailDefinition
  151. {
  152. get
  153. {
  154. if (_mailDefinition == null) {
  155. _mailDefinition = new MailDefinition ();
  156. if (IsTrackingViewState)
  157. ((IStateManager) _mailDefinition).TrackViewState ();
  158. }
  159. return _mailDefinition;
  160. }
  161. }
  162. [Themeable (false)]
  163. public virtual string MembershipProvider
  164. {
  165. get { return ViewState.GetString ("MembershipProvider", String.Empty); }
  166. set { ViewState ["MembershipProvider"] = value; }
  167. }
  168. [Themeable (false)]
  169. public virtual string Question
  170. {
  171. get { return ViewState.GetString ("Question", ""); }
  172. private set { ViewState ["Question"] = value; }
  173. }
  174. [Localizable (true)]
  175. public virtual string QuestionFailureText
  176. {
  177. get { return ViewState.GetString ("QuestionFailureText", "Your answer could not be verified. Please try again."); }
  178. set { ViewState ["QuestionFailureText"] = value; }
  179. }
  180. [Localizable (true)]
  181. public virtual string QuestionInstructionText
  182. {
  183. get { return ViewState.GetString ("QuestionInstructionText", "Answer the following question to receive your password."); }
  184. set { ViewState ["QuestionInstructionText"] = value; }
  185. }
  186. [Localizable (true)]
  187. public virtual string QuestionLabelText
  188. {
  189. get { return ViewState.GetString ("QuestionLabelText", "Question:"); }
  190. set { ViewState ["QuestionLabelText"] = value; }
  191. }
  192. [Localizable (true)]
  193. public virtual string QuestionTitleText
  194. {
  195. get { return ViewState.GetString ("QuestionTitleText", "Identity Confirmation"); }
  196. set { ViewState ["QuestionTitleText"] = value; }
  197. }
  198. public virtual string SubmitButtonImageUrl
  199. {
  200. get { return ViewState.GetString ("SubmitButtonImageUrl", String.Empty); }
  201. set { ViewState ["SubmitButtonImageUrl"] = value; }
  202. }
  203. [Localizable (true)]
  204. public virtual string SubmitButtonText
  205. {
  206. get { return ViewState.GetString ("SubmitButtonText", "Submit"); }
  207. set { ViewState ["SubmitButtonText"] = value; }
  208. }
  209. public virtual ButtonType SubmitButtonType
  210. {
  211. get
  212. {
  213. object o = ViewState ["SubmitButtonType"];
  214. return (o == null) ? ButtonType.Button : (ButtonType) o;
  215. }
  216. set
  217. {
  218. if ((value < ButtonType.Button) || (value > ButtonType.Link))
  219. throw new ArgumentOutOfRangeException ("SubmitButtonType");
  220. ViewState ["SubmitButtonType"] = (int) value;
  221. }
  222. }
  223. [Themeable (false)]
  224. public virtual string SuccessPageUrl
  225. {
  226. get { return ViewState.GetString ("SuccessPageUrl", String.Empty); }
  227. set { ViewState ["SuccessPageUrl"] = value; }
  228. }
  229. [Localizable (true)]
  230. public virtual string SuccessText
  231. {
  232. get { return ViewState.GetString ("SuccessText", "Your password has been sent to you."); }
  233. set { ViewState ["SuccessText"] = value; }
  234. }
  235. public virtual LoginTextLayout TextLayout
  236. {
  237. get
  238. {
  239. object o = ViewState ["TextLayout"];
  240. return (o == null) ? LoginTextLayout.TextOnLeft : (LoginTextLayout) o;
  241. }
  242. set
  243. {
  244. if ((value < LoginTextLayout.TextOnLeft) || (value > LoginTextLayout.TextOnTop))
  245. throw new ArgumentOutOfRangeException ("TextLayout");
  246. ViewState ["TextLayout"] = (int) value;
  247. }
  248. }
  249. [Localizable (true)]
  250. public virtual string UserName
  251. {
  252. get { return _username != null ? _username : ""; }
  253. set { _username = value; }
  254. }
  255. [Localizable (true)]
  256. public virtual string UserNameFailureText
  257. {
  258. get { return ViewState.GetString ("UserNameFailureText", "We were unable to access your information. Please try again."); }
  259. set { ViewState ["UserNameFailureText"] = value; }
  260. }
  261. [Localizable (true)]
  262. public virtual string UserNameInstructionText
  263. {
  264. get { return ViewState.GetString ("UserNameInstructionText", "Enter your User Name to receive your password."); }
  265. set { ViewState ["UserNameInstructionText"] = value; }
  266. }
  267. [Localizable (true)]
  268. public virtual string UserNameLabelText
  269. {
  270. get { return ViewState.GetString ("UserNameLabelText", "User Name:"); }
  271. set { ViewState ["UserNameLabelText"] = value; }
  272. }
  273. [Localizable (true)]
  274. public virtual string UserNameRequiredErrorMessage
  275. {
  276. get { return ViewState.GetString ("UserNameRequiredErrorMessage", "User Name is required."); }
  277. set { ViewState ["UserNameRequiredErrorMessage"] = value; }
  278. }
  279. [Localizable (true)]
  280. public virtual string UserNameTitleText
  281. {
  282. get { return ViewState.GetString ("UserNameTitleText", "Forgot Your Password?"); }
  283. set { ViewState ["UserNameTitleText"] = value; }
  284. }
  285. [TemplateContainer (typeof (PasswordRecovery))]
  286. public virtual ITemplate QuestionTemplate
  287. {
  288. get { return _questionTemplate; }
  289. set { _questionTemplate = value; }
  290. }
  291. public Control QuestionTemplateContainer
  292. {
  293. get {
  294. if (_questionTemplateContainer == null) {
  295. _questionTemplateContainer = new QuestionContainer (this);
  296. ITemplate template = QuestionTemplate;
  297. if (template != null)
  298. _questionTemplateContainer.InstantiateTemplate (template);
  299. }
  300. return _questionTemplateContainer;
  301. }
  302. }
  303. [TemplateContainer (typeof (PasswordRecovery))]
  304. public virtual ITemplate SuccessTemplate
  305. {
  306. get { return _successTemplate; }
  307. set { _successTemplate = value; }
  308. }
  309. public Control SuccessTemplateContainer
  310. {
  311. get {
  312. if (_successTemplateContainer == null) {
  313. _successTemplateContainer = new SuccessContainer (this);
  314. ITemplate template = SuccessTemplate;
  315. if (template != null)
  316. _successTemplateContainer.InstantiateTemplate (template);
  317. }
  318. return _successTemplateContainer;
  319. }
  320. }
  321. [TemplateContainer (typeof (PasswordRecovery))]
  322. public virtual ITemplate UserNameTemplate
  323. {
  324. get { return _userNameTemplate; }
  325. set { _userNameTemplate = value; }
  326. }
  327. public Control UserNameTemplateContainer
  328. {
  329. get
  330. {
  331. if (_userNameTemplateContainer == null) {
  332. _userNameTemplateContainer = new UserNameContainer (this);
  333. ITemplate template = UserNameTemplate;
  334. if (template != null)
  335. _userNameTemplateContainer.InstantiateTemplate (template);
  336. }
  337. return _userNameTemplateContainer;
  338. }
  339. }
  340. public TableItemStyle FailureTextStyle
  341. {
  342. get
  343. {
  344. if (_failureTextStyle == null) {
  345. _failureTextStyle = new TableItemStyle ();
  346. if (IsTrackingViewState)
  347. _failureTextStyle.TrackViewState ();
  348. }
  349. return _failureTextStyle;
  350. }
  351. }
  352. public TableItemStyle HyperLinkStyle
  353. {
  354. get
  355. {
  356. if (_hyperLinkStyle == null) {
  357. _hyperLinkStyle = new TableItemStyle ();
  358. if (IsTrackingViewState)
  359. _hyperLinkStyle.TrackViewState ();
  360. }
  361. return _hyperLinkStyle;
  362. }
  363. }
  364. public TableItemStyle InstructionTextStyle
  365. {
  366. get
  367. {
  368. if (_instructionTextStyle == null) {
  369. _instructionTextStyle = new TableItemStyle ();
  370. if (IsTrackingViewState)
  371. _instructionTextStyle.TrackViewState ();
  372. }
  373. return _instructionTextStyle;
  374. }
  375. }
  376. public TableItemStyle LabelStyle
  377. {
  378. get
  379. {
  380. if (_labelStyle == null) {
  381. _labelStyle = new TableItemStyle ();
  382. if (IsTrackingViewState)
  383. _labelStyle.TrackViewState ();
  384. }
  385. return _labelStyle;
  386. }
  387. }
  388. public Style SubmitButtonStyle
  389. {
  390. get
  391. {
  392. if (_submitButtonStyle == null) {
  393. _submitButtonStyle = new TableItemStyle ();
  394. if (IsTrackingViewState)
  395. _submitButtonStyle.TrackViewState ();
  396. }
  397. return _submitButtonStyle;
  398. }
  399. }
  400. public TableItemStyle SuccessTextStyle
  401. {
  402. get
  403. {
  404. if (_successTextStyle == null) {
  405. _successTextStyle = new TableItemStyle ();
  406. if (IsTrackingViewState)
  407. _successTextStyle.TrackViewState ();
  408. }
  409. return _successTextStyle;
  410. }
  411. }
  412. public Style TextBoxStyle
  413. {
  414. get
  415. {
  416. if (_textBoxStyle == null) {
  417. _textBoxStyle = new TableItemStyle ();
  418. if (IsTrackingViewState)
  419. _textBoxStyle.TrackViewState ();
  420. }
  421. return _textBoxStyle;
  422. }
  423. }
  424. public TableItemStyle TitleTextStyle
  425. {
  426. get
  427. {
  428. if (_titleTextStyle == null) {
  429. _titleTextStyle = new TableItemStyle ();
  430. if (IsTrackingViewState)
  431. _titleTextStyle.TrackViewState ();
  432. }
  433. return _titleTextStyle;
  434. }
  435. }
  436. public Style ValidatorTextStyle
  437. {
  438. get
  439. {
  440. if (_validatorTextStyle == null) {
  441. _validatorTextStyle = new TableItemStyle ();
  442. if (IsTrackingViewState)
  443. _validatorTextStyle.TrackViewState ();
  444. }
  445. return _validatorTextStyle;
  446. }
  447. }
  448. #region Protected Properties
  449. protected override HtmlTextWriterTag TagKey
  450. {
  451. get { return HtmlTextWriterTag.Table; }
  452. }
  453. internal virtual MembershipProvider MembershipProviderInternal
  454. {
  455. get
  456. {
  457. if (_provider == null)
  458. InitMemberShipProvider ();
  459. return _provider;
  460. }
  461. }
  462. #endregion
  463. protected internal override void CreateChildControls ()
  464. {
  465. ITemplate userNameTemplate = UserNameTemplate;
  466. if (userNameTemplate == null) {
  467. userNameTemplate = new UserNameDefaultTemplate (this);
  468. ((UserNameContainer) UserNameTemplateContainer).InstantiateTemplate (userNameTemplate);
  469. }
  470. ITemplate questionTemplate = QuestionTemplate;
  471. if (questionTemplate == null) {
  472. questionTemplate = new QuestionDefaultTemplate (this);
  473. ((QuestionContainer) QuestionTemplateContainer).InstantiateTemplate (questionTemplate);
  474. }
  475. ITemplate successTemplate = SuccessTemplate;
  476. if (successTemplate == null) {
  477. successTemplate = new SuccessDefaultTemplate (this);
  478. ((SuccessContainer) SuccessTemplateContainer).InstantiateTemplate (successTemplate);
  479. }
  480. Controls.AddAt (0, UserNameTemplateContainer);
  481. Controls.AddAt (1, QuestionTemplateContainer);
  482. Controls.AddAt (2, SuccessTemplateContainer);
  483. IEditableTextControl editable;
  484. editable = ((UserNameContainer) UserNameTemplateContainer).UserNameTextBox;
  485. if (editable != null)
  486. editable.TextChanged += new EventHandler (UserName_TextChanged);
  487. editable = ((QuestionContainer) QuestionTemplateContainer).AnswerTextBox;
  488. if (editable != null)
  489. editable.TextChanged += new EventHandler (Answer_TextChanged);
  490. }
  491. #region Protected methods
  492. protected internal override void Render (HtmlTextWriter writer)
  493. {
  494. ((QuestionContainer) QuestionTemplateContainer).UpdateChildControls ();
  495. for (int i = 0; i < Controls.Count; i++)
  496. if (Controls [i].Visible)
  497. Controls [i].Render (writer);
  498. }
  499. protected internal override void LoadControlState (object savedState)
  500. {
  501. if (savedState == null) return;
  502. object [] state = (object []) savedState;
  503. base.LoadControlState (state [0]);
  504. _currentStep = (PasswordReciveryStep) state [1];
  505. _username = (string) state [2];
  506. }
  507. protected internal override object SaveControlState ()
  508. {
  509. object state = base.SaveControlState ();
  510. return new object [] { state, _currentStep, _username };
  511. }
  512. protected override void TrackViewState ()
  513. {
  514. base.TrackViewState ();
  515. if (_failureTextStyle != null)
  516. _failureTextStyle.TrackViewState ();
  517. if (_hyperLinkStyle != null)
  518. _hyperLinkStyle.TrackViewState ();
  519. if (_instructionTextStyle != null)
  520. _instructionTextStyle.TrackViewState ();
  521. if (_labelStyle != null)
  522. _labelStyle.TrackViewState ();
  523. if (_submitButtonStyle != null)
  524. _submitButtonStyle.TrackViewState ();
  525. if (_successTextStyle != null)
  526. _successTextStyle.TrackViewState ();
  527. if (_textBoxStyle != null)
  528. _textBoxStyle.TrackViewState ();
  529. if (_titleTextStyle != null)
  530. _titleTextStyle.TrackViewState ();
  531. if (_validatorTextStyle != null)
  532. _validatorTextStyle.TrackViewState ();
  533. if (_mailDefinition != null)
  534. ((IStateManager) _mailDefinition).TrackViewState ();
  535. }
  536. protected override void LoadViewState (object savedState)
  537. {
  538. if (savedState == null)
  539. return;
  540. object [] states = (object []) savedState;
  541. base.LoadViewState (states [0]);
  542. if (states [1] != null)
  543. FailureTextStyle.LoadViewState (states [1]);
  544. if (states [2] != null)
  545. HyperLinkStyle.LoadViewState (states [2]);
  546. if (states [3] != null)
  547. InstructionTextStyle.LoadViewState (states [3]);
  548. if (states [4] != null)
  549. LabelStyle.LoadViewState (states [4]);
  550. if (states [5] != null)
  551. SubmitButtonStyle.LoadViewState (states [5]);
  552. if (states [6] != null)
  553. SuccessTextStyle.LoadViewState (states [6]);
  554. if (states [7] != null)
  555. TextBoxStyle.LoadViewState (states [7]);
  556. if (states [8] != null)
  557. TitleTextStyle.LoadViewState (states [8]);
  558. if (states [9] != null)
  559. ValidatorTextStyle.LoadViewState (states [9]);
  560. if (states [10] != null)
  561. ((IStateManager) MailDefinition).LoadViewState (states [10]);
  562. }
  563. protected override object SaveViewState ()
  564. {
  565. object [] states = new object [11];
  566. states [0] = base.SaveViewState ();
  567. if (_failureTextStyle != null)
  568. states [1] = _failureTextStyle.SaveViewState ();
  569. if (_hyperLinkStyle != null)
  570. states [2] = _hyperLinkStyle.SaveViewState ();
  571. if (_instructionTextStyle != null)
  572. states [3] = _instructionTextStyle.SaveViewState ();
  573. if (_labelStyle != null)
  574. states [4] = _labelStyle.SaveViewState ();
  575. if (_submitButtonStyle != null)
  576. states [5] = _submitButtonStyle.SaveViewState ();
  577. if (_successTextStyle != null)
  578. states [6] = _successTextStyle.SaveViewState ();
  579. if (_textBoxStyle != null)
  580. states [7] = _textBoxStyle.SaveViewState ();
  581. if (_titleTextStyle != null)
  582. states [8] = _titleTextStyle.SaveViewState ();
  583. if (_validatorTextStyle != null)
  584. states [9] = _validatorTextStyle.SaveViewState ();
  585. if (_mailDefinition != null)
  586. states [10] = ((IStateManager) _mailDefinition).SaveViewState ();
  587. for (int i = 0; i < states.Length; i++) {
  588. if (states [i] != null)
  589. return states;
  590. }
  591. return null;
  592. }
  593. #endregion
  594. void ProcessCommand (CommandEventArgs args)
  595. {
  596. if (!Page.IsValid)
  597. return;
  598. switch (_currentStep) {
  599. case PasswordReciveryStep.StepUserName:
  600. ProcessUserName ();
  601. break;
  602. case PasswordReciveryStep.StepAnswer:
  603. ProcessUserAnswer ();
  604. break;
  605. }
  606. }
  607. void ProcessUserName ()
  608. {
  609. LoginCancelEventArgs args = new LoginCancelEventArgs ();
  610. OnVerifyingUser (args);
  611. if (args.Cancel)
  612. return;
  613. MembershipUser user = MembershipProviderInternal.GetUser (UserName, false);
  614. if (user == null) {
  615. OnUserLookupError (EventArgs.Empty);
  616. ((UserNameContainer) UserNameTemplateContainer).FailureTextLiteral.Text = UserNameFailureText;
  617. return;
  618. }
  619. if (!MembershipProviderInternal.RequiresQuestionAndAnswer) {
  620. GenerateAndSendEmail ();
  621. _currentStep = PasswordReciveryStep.StepSuccess;
  622. return;
  623. }
  624. Question = user.PasswordQuestion;
  625. _currentStep = PasswordReciveryStep.StepAnswer;
  626. return;
  627. }
  628. void ProcessUserAnswer ()
  629. {
  630. LoginCancelEventArgs args = new LoginCancelEventArgs ();
  631. OnVerifyingAnswer (args);
  632. if (args.Cancel)
  633. return;
  634. MembershipUser user = MembershipProviderInternal.GetUser (UserName, false);
  635. if (user == null || string.IsNullOrEmpty (user.Email)) {
  636. ((QuestionContainer) QuestionTemplateContainer).FailureTextLiteral.Text = GeneralFailureText;
  637. return;
  638. }
  639. GenerateAndSendEmail ();
  640. _currentStep = PasswordReciveryStep.StepSuccess;
  641. return;
  642. }
  643. void GenerateAndSendEmail ()
  644. {
  645. string newPassword = "";
  646. try {
  647. if (MembershipProviderInternal.EnablePasswordRetrieval) {
  648. newPassword = MembershipProviderInternal.GetPassword (UserName, Answer);
  649. }
  650. else if (MembershipProviderInternal.EnablePasswordReset) {
  651. newPassword = MembershipProviderInternal.ResetPassword (UserName, Answer);
  652. }
  653. else
  654. throw new HttpException ("Membership provider does not support password retrieval or reset.");
  655. }
  656. catch (MembershipPasswordException) {
  657. OnAnswerLookupError (EventArgs.Empty);
  658. ((QuestionContainer) QuestionTemplateContainer).FailureTextLiteral.Text = QuestionFailureText;
  659. return;
  660. }
  661. SendPasswordByMail (UserName, newPassword);
  662. }
  663. void InitMemberShipProvider ()
  664. {
  665. string mp = MembershipProvider;
  666. _provider = (mp.Length == 0) ? _provider = Membership.Provider : Membership.Providers [mp];
  667. if (_provider == null)
  668. throw new HttpException (Locale.GetText ("No provider named '{0}' could be found.", mp));
  669. }
  670. void SendPasswordByMail (string username, string password)
  671. {
  672. MembershipUser user = MembershipProviderInternal.GetUser (UserName, false);
  673. if (user == null)
  674. return;
  675. // DO NOT change format of the message - it has to be exactly the same as in
  676. // .NET as some software (e.g. YetAnotherForum) depends on it.
  677. string messageText = "Please return to the site and log in using the following information.\n" +
  678. "User Name: <%USERNAME%>\nPassword: <%PASSWORD%>\n";
  679. ListDictionary dictionary = new ListDictionary (StringComparer.OrdinalIgnoreCase);
  680. dictionary.Add ("<%USERNAME%>", username);
  681. dictionary.Add ("<% UserName %>", username);
  682. dictionary.Add ("<%PASSWORD%>", password);
  683. dictionary.Add ("<% Password %>", password);
  684. MailMessage message = null;
  685. if (MailDefinition.BodyFileName.Length == 0)
  686. message = MailDefinition.CreateMailMessage (user.Email, dictionary, messageText, this);
  687. else
  688. message = MailDefinition.CreateMailMessage (user.Email, dictionary, this);
  689. if (string.IsNullOrEmpty (message.Subject))
  690. message.Subject = "Password";
  691. MailMessageEventArgs args = new MailMessageEventArgs (message);
  692. OnSendingMail (args);
  693. SmtpClient smtpClient = new SmtpClient ();
  694. try {
  695. smtpClient.Send (message);
  696. }
  697. catch (Exception e) {
  698. SendMailErrorEventArgs mailArgs = new SendMailErrorEventArgs (e);
  699. OnSendMailError (mailArgs);
  700. if (!mailArgs.Handled)
  701. throw e;
  702. }
  703. }
  704. #region Event handlers
  705. protected virtual void OnAnswerLookupError (EventArgs e)
  706. {
  707. }
  708. protected override bool OnBubbleEvent (object source, EventArgs e)
  709. {
  710. CommandEventArgs args = e as CommandEventArgs;
  711. if (e != null && args.CommandName == SubmitButtonCommandName) {
  712. ProcessCommand (args);
  713. return true;
  714. }
  715. return base.OnBubbleEvent (source, e);
  716. }
  717. protected internal override void OnInit (EventArgs e)
  718. {
  719. Page.RegisterRequiresControlState (this);
  720. base.OnInit (e);
  721. }
  722. protected internal override void OnPreRender (EventArgs e)
  723. {
  724. UserNameTemplateContainer.Visible = false;
  725. QuestionTemplateContainer.Visible = false;
  726. SuccessTemplateContainer.Visible = false;
  727. switch (_currentStep) {
  728. case PasswordReciveryStep.StepUserName:
  729. UserNameTemplateContainer.Visible = true;
  730. break;
  731. case PasswordReciveryStep.StepAnswer:
  732. QuestionTemplateContainer.Visible = true;
  733. break;
  734. case PasswordReciveryStep.StepSuccess:
  735. SuccessTemplateContainer.Visible = true;
  736. break;
  737. }
  738. base.OnPreRender (e);
  739. }
  740. protected virtual void OnSendingMail (MailMessageEventArgs e)
  741. {
  742. MailMessageEventHandler eh = events [sendingMailEvent] as MailMessageEventHandler;
  743. if (eh != null)
  744. eh (this, e);
  745. }
  746. protected virtual void OnSendMailError (SendMailErrorEventArgs e)
  747. {
  748. SendMailErrorEventHandler eh = events [sendingMailEvent] as SendMailErrorEventHandler;
  749. if (eh != null)
  750. eh (this, e);
  751. }
  752. protected virtual void OnUserLookupError (EventArgs e)
  753. {
  754. EventHandler eh = events [userLookupErrorEvent] as EventHandler;
  755. if (eh != null)
  756. eh (this, e);
  757. }
  758. protected virtual void OnVerifyingAnswer (LoginCancelEventArgs e)
  759. {
  760. LoginCancelEventHandler eh = events [verifyingAnswerEvent] as LoginCancelEventHandler;
  761. if (eh != null)
  762. eh (this, e);
  763. }
  764. protected virtual void OnVerifyingUser (LoginCancelEventArgs e)
  765. {
  766. LoginCancelEventHandler eh = events [verifyingUserEvent] as LoginCancelEventHandler;
  767. if (eh != null)
  768. eh (this, e);
  769. }
  770. #endregion
  771. #region Private Event Handlers
  772. void UserName_TextChanged (object sender, EventArgs e)
  773. {
  774. UserName = ((ITextControl) sender).Text;
  775. }
  776. void Answer_TextChanged (object sender, EventArgs e)
  777. {
  778. _answer = ((ITextControl) sender).Text;
  779. }
  780. #endregion
  781. [MonoTODO ("Not implemented")]
  782. protected override void SetDesignModeState (IDictionary data)
  783. {
  784. throw new NotImplementedException ();
  785. }
  786. abstract class BasePasswordRecoveryContainer : Table, INamingContainer
  787. {
  788. protected readonly PasswordRecovery _owner = null;
  789. TableCell _containerCell = null;
  790. public BasePasswordRecoveryContainer (PasswordRecovery owner)
  791. {
  792. _owner = owner;
  793. InitTable ();
  794. }
  795. public void InstantiateTemplate (ITemplate template)
  796. {
  797. template.InstantiateIn (_containerCell);
  798. }
  799. void InitTable ()
  800. {
  801. Attributes.Add ("ID", _owner.ID);
  802. CellSpacing = 0;
  803. CellPadding = _owner.BorderPadding;
  804. _containerCell = new TableCell ();
  805. TableRow row = new TableRow ();
  806. row.Cells.Add (_containerCell);
  807. Rows.Add (row);
  808. }
  809. protected internal override void OnPreRender (EventArgs e)
  810. {
  811. ApplyStyle (_owner.ControlStyle);
  812. base.OnPreRender (e);
  813. }
  814. public abstract void UpdateChildControls();
  815. }
  816. sealed class QuestionContainer : BasePasswordRecoveryContainer
  817. {
  818. public QuestionContainer (PasswordRecovery owner)
  819. : base (owner)
  820. {
  821. }
  822. // Requried controls
  823. public IEditableTextControl AnswerTextBox
  824. {
  825. get
  826. {
  827. Control c = FindControl ("Answer");
  828. if (c == null)
  829. throw new HttpException ("QuestionTemplate does not contain an IEditableTextControl with ID Answer for the username.");
  830. return c as IEditableTextControl;
  831. }
  832. }
  833. // Optional controls
  834. public Literal UserNameLiteral
  835. {
  836. get { return FindControl ("UserName") as Literal; }
  837. }
  838. public Literal QuestionLiteral
  839. {
  840. get { return FindControl ("Question") as Literal; }
  841. }
  842. public Literal FailureTextLiteral
  843. {
  844. get { return FindControl ("FailureText") as Literal; }
  845. }
  846. public override void UpdateChildControls ()
  847. {
  848. if (UserNameLiteral != null)
  849. UserNameLiteral.Text = _owner.UserName;
  850. if (QuestionLiteral != null)
  851. QuestionLiteral.Text = _owner.Question;
  852. }
  853. }
  854. sealed class SuccessContainer : BasePasswordRecoveryContainer
  855. {
  856. public SuccessContainer (PasswordRecovery owner)
  857. : base (owner)
  858. {
  859. }
  860. public override void UpdateChildControls ()
  861. {
  862. }
  863. }
  864. sealed class UserNameContainer : BasePasswordRecoveryContainer
  865. {
  866. public UserNameContainer (PasswordRecovery owner)
  867. : base (owner)
  868. {
  869. }
  870. // Requried controls
  871. public IEditableTextControl UserNameTextBox
  872. {
  873. get
  874. {
  875. Control c = FindControl ("UserName");
  876. if (c == null)
  877. throw new HttpException ("UserNameTemplate does not contain an IEditableTextControl with ID UserName for the username.");
  878. return c as IEditableTextControl;
  879. }
  880. }
  881. // Optional controls
  882. public ITextControl FailureTextLiteral
  883. {
  884. get { return FindControl ("FailureText") as ITextControl; }
  885. }
  886. public override void UpdateChildControls ()
  887. {
  888. }
  889. }
  890. class TemplateUtils
  891. {
  892. public static TableRow CreateRow(Control c1, Control c2, Style s1, Style s2, bool twoCells)
  893. {
  894. TableRow row = new TableRow ();
  895. TableCell cell1 = new TableCell ();
  896. cell1.Controls.Add (c1);
  897. if (s1 != null)
  898. cell1.ApplyStyle (s1);
  899. row.Cells.Add (cell1);
  900. if (c2 != null) {
  901. TableCell cell2 = new TableCell ();
  902. cell2.Controls.Add (c2);
  903. if (s2 != null)
  904. cell2.ApplyStyle (s2);
  905. row.Cells.Add (cell2);
  906. cell1.HorizontalAlign = HorizontalAlign.Right;
  907. cell2.HorizontalAlign = HorizontalAlign.Left;
  908. }
  909. else {
  910. cell1.HorizontalAlign = HorizontalAlign.Center;
  911. if (twoCells)
  912. cell1.ColumnSpan = 2;
  913. }
  914. return row;
  915. }
  916. public static TableRow CreateHelpRow (string pageUrl, string linkText, string linkIcon, Style linkStyle, bool twoCells)
  917. {
  918. TableRow row = new TableRow ();
  919. TableCell cell1 = new TableCell ();
  920. if (linkIcon.Length > 0) {
  921. Image img = new Image ();
  922. img.ImageUrl = linkIcon;
  923. cell1.Controls.Add (img);
  924. }
  925. if (linkText.Length > 0) {
  926. HyperLink link = new HyperLink ();
  927. link.NavigateUrl = pageUrl;
  928. link.Text = linkText;
  929. link.ControlStyle.CopyTextStylesFrom (linkStyle);
  930. cell1.Controls.Add (link);
  931. }
  932. if (twoCells)
  933. cell1.ColumnSpan = 2;
  934. row.ControlStyle.CopyFrom (linkStyle);
  935. row.Cells.Add (cell1);
  936. return row;
  937. }
  938. }
  939. sealed class UserNameDefaultTemplate : ITemplate
  940. {
  941. readonly PasswordRecovery _owner = null;
  942. public UserNameDefaultTemplate (PasswordRecovery _owner)
  943. {
  944. this._owner = _owner;
  945. }
  946. public void InstantiateIn (Control container)
  947. {
  948. Table table = new Table ();
  949. table.CellPadding = 0;
  950. bool twoCells = _owner.TextLayout == LoginTextLayout.TextOnLeft;
  951. // row 0
  952. table.Rows.Add (
  953. TemplateUtils.CreateRow (new LiteralControl (_owner.UserNameTitleText), null, _owner.TitleTextStyle, null, twoCells));
  954. // row 1
  955. table.Rows.Add (
  956. TemplateUtils.CreateRow (new LiteralControl (_owner.UserNameInstructionText), null, _owner.InstructionTextStyle, null, twoCells));
  957. // row 2
  958. TextBox UserNameTextBox = new TextBox ();
  959. UserNameTextBox.ID = "UserName";
  960. UserNameTextBox.Text = _owner.UserName;
  961. UserNameTextBox.ApplyStyle (_owner.TextBoxStyle);
  962. Label UserNameLabel = new Label ();
  963. UserNameLabel.ID = "UserNameLabel";
  964. UserNameLabel.AssociatedControlID = "UserName";
  965. UserNameLabel.Text = _owner.UserNameLabelText;
  966. UserNameLabel.ApplyStyle (_owner.LabelStyle);
  967. RequiredFieldValidator UserNameRequired = new RequiredFieldValidator ();
  968. UserNameRequired.ID = "UserNameRequired";
  969. UserNameRequired.ControlToValidate = "UserName";
  970. UserNameRequired.ErrorMessage = _owner.UserNameRequiredErrorMessage;
  971. UserNameRequired.ToolTip = _owner.UserNameRequiredErrorMessage;
  972. UserNameRequired.Text = "*";
  973. UserNameRequired.ValidationGroup = _owner.ID;
  974. UserNameRequired.ApplyStyle (_owner.ValidatorTextStyle);
  975. if (twoCells) {
  976. TableRow row = TemplateUtils.CreateRow (UserNameLabel, UserNameTextBox, null, null, twoCells);
  977. row.Cells [1].Controls.Add (UserNameRequired);
  978. table.Rows.Add (row);
  979. }
  980. else {
  981. table.Rows.Add (TemplateUtils.CreateRow (UserNameLabel, null, null, null, twoCells));
  982. TableRow row = TemplateUtils.CreateRow (UserNameTextBox, null, null, null, twoCells);
  983. row.Cells [0].Controls.Add (UserNameRequired);
  984. table.Rows.Add (row);
  985. }
  986. // row 3
  987. Literal FailureText = new Literal ();
  988. FailureText.ID = "FailureText";
  989. if (_owner.FailureTextStyle.ForeColor.IsEmpty)
  990. _owner.FailureTextStyle.ForeColor = System.Drawing.Color.Red;
  991. table.Rows.Add (TemplateUtils.CreateRow (FailureText, null, _owner.FailureTextStyle, null, twoCells));
  992. // row 4
  993. WebControl SubmitButton = null;
  994. switch (_owner.SubmitButtonType) {
  995. case ButtonType.Button:
  996. SubmitButton = new Button ();
  997. break;
  998. case ButtonType.Image:
  999. SubmitButton = new ImageButton ();
  1000. break;
  1001. case ButtonType.Link:
  1002. SubmitButton = new LinkButton ();
  1003. break;
  1004. }
  1005. SubmitButton.ID = "SubmitButton";
  1006. SubmitButton.ApplyStyle (_owner.SubmitButtonStyle);
  1007. ((IButtonControl) SubmitButton).CommandName = PasswordRecovery.SubmitButtonCommandName;
  1008. ((IButtonControl) SubmitButton).Text = _owner.SubmitButtonText;
  1009. ((IButtonControl) SubmitButton).ValidationGroup = _owner.ID;
  1010. TableRow buttonRow = TemplateUtils.CreateRow (SubmitButton, null, null, null, twoCells);
  1011. buttonRow.Cells [0].HorizontalAlign = HorizontalAlign.Right;
  1012. table.Rows.Add (buttonRow);
  1013. // row 5
  1014. table.Rows.Add (
  1015. TemplateUtils.CreateHelpRow (
  1016. _owner.HelpPageUrl, _owner.HelpPageText, _owner.HelpPageIconUrl, _owner.HyperLinkStyle, twoCells));
  1017. container.Controls.Add (table);
  1018. }
  1019. }
  1020. sealed class QuestionDefaultTemplate : ITemplate
  1021. {
  1022. readonly PasswordRecovery _owner = null;
  1023. public QuestionDefaultTemplate (PasswordRecovery _owner)
  1024. {
  1025. this._owner = _owner;
  1026. }
  1027. public void InstantiateIn (Control container)
  1028. {
  1029. Table table = new Table ();
  1030. table.CellPadding = 0;
  1031. bool twoCells = _owner.TextLayout == LoginTextLayout.TextOnLeft;
  1032. // row 0
  1033. table.Rows.Add (
  1034. TemplateUtils.CreateRow (new LiteralControl (_owner.QuestionTitleText), null, _owner.TitleTextStyle, null, twoCells));
  1035. // row 1
  1036. table.Rows.Add (
  1037. TemplateUtils.CreateRow (new LiteralControl (_owner.QuestionInstructionText), null, _owner.InstructionTextStyle, null, twoCells));
  1038. // row 2
  1039. Literal UserNameLiteral = new Literal ();
  1040. UserNameLiteral.ID = "UserName";
  1041. table.Rows.Add (
  1042. TemplateUtils.CreateRow (new LiteralControl (_owner.UserNameLabelText), UserNameLiteral, _owner.LabelStyle, _owner.LabelStyle, twoCells));
  1043. // row 3
  1044. Literal QuestionLiteral = new Literal ();
  1045. QuestionLiteral.ID = "Question";
  1046. table.Rows.Add (
  1047. TemplateUtils.CreateRow (new LiteralControl (_owner.QuestionLabelText), QuestionLiteral, _owner.LabelStyle, _owner.LabelStyle, twoCells));
  1048. // row 5
  1049. TextBox AnswerTextBox = new TextBox ();
  1050. AnswerTextBox.ID = "Answer";
  1051. AnswerTextBox.ApplyStyle (_owner.TextBoxStyle);
  1052. Label AnswerLabel = new Label ();
  1053. AnswerLabel.ID = "AnswerLabel";
  1054. AnswerLabel.AssociatedControlID = "Answer";
  1055. AnswerLabel.Text = _owner.AnswerLabelText;
  1056. AnswerLabel.ApplyStyle (_owner.LabelStyle);
  1057. RequiredFieldValidator AnswerRequired = new RequiredFieldValidator ();
  1058. AnswerRequired.ID = "AnswerRequired";
  1059. AnswerRequired.ControlToValidate = "Answer";
  1060. AnswerRequired.ErrorMessage = _owner.AnswerRequiredErrorMessage;
  1061. AnswerRequired.ToolTip = _owner.AnswerRequiredErrorMessage;
  1062. AnswerRequired.Text = "*";
  1063. AnswerRequired.ValidationGroup = _owner.ID;
  1064. AnswerRequired.ApplyStyle (_owner.ValidatorTextStyle);
  1065. if (twoCells) {
  1066. TableRow row = TemplateUtils.CreateRow (AnswerLabel, AnswerTextBox, null, null, twoCells);
  1067. row.Cells [1].Controls.Add (AnswerRequired);
  1068. table.Rows.Add (row);
  1069. }
  1070. else {
  1071. table.Rows.Add (TemplateUtils.CreateRow (AnswerLabel, null, null, null, twoCells));
  1072. TableRow row = TemplateUtils.CreateRow (AnswerTextBox, null, null, null, twoCells);
  1073. row.Cells [0].Controls.Add (AnswerRequired);
  1074. table.Rows.Add (row);
  1075. }
  1076. // row 6
  1077. Literal FailureText = new Literal ();
  1078. FailureText.ID = "FailureText";
  1079. if (_owner.FailureTextStyle.ForeColor.IsEmpty)
  1080. _owner.FailureTextStyle.ForeColor = System.Drawing.Color.Red;
  1081. table.Rows.Add (TemplateUtils.CreateRow (FailureText, null, _owner.FailureTextStyle, null, twoCells));
  1082. // row 7
  1083. WebControl SubmitButton = null;
  1084. switch (_owner.SubmitButtonType) {
  1085. case ButtonType.Button:
  1086. SubmitButton = new Button ();
  1087. break;
  1088. case ButtonType.Image:
  1089. SubmitButton = new ImageButton ();
  1090. break;
  1091. case ButtonType.Link:
  1092. SubmitButton = new LinkButton ();
  1093. break;
  1094. }
  1095. SubmitButton.ID = "SubmitButton";
  1096. SubmitButton.ApplyStyle (_owner.SubmitButtonStyle);
  1097. ((IButtonControl) SubmitButton).CommandName = PasswordRecovery.SubmitButtonCommandName;
  1098. ((IButtonControl) SubmitButton).Text = _owner.SubmitButtonText;
  1099. ((IButtonControl) SubmitButton).ValidationGroup = _owner.ID;
  1100. TableRow buttonRow = TemplateUtils.CreateRow (SubmitButton, null, null, null, twoCells);
  1101. buttonRow.Cells [0].HorizontalAlign = HorizontalAlign.Right;
  1102. table.Rows.Add (buttonRow);
  1103. // row 8
  1104. table.Rows.Add (
  1105. TemplateUtils.CreateHelpRow (
  1106. _owner.HelpPageUrl, _owner.HelpPageText, _owner.HelpPageIconUrl, _owner.HyperLinkStyle, twoCells));
  1107. container.Controls.Add (table);
  1108. }
  1109. }
  1110. sealed class SuccessDefaultTemplate : ITemplate
  1111. {
  1112. readonly PasswordRecovery _owner = null;
  1113. public SuccessDefaultTemplate (PasswordRecovery _owner)
  1114. {
  1115. this._owner = _owner;
  1116. }
  1117. public void InstantiateIn (Control container)
  1118. {
  1119. Table table = new Table ();
  1120. table.CellPadding = 0;
  1121. bool twoCells = _owner.TextLayout == LoginTextLayout.TextOnLeft;
  1122. // row 0
  1123. table.Rows.Add (
  1124. TemplateUtils.CreateRow (new LiteralControl (_owner.SuccessText), null, _owner.SuccessTextStyle, null, twoCells));
  1125. container.Controls.Add (table);
  1126. }
  1127. }
  1128. enum PasswordReciveryStep
  1129. {
  1130. StepUserName,
  1131. StepAnswer,
  1132. StepSuccess,
  1133. }
  1134. }
  1135. }
  1136. #endif