RemindPasswd.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. $item = Theme_Auth_panel_biall_net::fetchUser($email);
  39. $remindKey = Theme_Auth_panel_biall_net::generateRemindKey($email);
  40. {
  41. $resetLink = $this->getLink('rp', [ 'login' => $email, 'key' => $remindKey ]);
  42. $recipient = "piotrl86+bn-test-remind@gmail.com"; // TODO: $email
  43. $headers = "MIME-Version: 1.0\n";
  44. $headers .= "Content-Type: text/plain; charset=\"utf-8\"\n";
  45. //$headers .= 'Bcc: pawel.ratajczak@biall.com.pl' . "\r\n";
  46. $headers .= 'From: Panel klienta BIALL-NET <noreply@biall-net.pl>' . "\r\n";
  47. $headers .= 'Bcc: piotrl86@gmail.com' . "\r\n";
  48. $subject = "Panel BIALL-NET: Ustawianie nowego hasła";
  49. $body = implode("\r\n\r\n", [
  50. "Ktoś poprosił o wygenerowanie nowego hasła dla następującego konta:",
  51. "Nazwa witryny: Panel klienta BIALL-NET",
  52. "Nazwa użytkownika: {$email}",
  53. "Jeśli to pomyłka po prostu zignoruj tego maila i nic się nie stanie.",
  54. "Aby zresetować hasło, przejdź tutaj:",
  55. "{$resetLink}",
  56. ]);
  57. mail($recipient, $subject, $body, $headers);
  58. }
  59. }
  60. function rpAction() {
  61. if ('set' == V::get('_postTask', '', $_POST)) {
  62. try {
  63. $email = V::get('ADM_ACCOUNT', '', $_POST);
  64. $remindKey = V::get('REMIND_KEY', '', $_POST);
  65. $newPasswd = V::get('ADM_PASSWD', '', $_POST);
  66. Theme_Auth_panel_biall_net::setPasswd($email, $newPasswd, $remindKey);
  67. } catch (Exception $e) {
  68. $this->sendNewPasswdForm(array_merge($_GET, [ 'errors' => [ $e->getMessage() ] ]));
  69. }
  70. return $this->sendRemindPasswdSet();
  71. }
  72. $this->sendNewPasswdForm($_GET);
  73. exit;
  74. }
  75. function sendNewPasswdForm($args = []) {
  76. UI::gora();
  77. UI::tryCatchView([ $this, 'setNewPassForm' ], [ 'args' => $args ]);
  78. UI::dol();
  79. exit;
  80. }
  81. function sendRemindPasswdSet() {
  82. UI::gora();
  83. Theme::remindNewPasswordSet($data = [ 'msg' => "Twoje nowe hasło zostało zapisane." ]);
  84. UI::dol();
  85. exit;
  86. }
  87. function setNewPassForm($args) {
  88. $login = V::get('login', '', $args);
  89. $remindKey = V::get('key', '', $args);
  90. if (empty($login)) throw new Exception("Missing login!");
  91. if (empty($remindKey)) throw new Exception("Missing key!");
  92. Theme::remindSetNewPassword($args);
  93. }
  94. function sendRemindPasswdForm($data = []) {
  95. UI::gora();
  96. Theme::remind($data);
  97. UI::dol();
  98. exit;
  99. }
  100. function sendRemindPasswdSent() {
  101. UI::gora();
  102. Theme::remindSent($data = []);
  103. UI::dol();
  104. exit;
  105. }
  106. function sendAlreadyLoggedIn() {
  107. UI::gora();
  108. // Theme::top();
  109. echo UI::h('h1', [], "TODO: Already logged in");
  110. UI::dol();
  111. exit;
  112. }
  113. function defaultAction() {
  114. UI::gora();
  115. Theme::top();
  116. echo '<h1>ReminPasswd Tool</h1>';
  117. // UI::inlineJS(__FILE__ . '.example.js', [
  118. // 'URL_TEST_AJAX_ACTION' => $this->getLink('testAjax'),
  119. // ]);
  120. UI::dol();
  121. }
  122. // function testAjaxAction() {
  123. // Response::sendTryCatchJson(array($this, 'testAjax'), $_REQUEST); // args from request
  124. // // Response::sendTryCatchJson(array($this, 'testAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // args from json request
  125. // }
  126. // function testAjax($args) { // args given by sendTryCatchJson
  127. // $items = [
  128. // [ 'ID' => 1, 'name' => 'x', 'desc' => 'a' ],
  129. // [ 'ID' => 2, 'name' => 'y', 'desc' => 'b' ],
  130. // [ 'ID' => 3, 'name' => 'z', 'desc' => 'c' ],
  131. // ];
  132. // return [
  133. // 'type' => 'success',
  134. // 'msg' => 'OK',
  135. // 'body' => [
  136. // 'items' => $items,
  137. // ]
  138. // ];
  139. // }
  140. }