RemindPasswd.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. Lib::loadClass('RouteToolBase');
  3. Lib::loadClass('UI');
  4. Lib::loadClass('Response');
  5. Lib::loadClass('Theme');
  6. require_once dirname(__FILE__) . '/../auth.php'; // Theme_Auth_panel_biall_net
  7. // class name must have the same name as file
  8. // index.php?_route=UrlAction_RemindPasswd - uruchamia defaultAction
  9. class RouteTool_RemindPasswd extends RouteToolBase {
  10. function handleAuth() {
  11. // return (!User::logged())
  12. // ? $this->remindPasswdAction()
  13. // : $this->sendAlreadyLoggedIn()
  14. // ;
  15. $task = V::get('_task', '', $_GET);
  16. switch ($task) {
  17. case 'rp': return $this->rpAction();
  18. default: return $this->remindPasswdAction();
  19. }
  20. }
  21. function remindPasswdAction() {
  22. if ('remind' == V::get('_postTask', '', $_POST)) {
  23. try {
  24. $email = V::get('ADM_ACCOUNT', '', $_POST);
  25. $this->remindPasswd($email);
  26. } catch (Exception $e) {
  27. $this->sendRemindPasswdForm([ 'errors' => [ $e->getMessage() ] ]);
  28. }
  29. return $this->sendRemindPasswdSent();
  30. }
  31. $this->sendRemindPasswdForm();
  32. exit;
  33. }
  34. function remindPasswd($email) {
  35. if (empty($email)) throw new Exception("Proszę podać adres email");
  36. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) throw new Exception("Proszę podać poprawny adres email");
  37. // BŁĄD: Brak zarejestrowanego użytkownika o wprowadzonym adresie email.
  38. Theme_Auth_panel_biall_net::fetchUser($email);
  39. $remindKey = Theme_Auth_panel_biall_net::generateRemindKey($email);
  40. $resetLink = $this->getLink('rp', [ 'login' => $email, 'key' => $remindKey ]);
  41. Theme_Auth_panel_biall_net::sendRemindPasswd($email, $resetLink);
  42. }
  43. function rpAction() {
  44. if ('set' == V::get('_postTask', '', $_POST)) {
  45. try {
  46. $email = V::get('ADM_ACCOUNT', '', $_POST);
  47. $remindKey = V::get('REMIND_KEY', '', $_POST);
  48. $newPasswd = V::get('ADM_PASSWD', '', $_POST);
  49. Theme_Auth_panel_biall_net::setPasswd($email, $newPasswd, $remindKey);
  50. } catch (Exception $e) {
  51. $this->sendNewPasswdForm(array_merge($_GET, [ 'errors' => [ $e->getMessage() ] ]));
  52. }
  53. return $this->sendRemindPasswdSet();
  54. }
  55. $this->sendNewPasswdForm($_GET);
  56. exit;
  57. }
  58. function sendNewPasswdForm($args = []) {
  59. UI::gora();
  60. UI::tryCatchView([ $this, 'setNewPassForm' ], [ 'args' => $args ]);
  61. UI::dol();
  62. exit;
  63. }
  64. function sendRemindPasswdSet() {
  65. UI::gora();
  66. Theme::remindNewPasswordSet($data = [ 'msg' => "Twoje nowe hasło zostało zapisane." ]);
  67. UI::dol();
  68. exit;
  69. }
  70. function setNewPassForm($args) {
  71. $login = V::get('login', '', $args);
  72. $remindKey = V::get('key', '', $args);
  73. if (empty($login)) throw new Exception("Missing login!");
  74. if (empty($remindKey)) throw new Exception("Missing key!");
  75. Theme::remindSetNewPassword($args);
  76. }
  77. function sendRemindPasswdForm($data = []) {
  78. UI::gora();
  79. Theme::remind($data);
  80. UI::dol();
  81. exit;
  82. }
  83. function sendRemindPasswdSent() {
  84. UI::gora();
  85. Theme::remindSent($data = []);
  86. UI::dol();
  87. exit;
  88. }
  89. function sendAlreadyLoggedIn() {
  90. UI::gora();
  91. // Theme::top();
  92. echo UI::h('h1', [], "TODO: Already logged in");
  93. UI::dol();
  94. exit;
  95. }
  96. function defaultAction() {
  97. UI::gora();
  98. // Theme::top();
  99. echo '<h1>ReminPasswd Tool</h1>';
  100. // UI::inlineJS(__FILE__ . '.example.js', [
  101. // 'URL_TEST_AJAX_ACTION' => $this->getLink('testAjax'),
  102. // ]);
  103. UI::dol();
  104. }
  105. // function testAjaxAction() {
  106. // Response::sendTryCatchJson(array($this, 'testAjax'), $_REQUEST); // args from request
  107. // // Response::sendTryCatchJson(array($this, 'testAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // args from json request
  108. // }
  109. // function testAjax($args) { // args given by sendTryCatchJson
  110. // $items = [
  111. // [ 'ID' => 1, 'name' => 'x', 'desc' => 'a' ],
  112. // [ 'ID' => 2, 'name' => 'y', 'desc' => 'b' ],
  113. // [ 'ID' => 3, 'name' => 'z', 'desc' => 'c' ],
  114. // ];
  115. // return [
  116. // 'type' => 'success',
  117. // 'msg' => 'OK',
  118. // 'body' => [
  119. // 'items' => $items,
  120. // ]
  121. // ];
  122. // }
  123. }