ChangePassword.cs 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  1. //
  2. // System.Web.UI.WebControls.ChangePassword.cs
  3. //
  4. // Authors:
  5. // Igor Zelmanovich ([email protected])
  6. // Vladimir Krasnov ([email protected])
  7. //
  8. // (C) 2006 Mainsoft, Inc (http://www.mainsoft.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System;
  31. using System.Web.Security;
  32. using System.Collections.Generic;
  33. using System.Collections.Specialized;
  34. using System.Text;
  35. using System.ComponentModel;
  36. using System.Collections;
  37. using System.Net.Mail;
  38. namespace System.Web.UI.WebControls
  39. {
  40. public class ChangePassword : CompositeControl, INamingContainer
  41. {
  42. static readonly object cancelButtonClickEvent = new object ();
  43. static readonly object changedPasswordEvent = new object ();
  44. static readonly object changePasswordErrorEvent = new object ();
  45. static readonly object changingPasswordEvent = new object ();
  46. static readonly object continueButtonClickEvent = new object ();
  47. static readonly object sendingMailEvent = new object ();
  48. static readonly object sendMailErrorEvent = new object ();
  49. public static readonly string CancelButtonCommandName = "Cancel";
  50. public static readonly string ChangePasswordButtonCommandName = "ChangePassword";
  51. public static readonly string ContinueButtonCommandName = "Continue";
  52. Style _cancelButtonStyle = null;
  53. Style _changePasswordButtonStyle = null;
  54. Style _continueButtonStyle = null;
  55. TableItemStyle _failureTextStyle = null;
  56. TableItemStyle _hyperLinkStyle = null;
  57. TableItemStyle _instructionTextStyle = null;
  58. TableItemStyle _labelStyle = null;
  59. TableItemStyle _passwordHintStyle = null;
  60. TableItemStyle _successTextStyle = null;
  61. Style _textBoxStyle = null;
  62. TableItemStyle _titleTextStyle = null;
  63. Style _validatorTextStyle = null;
  64. MailDefinition _mailDefinition = null;
  65. MembershipProvider _provider = null;
  66. ITemplate _changePasswordTemplate = null;
  67. ITemplate _successTemplate = null;
  68. Control _changePasswordTemplateContainer = null;
  69. Control _successTemplateContainer = null;
  70. string _username = null;
  71. string _currentPassword = null;
  72. string _newPassword = null;
  73. string _newPasswordConfirm = null;
  74. bool _showContinue = false;
  75. EventHandlerList events = new EventHandlerList ();
  76. #region Public Events
  77. public event EventHandler CancelButtonClick {
  78. add { events.AddHandler (cancelButtonClickEvent, value); }
  79. remove { events.RemoveHandler (cancelButtonClickEvent, value); }
  80. }
  81. public event EventHandler ChangedPassword {
  82. add { events.AddHandler (changedPasswordEvent, value); }
  83. remove { events.RemoveHandler (changedPasswordEvent, value); }
  84. }
  85. public event EventHandler ChangePasswordError {
  86. add { events.AddHandler (changePasswordErrorEvent, value); }
  87. remove { events.RemoveHandler (changePasswordErrorEvent, value); }
  88. }
  89. public event LoginCancelEventHandler ChangingPassword {
  90. add { events.AddHandler (changingPasswordEvent, value); }
  91. remove { events.RemoveHandler (changingPasswordEvent, value); }
  92. }
  93. public event EventHandler ContinueButtonClick {
  94. add { events.AddHandler (continueButtonClickEvent, value); }
  95. remove { events.RemoveHandler (continueButtonClickEvent, value); }
  96. }
  97. public event MailMessageEventHandler SendingMail {
  98. add { events.AddHandler (sendingMailEvent, value); }
  99. remove { events.RemoveHandler (sendingMailEvent, value); }
  100. }
  101. public event SendMailErrorEventHandler SendMailError {
  102. add { events.AddHandler (sendMailErrorEvent, value); }
  103. remove { events.RemoveHandler (sendMailErrorEvent, value); }
  104. }
  105. #endregion
  106. #region Public Properties
  107. [DefaultValue (1)]
  108. public virtual int BorderPadding
  109. {
  110. get { return ViewState.GetInt ("BorderPadding", 1); }
  111. set
  112. {
  113. if (value < -1)
  114. throw new ArgumentOutOfRangeException ();
  115. ViewState ["BorderPadding"] = value;
  116. }
  117. }
  118. [DefaultValue ("")]
  119. public virtual string CancelButtonImageUrl
  120. {
  121. get { return ViewState.GetString ("CancelButtonImageUrl", String.Empty); }
  122. set { ViewState ["CancelButtonImageUrl"] = value; }
  123. }
  124. [PersistenceMode (PersistenceMode.InnerProperty)]
  125. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  126. [NotifyParentProperty (true)]
  127. public Style CancelButtonStyle
  128. {
  129. get
  130. {
  131. if (_cancelButtonStyle == null) {
  132. _cancelButtonStyle = new Style ();
  133. if (IsTrackingViewState)
  134. _cancelButtonStyle.TrackViewState ();
  135. }
  136. return _cancelButtonStyle;
  137. }
  138. }
  139. [Localizable (true)]
  140. public virtual string CancelButtonText
  141. {
  142. get { return ViewState.GetString ("CancelButtonText", "Cancel"); }
  143. set { ViewState ["CancelButtonText"] = value; }
  144. }
  145. public virtual ButtonType CancelButtonType
  146. {
  147. get { return ViewState ["CancelButtonType"] == null ? ButtonType.Button : (ButtonType) ViewState ["CancelButtonType"]; }
  148. set { ViewState ["CancelButtonType"] = value; }
  149. }
  150. [Themeable (false)]
  151. public virtual string CancelDestinationPageUrl
  152. {
  153. get { return ViewState.GetString ("CancelDestinationPageUrl", String.Empty); }
  154. set { ViewState ["CancelDestinationPageUrl"] = value; }
  155. }
  156. public virtual string ChangePasswordButtonImageUrl
  157. {
  158. get { return ViewState.GetString ("ChangePasswordButtonImageUrl", String.Empty); }
  159. set { ViewState ["ChangePasswordButtonImageUrl"] = value; }
  160. }
  161. [DefaultValue ("")]
  162. [PersistenceMode (PersistenceMode.InnerProperty)]
  163. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  164. [NotifyParentProperty (true)]
  165. public Style ChangePasswordButtonStyle
  166. {
  167. get
  168. {
  169. if (_changePasswordButtonStyle == null) {
  170. _changePasswordButtonStyle = new Style ();
  171. if (IsTrackingViewState)
  172. _changePasswordButtonStyle.TrackViewState ();
  173. }
  174. return _changePasswordButtonStyle;
  175. }
  176. }
  177. [Localizable (true)]
  178. public virtual string ChangePasswordButtonText
  179. {
  180. get { return ViewState.GetString ("ChangePasswordButtonText", "Change Password"); }
  181. set { ViewState ["ChangePasswordButtonText"] = value; }
  182. }
  183. public virtual ButtonType ChangePasswordButtonType
  184. {
  185. get { return ViewState ["ChangePasswordButtonType"] == null ? ButtonType.Button : (ButtonType) ViewState ["ChangePasswordButtonType"]; }
  186. set { ViewState ["ChangePasswordButtonType"] = value; }
  187. }
  188. [Localizable (true)]
  189. public virtual string ChangePasswordFailureText
  190. {
  191. get { return ViewState.GetString ("ChangePasswordFailureText", "Your attempt to change passwords was unsuccessful. Please try again."); }
  192. set { ViewState ["ChangePasswordFailureText"] = value; }
  193. }
  194. [Browsable (false)]
  195. [PersistenceMode (PersistenceMode.InnerProperty)]
  196. [TemplateContainer (typeof (ChangePassword))]
  197. public virtual ITemplate ChangePasswordTemplate
  198. {
  199. get { return _changePasswordTemplate; }
  200. set { _changePasswordTemplate = value; }
  201. }
  202. [Browsable (false)]
  203. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  204. public Control ChangePasswordTemplateContainer
  205. {
  206. get
  207. {
  208. if (_changePasswordTemplateContainer == null)
  209. _changePasswordTemplateContainer = new ChangePasswordContainer (this);
  210. return _changePasswordTemplateContainer;
  211. }
  212. }
  213. [Localizable (true)]
  214. public virtual string ChangePasswordTitleText
  215. {
  216. get { return ViewState.GetString ("ChangePasswordTitleText", "Change Your Password"); }
  217. set { ViewState ["ChangePasswordTitleText"] = value; }
  218. }
  219. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  220. [Browsable (false)]
  221. [Themeable (false)]
  222. [Filterable (false)]
  223. public virtual string ConfirmNewPassword
  224. {
  225. get { return _newPasswordConfirm != null ? _newPasswordConfirm : ""; }
  226. }
  227. [Localizable (true)]
  228. public virtual string ConfirmNewPasswordLabelText
  229. {
  230. get { return ViewState.GetString ("ConfirmNewPasswordLabelText", "Confirm New Password:"); }
  231. set { ViewState ["ConfirmNewPasswordLabelText"] = value; }
  232. }
  233. [Localizable (true)]
  234. public virtual string ConfirmPasswordCompareErrorMessage
  235. {
  236. get { return ViewState.GetString ("ConfirmPasswordCompareErrorMessage", "The Confirm New Password must match the New Password entry."); }
  237. set { ViewState ["ConfirmPasswordCompareErrorMessage"] = value; }
  238. }
  239. [Localizable (true)]
  240. public virtual string ConfirmPasswordRequiredErrorMessage
  241. {
  242. get { return ViewState.GetString ("ConfirmPasswordRequiredErrorMessage", String.Empty); }
  243. set { ViewState ["ConfirmPasswordRequiredErrorMessage"] = value; }
  244. }
  245. public virtual string ContinueButtonImageUrl
  246. {
  247. get { return ViewState.GetString ("ContinueButtonImageUrl", String.Empty); }
  248. set { ViewState ["ContinueButtonImageUrl"] = value; }
  249. }
  250. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  251. [NotifyParentProperty (true)]
  252. [PersistenceMode (PersistenceMode.InnerProperty)]
  253. public Style ContinueButtonStyle
  254. {
  255. get
  256. {
  257. if (_continueButtonStyle == null) {
  258. _continueButtonStyle = new Style ();
  259. if (IsTrackingViewState)
  260. _continueButtonStyle.TrackViewState ();
  261. }
  262. return _continueButtonStyle;
  263. }
  264. }
  265. [Localizable (true)]
  266. public virtual string ContinueButtonText
  267. {
  268. get { return ViewState.GetString ("ContinueButtonText", "Continue"); }
  269. set { ViewState ["ContinueButtonText"] = value; }
  270. }
  271. public virtual ButtonType ContinueButtonType
  272. {
  273. get { return ViewState ["ContinueButtonType"] == null ? ButtonType.Button : (ButtonType) ViewState ["ContinueButtonType"]; }
  274. set { ViewState ["ContinueButtonType"] = value; }
  275. }
  276. [Themeable (false)]
  277. public virtual string ContinueDestinationPageUrl
  278. {
  279. get { return ViewState.GetString ("ContinueDestinationPageUrl", String.Empty); }
  280. set { ViewState ["ContinueDestinationPageUrl"] = value; }
  281. }
  282. public virtual string CreateUserIconUrl
  283. {
  284. get { return ViewState.GetString ("CreateUserIconUrl", String.Empty); }
  285. set { ViewState ["CreateUserIconUrl"] = value; }
  286. }
  287. [Localizable (true)]
  288. public virtual string CreateUserText
  289. {
  290. get { return ViewState.GetString ("CreateUserText", String.Empty); }
  291. set { ViewState ["CreateUserText"] = value; }
  292. }
  293. public virtual string CreateUserUrl
  294. {
  295. get { return ViewState.GetString ("CreateUserUrl", String.Empty); }
  296. set { ViewState ["CreateUserUrl"] = value; }
  297. }
  298. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  299. [Browsable (false)]
  300. [Themeable (false)]
  301. public virtual string CurrentPassword
  302. {
  303. get { return _currentPassword != null ? _currentPassword : ""; }
  304. }
  305. [DefaultValue (false)]
  306. public virtual bool DisplayUserName
  307. {
  308. get { return ViewState.GetBool ("DisplayUserName", false); }
  309. set { ViewState ["DisplayUserName"] = value; }
  310. }
  311. public virtual string EditProfileIconUrl
  312. {
  313. get { return ViewState.GetString ("EditProfileIconUrl", String.Empty); }
  314. set { ViewState ["EditProfileIconUrl"] = value; }
  315. }
  316. [Localizable (true)]
  317. public virtual string EditProfileText
  318. {
  319. get { return ViewState.GetString ("EditProfileText", String.Empty); }
  320. set { ViewState ["EditProfileText"] = value; }
  321. }
  322. public virtual string EditProfileUrl
  323. {
  324. get { return ViewState.GetString ("EditProfileUrl", String.Empty); }
  325. set { ViewState ["EditProfileUrl"] = value; }
  326. }
  327. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  328. [NotifyParentProperty (true)]
  329. [PersistenceMode (PersistenceMode.InnerProperty)]
  330. public TableItemStyle FailureTextStyle
  331. {
  332. get
  333. {
  334. if (_failureTextStyle == null) {
  335. _failureTextStyle = new TableItemStyle ();
  336. if (IsTrackingViewState)
  337. _failureTextStyle.TrackViewState ();
  338. }
  339. return _failureTextStyle;
  340. }
  341. }
  342. public virtual string HelpPageIconUrl
  343. {
  344. get { return ViewState.GetString ("HelpPageIconUrl", String.Empty); }
  345. set { ViewState ["HelpPageIconUrl"] = value; }
  346. }
  347. [Localizable (true)]
  348. public virtual string HelpPageText
  349. {
  350. get { return ViewState.GetString ("HelpPageText", String.Empty); }
  351. set { ViewState ["HelpPageText"] = value; }
  352. }
  353. public virtual string HelpPageUrl
  354. {
  355. get { return ViewState.GetString ("HelpPageUrl", String.Empty); }
  356. set { ViewState ["HelpPageUrl"] = value; }
  357. }
  358. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  359. [NotifyParentProperty (true)]
  360. [PersistenceMode (PersistenceMode.InnerProperty)]
  361. public TableItemStyle HyperLinkStyle
  362. {
  363. get
  364. {
  365. if (_hyperLinkStyle == null) {
  366. _hyperLinkStyle = new TableItemStyle ();
  367. if (IsTrackingViewState)
  368. _hyperLinkStyle.TrackViewState ();
  369. }
  370. return _hyperLinkStyle;
  371. }
  372. }
  373. [Localizable (true)]
  374. public virtual string InstructionText
  375. {
  376. get { return ViewState.GetString ("InstructionText", String.Empty); }
  377. set { ViewState ["InstructionText"] = value; }
  378. }
  379. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  380. [NotifyParentProperty (true)]
  381. [PersistenceMode (PersistenceMode.InnerProperty)]
  382. public TableItemStyle InstructionTextStyle
  383. {
  384. get
  385. {
  386. if (_instructionTextStyle == null) {
  387. _instructionTextStyle = new TableItemStyle ();
  388. if (IsTrackingViewState)
  389. _instructionTextStyle.TrackViewState ();
  390. }
  391. return _instructionTextStyle;
  392. }
  393. }
  394. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  395. [NotifyParentProperty (true)]
  396. [PersistenceMode (PersistenceMode.InnerProperty)]
  397. public TableItemStyle LabelStyle
  398. {
  399. get
  400. {
  401. if (_labelStyle == null) {
  402. _labelStyle = new TableItemStyle ();
  403. if (IsTrackingViewState)
  404. _labelStyle.TrackViewState ();
  405. }
  406. return _labelStyle;
  407. }
  408. }
  409. [Themeable (false)]
  410. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  411. [NotifyParentProperty (true)]
  412. [PersistenceMode (PersistenceMode.InnerProperty)]
  413. public MailDefinition MailDefinition
  414. {
  415. get
  416. {
  417. if (_mailDefinition == null) {
  418. _mailDefinition = new MailDefinition ();
  419. if (IsTrackingViewState)
  420. ((IStateManager) _mailDefinition).TrackViewState ();
  421. }
  422. return _mailDefinition;
  423. }
  424. }
  425. [Themeable (false)]
  426. [DefaultValue ("")]
  427. public virtual string MembershipProvider
  428. {
  429. get
  430. {
  431. object o = ViewState ["MembershipProvider"];
  432. return (o == null) ? "" : (string) o;
  433. }
  434. set
  435. {
  436. if (value == null)
  437. ViewState.Remove ("MembershipProvider");
  438. else
  439. ViewState ["MembershipProvider"] = value;
  440. _provider = null;
  441. }
  442. }
  443. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  444. [Themeable (false)]
  445. public virtual string NewPassword
  446. {
  447. get { return _newPassword != null ? _newPassword : ""; }
  448. }
  449. [Localizable (true)]
  450. public virtual string NewPasswordLabelText
  451. {
  452. get { return ViewState.GetString ("NewPasswordLabelText", "New Password:"); }
  453. set { ViewState ["NewPasswordLabelText"] = value; }
  454. }
  455. public virtual string NewPasswordRegularExpression
  456. {
  457. get { return ViewState.GetString ("NewPasswordRegularExpression", String.Empty); }
  458. set { ViewState ["NewPasswordRegularExpression"] = value; }
  459. }
  460. public virtual string NewPasswordRegularExpressionErrorMessage
  461. {
  462. get { return ViewState.GetString ("NewPasswordRegularExpressionErrorMessage", String.Empty); }
  463. set { ViewState ["NewPasswordRegularExpressionErrorMessage"] = value; }
  464. }
  465. [Localizable (true)]
  466. public virtual string NewPasswordRequiredErrorMessage
  467. {
  468. get { return ViewState.GetString ("NewPasswordRequiredErrorMessage", "New Password is required."); }
  469. set { ViewState ["NewPasswordRequiredErrorMessage"] = value; }
  470. }
  471. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  472. [NotifyParentProperty (true)]
  473. [PersistenceMode (PersistenceMode.InnerProperty)]
  474. public TableItemStyle PasswordHintStyle
  475. {
  476. get
  477. {
  478. if (_passwordHintStyle == null) {
  479. _passwordHintStyle = new TableItemStyle ();
  480. if (IsTrackingViewState)
  481. _passwordHintStyle.TrackViewState ();
  482. }
  483. return _passwordHintStyle;
  484. }
  485. }
  486. [Localizable (true)]
  487. public virtual string PasswordHintText
  488. {
  489. get { return ViewState.GetString ("PasswordHintText", String.Empty); }
  490. set { ViewState ["PasswordHintText"] = value; }
  491. }
  492. [Localizable (true)]
  493. public virtual string PasswordLabelText
  494. {
  495. get { return ViewState.GetString ("PasswordLabelText", "Password:"); }
  496. set { ViewState ["PasswordLabelText"] = value; }
  497. }
  498. public virtual string PasswordRecoveryIconUrl
  499. {
  500. get { return ViewState.GetString ("PasswordRecoveryIconUrl", String.Empty); }
  501. set { ViewState ["PasswordRecoveryIconUrl"] = value; }
  502. }
  503. [Localizable (true)]
  504. public virtual string PasswordRecoveryText
  505. {
  506. get { return ViewState.GetString ("PasswordRecoveryText", String.Empty); }
  507. set { ViewState ["PasswordRecoveryText"] = value; }
  508. }
  509. public virtual string PasswordRecoveryUrl
  510. {
  511. get { return ViewState.GetString ("PasswordRecoveryUrl", String.Empty); }
  512. set { ViewState ["PasswordRecoveryUrl"] = value; }
  513. }
  514. [Localizable (true)]
  515. public virtual string PasswordRequiredErrorMessage
  516. {
  517. get { return ViewState.GetString ("PasswordRequiredErrorMessage", String.Empty); }
  518. set { ViewState ["PasswordRequiredErrorMessage"] = value; }
  519. }
  520. [Themeable (false)]
  521. public virtual string SuccessPageUrl
  522. {
  523. get { return ViewState.GetString ("SuccessPageUrl", String.Empty); }
  524. set { ViewState ["SuccessPageUrl"] = value; }
  525. }
  526. [PersistenceMode (PersistenceMode.InnerProperty)]
  527. [TemplateContainer (typeof (ChangePassword))]
  528. [Browsable (false)]
  529. public virtual ITemplate SuccessTemplate
  530. {
  531. get { return _successTemplate; }
  532. set { _successTemplate = value; }
  533. }
  534. [Browsable (false)]
  535. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  536. public Control SuccessTemplateContainer
  537. {
  538. get
  539. {
  540. if (_successTemplateContainer == null)
  541. _successTemplateContainer = new SuccessContainer (this);
  542. return _successTemplateContainer;
  543. }
  544. }
  545. [Localizable (true)]
  546. public virtual string SuccessText
  547. {
  548. get { return ViewState.GetString ("SuccessText", "Your password has been changed!"); }
  549. set { ViewState ["SuccessText"] = value; }
  550. }
  551. [NotifyParentProperty (true)]
  552. [PersistenceMode (PersistenceMode.InnerProperty)]
  553. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  554. public TableItemStyle SuccessTextStyle
  555. {
  556. get
  557. {
  558. if (_successTextStyle == null) {
  559. _successTextStyle = new TableItemStyle ();
  560. if (IsTrackingViewState)
  561. _successTextStyle.TrackViewState ();
  562. }
  563. return _successTextStyle;
  564. }
  565. }
  566. [Localizable (true)]
  567. public virtual string SuccessTitleText
  568. {
  569. get { return ViewState.GetString ("SuccessTitleText", "Change Password Complete"); }
  570. set { ViewState ["SuccessTitleText"] = value; }
  571. }
  572. [NotifyParentProperty (true)]
  573. [PersistenceMode (PersistenceMode.InnerProperty)]
  574. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  575. public Style TextBoxStyle
  576. {
  577. get
  578. {
  579. if (_textBoxStyle == null) {
  580. _textBoxStyle = new Style ();
  581. if (IsTrackingViewState)
  582. _textBoxStyle.TrackViewState ();
  583. }
  584. return _textBoxStyle;
  585. }
  586. }
  587. [NotifyParentProperty (true)]
  588. [PersistenceMode (PersistenceMode.InnerProperty)]
  589. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  590. public TableItemStyle TitleTextStyle
  591. {
  592. get
  593. {
  594. if (_titleTextStyle == null) {
  595. _titleTextStyle = new TableItemStyle ();
  596. if (IsTrackingViewState)
  597. _titleTextStyle.TrackViewState ();
  598. }
  599. return _titleTextStyle;
  600. }
  601. }
  602. [DefaultValue ("")]
  603. public virtual string UserName
  604. {
  605. get
  606. {
  607. if (_username == null && HttpContext.Current.Request.IsAuthenticated)
  608. _username = HttpContext.Current.User.Identity.Name;
  609. return _username != null ? _username : "";
  610. }
  611. set { _username = value; }
  612. }
  613. [Localizable (true)]
  614. public virtual string UserNameLabelText
  615. {
  616. get { return ViewState.GetString ("UserNameLabelText", "User Name:"); }
  617. set { ViewState ["UserNameLabelText"] = value; }
  618. }
  619. [Localizable (true)]
  620. public virtual string UserNameRequiredErrorMessage
  621. {
  622. get { return ViewState.GetString ("UserNameRequiredErrorMessage", "User Name is required."); }
  623. set { ViewState ["UserNameRequiredErrorMessage"] = value; }
  624. }
  625. [NotifyParentProperty (true)]
  626. [PersistenceMode (PersistenceMode.InnerProperty)]
  627. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  628. public Style ValidatorTextStyle
  629. {
  630. get
  631. {
  632. if (_validatorTextStyle == null) {
  633. _validatorTextStyle = new Style ();
  634. if (IsTrackingViewState)
  635. _validatorTextStyle.TrackViewState ();
  636. }
  637. return _validatorTextStyle;
  638. }
  639. }
  640. #endregion
  641. #region Protected Methods
  642. protected internal override void CreateChildControls ()
  643. {
  644. Controls.Clear ();
  645. ITemplate cpTemplate = ChangePasswordTemplate;
  646. if (cpTemplate == null)
  647. cpTemplate = new ChangePasswordDeafultTemplate (this);
  648. ((ChangePasswordContainer) ChangePasswordTemplateContainer).InstantiateTemplate (cpTemplate);
  649. ITemplate sTemplate = SuccessTemplate;
  650. if (sTemplate == null)
  651. sTemplate = new SuccessDefaultTemplate (this);
  652. ((SuccessContainer) SuccessTemplateContainer).InstantiateTemplate (sTemplate);
  653. Controls.AddAt (0, ChangePasswordTemplateContainer);
  654. Controls.AddAt (1, SuccessTemplateContainer);
  655. IEditableTextControl editable;
  656. ChangePasswordContainer container = (ChangePasswordContainer) ChangePasswordTemplateContainer;
  657. if (DisplayUserName) {
  658. editable = container.UserNameTextBox;
  659. if (editable != null)
  660. editable.TextChanged += new EventHandler (UserName_TextChanged);
  661. }
  662. editable = container.CurrentPasswordTextBox;
  663. if (editable != null)
  664. editable.TextChanged += new EventHandler (CurrentPassword_TextChanged);
  665. editable = container.NewPasswordTextBox;
  666. if (editable != null)
  667. editable.TextChanged += new EventHandler (NewPassword_TextChanged);
  668. editable = container.ConfirmNewPasswordTextBox;
  669. if (editable != null)
  670. editable.TextChanged += new EventHandler (NewPasswordConfirm_TextChanged);
  671. }
  672. protected internal override void Render (HtmlTextWriter writer)
  673. {
  674. for (int i = 0; i < Controls.Count; i++)
  675. if (Controls [i].Visible)
  676. Controls [i].Render (writer);
  677. }
  678. #endregion
  679. #region Private Methods
  680. [MonoTODO ("Not implemented")]
  681. protected override void SetDesignModeState (IDictionary data)
  682. {
  683. throw new NotImplementedException ();
  684. }
  685. void InitMemberShipProvider ()
  686. {
  687. string mp = MembershipProvider;
  688. _provider = (mp.Length == 0) ? Membership.Provider : Membership.Providers [mp];
  689. if (_provider == null)
  690. throw new HttpException (Locale.GetText ("No provider named '{0}' could be found.", mp));
  691. }
  692. void ProcessChangePasswordEvent (CommandEventArgs args)
  693. {
  694. if (!Page.IsValid)
  695. return;
  696. LoginCancelEventArgs loginCancelEventArgs = new LoginCancelEventArgs ();
  697. OnChangingPassword (loginCancelEventArgs);
  698. if (loginCancelEventArgs.Cancel)
  699. return;
  700. bool res = false;
  701. try {
  702. res = MembershipProviderInternal.ChangePassword (UserName, CurrentPassword, NewPassword);
  703. }
  704. catch { }
  705. if (res) {
  706. OnChangedPassword (args);
  707. _showContinue = true;
  708. if (_mailDefinition != null)
  709. SendMail (UserName, NewPassword);
  710. }
  711. else {
  712. OnChangePasswordError (EventArgs.Empty);
  713. string lastError = string.Format (
  714. "Password incorrect or New Password invalid. New Password length minimum: {0}. Non-alphanumeric characters required: {1}.",
  715. MembershipProviderInternal.MinRequiredPasswordLength,
  716. MembershipProviderInternal.MinRequiredNonAlphanumericCharacters);
  717. ChangePasswordContainer container = (ChangePasswordContainer) ChangePasswordTemplateContainer;
  718. container.FailureTextLiteral.Text = lastError;
  719. _showContinue = false;
  720. }
  721. return;
  722. }
  723. void ProcessCancelEvent (CommandEventArgs args)
  724. {
  725. OnCancelButtonClick (args);
  726. if (ContinueDestinationPageUrl.Length > 0)
  727. Context.Response.Redirect (ContinueDestinationPageUrl);
  728. return;
  729. }
  730. void ProcessContinueEvent (CommandEventArgs args)
  731. {
  732. OnContinueButtonClick (args);
  733. if (ContinueDestinationPageUrl.Length > 0)
  734. Context.Response.Redirect (ContinueDestinationPageUrl);
  735. return;
  736. }
  737. void SendMail (string username, string password)
  738. {
  739. MembershipUser user = MembershipProviderInternal.GetUser (UserName, false);
  740. if (user == null)
  741. return;
  742. ListDictionary dictionary = new ListDictionary ();
  743. dictionary.Add ("<%USERNAME%>", username);
  744. dictionary.Add ("<%PASSWORD%>", password);
  745. MailMessage message = MailDefinition.CreateMailMessage (user.Email, dictionary, this);
  746. MailMessageEventArgs args = new MailMessageEventArgs (message);
  747. OnSendingMail (args);
  748. SmtpClient smtpClient = new SmtpClient ();
  749. try {
  750. smtpClient.Send (message);
  751. }
  752. catch (Exception e) {
  753. SendMailErrorEventArgs mailArgs = new SendMailErrorEventArgs (e);
  754. OnSendMailError (mailArgs);
  755. if (!mailArgs.Handled)
  756. throw e;
  757. }
  758. }
  759. #endregion
  760. #region Properties
  761. protected override HtmlTextWriterTag TagKey
  762. {
  763. get { return HtmlTextWriterTag.Table; }
  764. }
  765. internal virtual MembershipProvider MembershipProviderInternal
  766. {
  767. get
  768. {
  769. if (_provider == null)
  770. InitMemberShipProvider ();
  771. return _provider;
  772. }
  773. }
  774. #endregion
  775. #region View and Control State
  776. protected internal override void LoadControlState (object savedState)
  777. {
  778. if (savedState == null) return;
  779. object [] state = (object []) savedState;
  780. base.LoadControlState (state [0]);
  781. _showContinue = (bool) state [1];
  782. _username = (string) state [2];
  783. }
  784. protected internal override object SaveControlState ()
  785. {
  786. object state = base.SaveControlState ();
  787. return new object [] { state, _showContinue, _username };
  788. }
  789. protected override void LoadViewState (object savedState)
  790. {
  791. if (savedState == null)
  792. return;
  793. object [] states = (object []) savedState;
  794. base.LoadViewState (states [0]);
  795. if (states [1] != null)
  796. CancelButtonStyle.LoadViewState (states [1]);
  797. if (states [2] != null)
  798. ChangePasswordButtonStyle.LoadViewState (states [2]);
  799. if (states [3] != null)
  800. ContinueButtonStyle.LoadViewState (states [3]);
  801. if (states [4] != null)
  802. FailureTextStyle.LoadViewState (states [4]);
  803. if (states [5] != null)
  804. HyperLinkStyle.LoadViewState (states [5]);
  805. if (states [6] != null)
  806. InstructionTextStyle.LoadViewState (states [6]);
  807. if (states [7] != null)
  808. LabelStyle.LoadViewState (states [7]);
  809. if (states [8] != null)
  810. PasswordHintStyle.LoadViewState (states [8]);
  811. if (states [9] != null)
  812. SuccessTextStyle.LoadViewState (states [9]);
  813. if (states [10] != null)
  814. TextBoxStyle.LoadViewState (states [10]);
  815. if (states [11] != null)
  816. TitleTextStyle.LoadViewState (states [11]);
  817. if (states [12] != null)
  818. ValidatorTextStyle.LoadViewState (states [12]);
  819. if (states [13] != null)
  820. ((IStateManager) MailDefinition).LoadViewState (states [13]);
  821. }
  822. protected override object SaveViewState ()
  823. {
  824. object [] states = new object [14];
  825. states [0] = base.SaveViewState ();
  826. if (_cancelButtonStyle != null)
  827. states [1] = _cancelButtonStyle.SaveViewState ();
  828. if (_changePasswordButtonStyle != null)
  829. states [2] = _changePasswordButtonStyle.SaveViewState ();
  830. if (_continueButtonStyle != null)
  831. states [3] = _continueButtonStyle.SaveViewState ();
  832. if (_failureTextStyle != null)
  833. states [4] = _failureTextStyle.SaveViewState ();
  834. if (_hyperLinkStyle != null)
  835. states [5] = _hyperLinkStyle.SaveViewState ();
  836. if (_instructionTextStyle != null)
  837. states [6] = _instructionTextStyle.SaveViewState ();
  838. if (_labelStyle != null)
  839. states [7] = _labelStyle.SaveViewState ();
  840. if (_passwordHintStyle != null)
  841. states [8] = _passwordHintStyle.SaveViewState ();
  842. if (_successTextStyle != null)
  843. states [9] = _successTextStyle.SaveViewState ();
  844. if (_textBoxStyle != null)
  845. states [10] = _textBoxStyle.SaveViewState ();
  846. if (_titleTextStyle != null)
  847. states [11] = _titleTextStyle.SaveViewState ();
  848. if (_validatorTextStyle != null)
  849. states [12] = _validatorTextStyle.SaveViewState ();
  850. if (_mailDefinition != null)
  851. states [13] = ((IStateManager) _mailDefinition).SaveViewState ();
  852. for (int i = 0; i < states.Length; i++) {
  853. if (states [i] != null)
  854. return states;
  855. }
  856. return null;
  857. }
  858. protected override void TrackViewState ()
  859. {
  860. base.TrackViewState ();
  861. if (_cancelButtonStyle != null)
  862. _cancelButtonStyle.TrackViewState ();
  863. if (_changePasswordButtonStyle != null)
  864. _changePasswordButtonStyle.TrackViewState ();
  865. if (_continueButtonStyle != null)
  866. _continueButtonStyle.TrackViewState ();
  867. if (_failureTextStyle != null)
  868. _failureTextStyle.TrackViewState ();
  869. if (_hyperLinkStyle != null)
  870. _hyperLinkStyle.TrackViewState ();
  871. if (_instructionTextStyle != null)
  872. _instructionTextStyle.TrackViewState ();
  873. if (_labelStyle != null)
  874. _labelStyle.TrackViewState ();
  875. if (_passwordHintStyle != null)
  876. _passwordHintStyle.TrackViewState ();
  877. if (_successTextStyle != null)
  878. _successTextStyle.TrackViewState ();
  879. if (_textBoxStyle != null)
  880. _textBoxStyle.TrackViewState ();
  881. if (_titleTextStyle != null)
  882. _titleTextStyle.TrackViewState ();
  883. if (_validatorTextStyle != null)
  884. _validatorTextStyle.TrackViewState ();
  885. if (_mailDefinition != null)
  886. ((IStateManager) _mailDefinition).TrackViewState ();
  887. }
  888. #endregion
  889. #region Event Handlers
  890. protected override bool OnBubbleEvent (object source, EventArgs e)
  891. {
  892. CommandEventArgs args = e as CommandEventArgs;
  893. if (e != null) {
  894. if (args.CommandName == ChangePasswordButtonCommandName) {
  895. ProcessChangePasswordEvent (args);
  896. return true;
  897. }
  898. if (args.CommandName == CancelButtonCommandName) {
  899. ProcessCancelEvent (args);
  900. return true;
  901. }
  902. if (args.CommandName == ContinueButtonCommandName) {
  903. ProcessContinueEvent (args);
  904. return true;
  905. }
  906. }
  907. return base.OnBubbleEvent (source, e);
  908. }
  909. protected virtual void OnCancelButtonClick (EventArgs e)
  910. {
  911. EventHandler eh = events [cancelButtonClickEvent] as EventHandler;
  912. if (eh != null)
  913. eh (this, e);
  914. }
  915. protected virtual void OnChangedPassword (EventArgs e)
  916. {
  917. EventHandler eh = events [changedPasswordEvent] as EventHandler;
  918. if (eh != null)
  919. eh (this, e);
  920. }
  921. protected virtual void OnChangePasswordError (EventArgs e)
  922. {
  923. EventHandler eh = events [changePasswordErrorEvent] as EventHandler;
  924. if (eh != null)
  925. eh (this, e);
  926. }
  927. protected virtual void OnChangingPassword (LoginCancelEventArgs e)
  928. {
  929. LoginCancelEventHandler eh = events [changingPasswordEvent] as LoginCancelEventHandler;
  930. if (eh != null)
  931. eh (this, e);
  932. }
  933. protected virtual void OnContinueButtonClick (EventArgs e)
  934. {
  935. EventHandler eh = events [continueButtonClickEvent] as EventHandler;
  936. if (eh != null)
  937. eh (this, e);
  938. }
  939. protected internal override void OnInit (EventArgs e)
  940. {
  941. Page.RegisterRequiresControlState (this);
  942. base.OnInit (e);
  943. }
  944. protected internal override void OnPreRender (EventArgs e)
  945. {
  946. ChangePasswordTemplateContainer.Visible = !_showContinue;
  947. SuccessTemplateContainer.Visible = _showContinue;
  948. base.OnPreRender (e);
  949. }
  950. protected virtual void OnSendingMail (MailMessageEventArgs e)
  951. {
  952. MailMessageEventHandler eh = events [sendingMailEvent] as MailMessageEventHandler;
  953. if (eh != null)
  954. eh (this, e);
  955. }
  956. protected virtual void OnSendMailError (SendMailErrorEventArgs e)
  957. {
  958. SendMailErrorEventHandler eh = events [sendMailErrorEvent] as SendMailErrorEventHandler;
  959. if (eh != null)
  960. eh (this, e);
  961. }
  962. void UserName_TextChanged (object sender, EventArgs e)
  963. {
  964. UserName = ((ITextControl) sender).Text;
  965. }
  966. void CurrentPassword_TextChanged (object sender, EventArgs e)
  967. {
  968. _currentPassword = ((ITextControl) sender).Text;
  969. }
  970. void NewPassword_TextChanged (object sender, EventArgs e)
  971. {
  972. _newPassword = ((ITextControl) sender).Text;
  973. }
  974. void NewPasswordConfirm_TextChanged (object sender, EventArgs e)
  975. {
  976. _newPasswordConfirm = ((ITextControl) sender).Text;
  977. }
  978. #endregion
  979. class BaseChangePasswordContainer : Table, INamingContainer, INonBindingContainer
  980. {
  981. protected readonly ChangePassword _owner = null;
  982. TableCell _containerCell = null;
  983. public BaseChangePasswordContainer (ChangePassword owner)
  984. {
  985. _owner = owner;
  986. InitTable ();
  987. }
  988. public void InstantiateTemplate (ITemplate template)
  989. {
  990. template.InstantiateIn (_containerCell);
  991. }
  992. void InitTable ()
  993. {
  994. Attributes.Add ("ID", _owner.ID);
  995. CellSpacing = 0;
  996. CellPadding = _owner.BorderPadding;
  997. _containerCell = new TableCell ();
  998. TableRow row = new TableRow ();
  999. row.Cells.Add (_containerCell);
  1000. Rows.Add (row);
  1001. }
  1002. protected internal override void OnPreRender (EventArgs e)
  1003. {
  1004. ApplyStyle (_owner.ControlStyle);
  1005. base.OnPreRender (e);
  1006. }
  1007. }
  1008. sealed class ChangePasswordContainer : BaseChangePasswordContainer
  1009. {
  1010. public ChangePasswordContainer (ChangePassword owner) : base (owner)
  1011. {
  1012. ID = "ChangePasswordContainerID";
  1013. }
  1014. // Requried controls
  1015. public IEditableTextControl UserNameTextBox
  1016. {
  1017. get
  1018. {
  1019. Control c = FindControl ("UserName");
  1020. if (c == null)
  1021. throw new HttpException ("ChangePasswordTemplate does not contain an IEditableTextControl with ID UserName for the username, this is required if DisplayUserName=true.");
  1022. return c as IEditableTextControl;
  1023. }
  1024. }
  1025. public IEditableTextControl CurrentPasswordTextBox
  1026. {
  1027. get
  1028. {
  1029. Control c = FindControl ("CurrentPassword");
  1030. if (c == null)
  1031. throw new HttpException ("ChangePasswordTemplate does not contain an IEditableTextControl with ID CurrentPassword for the current password.");
  1032. return c as IEditableTextControl;
  1033. }
  1034. }
  1035. public IEditableTextControl NewPasswordTextBox
  1036. {
  1037. get
  1038. {
  1039. Control c = FindControl ("NewPassword");
  1040. if (c == null)
  1041. throw new HttpException ("ChangePasswordTemplate does not contain an IEditableTextControl with ID NewPassword for the new password.");
  1042. return c as IEditableTextControl;
  1043. }
  1044. }
  1045. // Optional controls
  1046. public IEditableTextControl ConfirmNewPasswordTextBox
  1047. {
  1048. get { return FindControl ("ConfirmNewPassword") as IEditableTextControl; }
  1049. }
  1050. public Control CancelButton
  1051. {
  1052. get { return FindControl ("Cancel"); }
  1053. }
  1054. public Control ChangePasswordButton
  1055. {
  1056. get { return FindControl ("ChangePassword"); }
  1057. }
  1058. public ITextControl FailureTextLiteral
  1059. {
  1060. get { return FindControl ("FailureText") as ITextControl; }
  1061. }
  1062. }
  1063. sealed class ChangePasswordDeafultTemplate : ITemplate
  1064. {
  1065. readonly ChangePassword _owner = null;
  1066. internal ChangePasswordDeafultTemplate (ChangePassword cPassword)
  1067. {
  1068. _owner = cPassword;
  1069. }
  1070. TableRow CreateRow (Control c0, Control c1, Control c2, Style s0, Style s1)
  1071. {
  1072. TableRow row = new TableRow ();
  1073. TableCell cell0 = new TableCell ();
  1074. TableCell cell1 = new TableCell ();
  1075. cell0.Controls.Add (c0);
  1076. row.Controls.Add (cell0);
  1077. if ((c1 != null) && (c2 != null)) {
  1078. cell1.Controls.Add (c1);
  1079. cell1.Controls.Add (c2);
  1080. cell0.HorizontalAlign = HorizontalAlign.Right;
  1081. if (s0 != null)
  1082. cell0.ApplyStyle (s0);
  1083. if (s1 != null)
  1084. cell1.ApplyStyle (s1);
  1085. row.Controls.Add (cell1);
  1086. }
  1087. else {
  1088. cell0.ColumnSpan = 2;
  1089. cell0.HorizontalAlign = HorizontalAlign.Center;
  1090. if (s0 != null)
  1091. cell0.ApplyStyle (s0);
  1092. }
  1093. return row;
  1094. }
  1095. bool AddLink (string pageUrl, string linkText, string linkIcon, WebControl container)
  1096. {
  1097. bool added = false;
  1098. if (linkIcon.Length > 0) {
  1099. Image img = new Image ();
  1100. img.ImageUrl = linkIcon;
  1101. container.Controls.Add (img);
  1102. added = true;
  1103. }
  1104. if (linkText.Length > 0) {
  1105. HyperLink link = new HyperLink ();
  1106. link.NavigateUrl = pageUrl;
  1107. link.Text = linkText;
  1108. link.ControlStyle.CopyTextStylesFrom (container.ControlStyle);
  1109. container.Controls.Add (link);
  1110. added = true;
  1111. }
  1112. return added;
  1113. }
  1114. public void InstantiateIn (Control container)
  1115. {
  1116. Table table = new Table ();
  1117. table.CellPadding = 0;
  1118. // Row #0
  1119. table.Controls.Add (
  1120. CreateRow (new LiteralControl (_owner.ChangePasswordTitleText),
  1121. null, null, _owner.TitleTextStyle, null));
  1122. // Row #1
  1123. if (_owner.InstructionText.Length > 0) {
  1124. table.Controls.Add (
  1125. CreateRow (new LiteralControl (_owner.InstructionText),
  1126. null, null, _owner.InstructionTextStyle, null));
  1127. }
  1128. // Row #2
  1129. if (_owner.DisplayUserName) {
  1130. TextBox UserName = new TextBox ();
  1131. UserName.ID = "UserName";
  1132. UserName.Text = _owner.UserName;
  1133. UserName.ApplyStyle (_owner.TextBoxStyle);
  1134. Label UserNameLabel = new Label ();
  1135. UserNameLabel.ID = "UserNameLabel";
  1136. UserNameLabel.AssociatedControlID = "UserName";
  1137. UserNameLabel.Text = _owner.UserNameLabelText;
  1138. RequiredFieldValidator UserNameRequired = new RequiredFieldValidator ();
  1139. UserNameRequired.ID = "UserNameRequired";
  1140. UserNameRequired.ControlToValidate = "UserName";
  1141. UserNameRequired.ErrorMessage = _owner.UserNameRequiredErrorMessage;
  1142. UserNameRequired.ToolTip = _owner.UserNameRequiredErrorMessage;
  1143. UserNameRequired.Text = "*";
  1144. UserNameRequired.ValidationGroup = _owner.ID;
  1145. UserNameRequired.ApplyStyle (_owner.ValidatorTextStyle);
  1146. table.Controls.Add (CreateRow (UserNameLabel, UserName, UserNameRequired, _owner.LabelStyle, null));
  1147. }
  1148. // Row #3
  1149. TextBox CurrentPassword = new TextBox ();
  1150. CurrentPassword.ID = "CurrentPassword";
  1151. CurrentPassword.TextMode = TextBoxMode.Password;
  1152. CurrentPassword.ApplyStyle (_owner.TextBoxStyle);
  1153. Label CurrentPasswordLabel = new Label ();
  1154. CurrentPasswordLabel.ID = "CurrentPasswordLabel";
  1155. CurrentPasswordLabel.AssociatedControlID = "CurrentPasswordLabel";
  1156. CurrentPasswordLabel.Text = _owner.PasswordLabelText;
  1157. RequiredFieldValidator CurrentPasswordRequired = new RequiredFieldValidator ();
  1158. CurrentPasswordRequired.ID = "CurrentPasswordRequired";
  1159. CurrentPasswordRequired.ControlToValidate = "CurrentPassword";
  1160. CurrentPasswordRequired.ErrorMessage = _owner.PasswordRequiredErrorMessage;
  1161. CurrentPasswordRequired.ToolTip = _owner.PasswordRequiredErrorMessage;
  1162. CurrentPasswordRequired.Text = "*";
  1163. CurrentPasswordRequired.ValidationGroup = _owner.ID;
  1164. CurrentPasswordRequired.ApplyStyle (_owner.ValidatorTextStyle);
  1165. table.Controls.Add (CreateRow (CurrentPasswordLabel, CurrentPassword, CurrentPasswordRequired, _owner.LabelStyle, null));
  1166. // Row #4
  1167. TextBox NewPassword = new TextBox ();
  1168. NewPassword.ID = "NewPassword";
  1169. NewPassword.TextMode = TextBoxMode.Password;
  1170. NewPassword.ApplyStyle (_owner.TextBoxStyle);
  1171. Label NewPasswordLabel = new Label ();
  1172. NewPasswordLabel.ID = "NewPasswordLabel";
  1173. NewPasswordLabel.AssociatedControlID = "NewPassword";
  1174. NewPasswordLabel.Text = _owner.NewPasswordLabelText;
  1175. RequiredFieldValidator NewPasswordRequired = new RequiredFieldValidator ();
  1176. NewPasswordRequired.ID = "NewPasswordRequired";
  1177. NewPasswordRequired.ControlToValidate = "NewPassword";
  1178. NewPasswordRequired.ErrorMessage = _owner.PasswordRequiredErrorMessage;
  1179. NewPasswordRequired.ToolTip = _owner.PasswordRequiredErrorMessage;
  1180. NewPasswordRequired.Text = "*";
  1181. NewPasswordRequired.ValidationGroup = _owner.ID;
  1182. NewPasswordRequired.ApplyStyle (_owner.ValidatorTextStyle);
  1183. table.Controls.Add (CreateRow (NewPasswordLabel, NewPassword, NewPasswordRequired, _owner.LabelStyle, null));
  1184. // Row #5
  1185. if (_owner.PasswordHintText.Length > 0) {
  1186. table.Controls.Add (
  1187. CreateRow (new LiteralControl (""),
  1188. new LiteralControl (_owner.PasswordHintText),
  1189. new LiteralControl (""),
  1190. null, _owner.PasswordHintStyle));
  1191. }
  1192. // Row #6
  1193. TextBox ConfirmNewPassword = new TextBox ();
  1194. ConfirmNewPassword.ID = "ConfirmNewPassword";
  1195. ConfirmNewPassword.TextMode = TextBoxMode.Password;
  1196. ConfirmNewPassword.ApplyStyle (_owner.TextBoxStyle);
  1197. Label ConfirmNewPasswordLabel = new Label ();
  1198. ConfirmNewPasswordLabel.ID = "ConfirmNewPasswordLabel";
  1199. ConfirmNewPasswordLabel.AssociatedControlID = "ConfirmNewPasswordLabel";
  1200. ConfirmNewPasswordLabel.Text = _owner.ConfirmNewPasswordLabelText;
  1201. RequiredFieldValidator ConfirmNewPasswordRequired = new RequiredFieldValidator ();
  1202. ConfirmNewPasswordRequired.ID = "ConfirmNewPasswordRequired";
  1203. ConfirmNewPasswordRequired.ControlToValidate = "ConfirmNewPassword";
  1204. ConfirmNewPasswordRequired.ErrorMessage = _owner.PasswordRequiredErrorMessage;
  1205. ConfirmNewPasswordRequired.ToolTip = _owner.PasswordRequiredErrorMessage;
  1206. ConfirmNewPasswordRequired.Text = "*";
  1207. ConfirmNewPasswordRequired.ValidationGroup = _owner.ID;
  1208. ConfirmNewPasswordRequired.ApplyStyle (_owner.ValidatorTextStyle);
  1209. table.Controls.Add (CreateRow (ConfirmNewPasswordLabel, ConfirmNewPassword, ConfirmNewPasswordRequired, _owner.LabelStyle, null));
  1210. // Row #7
  1211. CompareValidator NewPasswordCompare = new CompareValidator ();
  1212. NewPasswordCompare.ID = "NewPasswordCompare";
  1213. NewPasswordCompare.ControlToCompare = "NewPassword";
  1214. NewPasswordCompare.ControlToValidate = "ConfirmNewPassword";
  1215. NewPasswordCompare.Display = ValidatorDisplay.Dynamic;
  1216. NewPasswordCompare.ErrorMessage = _owner.ConfirmPasswordCompareErrorMessage;
  1217. NewPasswordCompare.ValidationGroup = _owner.ID;
  1218. table.Controls.Add (CreateRow (NewPasswordCompare, null, null, null, null));
  1219. // Row #8
  1220. Literal FailureTextLiteral = new Literal ();
  1221. FailureTextLiteral.ID = "FailureText";
  1222. FailureTextLiteral.EnableViewState = false;
  1223. if (_owner.FailureTextStyle.ForeColor.IsEmpty)
  1224. _owner.FailureTextStyle.ForeColor = System.Drawing.Color.Red;
  1225. table.Controls.Add (CreateRow (FailureTextLiteral, null, null, _owner.FailureTextStyle, null));
  1226. // Row #9
  1227. WebControl ChangePasswordButton = null;
  1228. switch (_owner.ChangePasswordButtonType) {
  1229. case ButtonType.Button:
  1230. ChangePasswordButton = new Button ();
  1231. break;
  1232. case ButtonType.Image:
  1233. ChangePasswordButton = new ImageButton ();
  1234. break;
  1235. case ButtonType.Link:
  1236. ChangePasswordButton = new LinkButton ();
  1237. break;
  1238. }
  1239. ChangePasswordButton.ID = "ChangePasswordPushButton";
  1240. ChangePasswordButton.ApplyStyle (_owner.ChangePasswordButtonStyle);
  1241. ((IButtonControl) ChangePasswordButton).CommandName = ChangePassword.ChangePasswordButtonCommandName;
  1242. ((IButtonControl) ChangePasswordButton).Text = _owner.ChangePasswordButtonText;
  1243. ((IButtonControl) ChangePasswordButton).ValidationGroup = _owner.ID;
  1244. WebControl CancelButton = null;
  1245. switch (_owner.CancelButtonType) {
  1246. case ButtonType.Button:
  1247. CancelButton = new Button ();
  1248. break;
  1249. case ButtonType.Image:
  1250. CancelButton = new ImageButton ();
  1251. break;
  1252. case ButtonType.Link:
  1253. CancelButton = new LinkButton ();
  1254. break;
  1255. }
  1256. CancelButton.ID = "CancelPushButton";
  1257. CancelButton.ApplyStyle (_owner.CancelButtonStyle);
  1258. ((IButtonControl) CancelButton).CommandName = ChangePassword.CancelButtonCommandName;
  1259. ((IButtonControl) CancelButton).Text = _owner.CancelButtonText;
  1260. ((IButtonControl) CancelButton).CausesValidation = false;
  1261. table.Controls.Add (CreateRow (ChangePasswordButton, CancelButton, new LiteralControl (""), null, null));
  1262. // Row #10
  1263. TableRow linksRow = new TableRow ();
  1264. TableCell linksCell = new TableCell ();
  1265. linksCell.ColumnSpan = 2;
  1266. linksCell.ControlStyle.CopyFrom (_owner.HyperLinkStyle);
  1267. linksRow.Cells.Add (linksCell);
  1268. if (AddLink (_owner.HelpPageUrl, _owner.HelpPageText, _owner.HelpPageIconUrl, linksCell))
  1269. linksCell.Controls.Add (new LiteralControl ("<br/>"));
  1270. if (AddLink (_owner.CreateUserUrl, _owner.CreateUserText, _owner.CreateUserIconUrl, linksCell))
  1271. linksCell.Controls.Add (new LiteralControl ("<br/>"));
  1272. if (AddLink (_owner.PasswordRecoveryUrl, _owner.PasswordRecoveryText, _owner.PasswordRecoveryIconUrl, linksCell))
  1273. linksCell.Controls.Add (new LiteralControl ("<br/>"));
  1274. AddLink (_owner.EditProfileUrl, _owner.EditProfileText, _owner.EditProfileIconUrl, linksCell);
  1275. table.Controls.Add (linksRow);
  1276. container.Controls.Add (table);
  1277. }
  1278. }
  1279. sealed class SuccessDefaultTemplate : ITemplate
  1280. {
  1281. readonly ChangePassword _cPassword = null;
  1282. internal SuccessDefaultTemplate (ChangePassword cPassword)
  1283. {
  1284. _cPassword = cPassword;
  1285. }
  1286. TableRow CreateRow (Control c0, Style s0, HorizontalAlign align)
  1287. {
  1288. TableRow row = new TableRow ();
  1289. TableCell cell0 = new TableCell ();
  1290. cell0.Controls.Add (c0);
  1291. cell0.HorizontalAlign = align;
  1292. if (s0 != null)
  1293. cell0.ApplyStyle (s0);
  1294. row.Controls.Add (cell0);
  1295. return row;
  1296. }
  1297. public void InstantiateIn (Control container)
  1298. {
  1299. Table table = new Table ();
  1300. table.ControlStyle.Width = Unit.Percentage (100);
  1301. table.ControlStyle.Height = Unit.Percentage (100);
  1302. // Row #0
  1303. table.Controls.Add (
  1304. CreateRow (new LiteralControl (_cPassword.SuccessTitleText), _cPassword.TitleTextStyle, HorizontalAlign.Center));
  1305. // Row #1
  1306. table.Controls.Add (
  1307. CreateRow (new LiteralControl (_cPassword.SuccessText), _cPassword.SuccessTextStyle, HorizontalAlign.Center));
  1308. // Row #3
  1309. WebControl ContinueButton = null;
  1310. switch (_cPassword.ChangePasswordButtonType) {
  1311. case ButtonType.Button:
  1312. ContinueButton = new Button ();
  1313. break;
  1314. case ButtonType.Image:
  1315. ContinueButton = new ImageButton ();
  1316. break;
  1317. case ButtonType.Link:
  1318. ContinueButton = new LinkButton ();
  1319. break;
  1320. }
  1321. ContinueButton.ID = "ContinueButton";
  1322. ContinueButton.ApplyStyle (_cPassword.ContinueButtonStyle);
  1323. ((IButtonControl) ContinueButton).CommandName = ChangePassword.ContinueButtonCommandName;
  1324. ((IButtonControl) ContinueButton).Text = _cPassword.ContinueButtonText;
  1325. ((IButtonControl) ContinueButton).CausesValidation = false;
  1326. table.Controls.Add (
  1327. CreateRow (ContinueButton, null, HorizontalAlign.Right));
  1328. container.Controls.Add (table);
  1329. }
  1330. }
  1331. sealed class SuccessContainer : BaseChangePasswordContainer
  1332. {
  1333. public SuccessContainer (ChangePassword owner) : base (owner)
  1334. {
  1335. ID = "SuccessContainerID";
  1336. }
  1337. public Control ChangePasswordButton
  1338. {
  1339. get { return FindControl ("Continue"); }
  1340. }
  1341. }
  1342. }
  1343. }
  1344. #endif