PasswordRecovery.cs 41 KB

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