PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/site/cms/modules/base/ChangePassword.hx

http://poko.googlecode.com/
Haxe | 112 lines | 69 code | 17 blank | 26 comment | 6 complexity | 2a716587106b2090c276bdcc9e389776 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. /*
  2. * Copyright (c) 2008, TouchMyPixel & contributors
  3. * Original author : Tarwin Stroh-Spijer <tarwin@touchmypixel.com>
  4. * Contributors: Tony Polinelli
  5. * All rights reserved.
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * - Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * - Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE TOUCH MY PIXEL & CONTRIBUTERS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE TOUCH MY PIXEL & CONTRIBUTORS
  19. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  25. * THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. package site.cms.modules.base;
  28. import poko.form.elements.Button;
  29. import poko.form.elements.CheckboxGroup;
  30. import poko.form.elements.Hidden;
  31. import poko.form.elements.Input;
  32. import poko.form.elements.RadioGroup;
  33. import poko.form.Form;
  34. import poko.utils.Tools;
  35. import haxe.Md5;
  36. import php.Web;
  37. import site.cms.modules.base.Users;
  38. import site.cms.templates.CmsTemplate;
  39. class ChangePassword extends CmsTemplate
  40. {
  41. public var userData:List<Dynamic>;
  42. public var action:String;
  43. public var form1:Form;
  44. public var heading:String;
  45. public function new()
  46. {
  47. super();
  48. }
  49. override public function main():Void
  50. {
  51. super.main();
  52. action = app.params.get("form1_action");
  53. heading = "Change Password";
  54. setupForm1();
  55. if (form1.isSubmitted() && form1.isValid())
  56. process();
  57. navigation.setSelected("Password");
  58. }
  59. private function process():Void
  60. {
  61. switch(action)
  62. {
  63. case "change":
  64. var d:Dynamic = form1.getData();
  65. var oldPassword = app.db.requestSingle("SELECT password FROM _users WHERE id='" + user.id + "'").password;
  66. if (Md5.encode(d.passwordOld) == oldPassword) {
  67. if (d.passwordNew1 == d.passwordNew2) {
  68. app.db.update("_users", { password: Md5.encode(d.passwordNew1) }, "id='" + user.id + "'");
  69. messages.addMessage("Password updated.");
  70. form1.clearData();
  71. }else {
  72. messages.addError("You did not enter the new password the same twice. Please try again.");
  73. }
  74. }else {
  75. messages.addError("Your old password was not correct.");
  76. }
  77. }
  78. }
  79. private function setupForm1():Void
  80. {
  81. form1 = new Form("form1");
  82. var pass1 = new Input("passwordOld", "Old Password", null, true);
  83. pass1.password = true;
  84. form1.addElement(pass1);
  85. var pass2 = new Input("passwordNew1", "New Password", null, true);
  86. pass2.password = true;
  87. form1.addElement(pass2);
  88. var pass3 = new Input("passwordNew2", "New Password (Again)", null, true);
  89. pass3.password = true;
  90. form1.addElement(pass3);
  91. form1.addElement(new Hidden("action", "change"));
  92. form1.addElement(new Button("submit", "Update", "Update"));
  93. form1.populateElements();
  94. }
  95. }