123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- Lib::loadClass('RouteToolBase');
- Lib::loadClass('UI');
- Lib::loadClass('Response');
- Lib::loadClass('Theme');
- require_once dirname(__FILE__) . '/../auth.php'; // Theme_Auth_panel_biall_net
- // class name must have the same name as file
- // index.php?_route=UrlAction_RemindPasswd - uruchamia defaultAction
- class RouteTool_RemindPasswd extends RouteToolBase {
- function handleAuth() {
- // return (!User::logged())
- // ? $this->remindPasswdAction()
- // : $this->sendAlreadyLoggedIn()
- // ;
- $task = V::get('_task', '', $_GET);
- switch ($task) {
- case 'rp': return $this->rpAction();
- default: return $this->remindPasswdAction();
- }
- }
- function remindPasswdAction() {
- if ('remind' == V::get('_postTask', '', $_POST)) {
- try {
- $email = V::get('ADM_ACCOUNT', '', $_POST);
- $this->remindPasswd($email);
- } catch (Exception $e) {
- $this->sendRemindPasswdForm([ 'errors' => [ $e->getMessage() ] ]);
- }
- return $this->sendRemindPasswdSent();
- }
- $this->sendRemindPasswdForm();
- exit;
- }
- function remindPasswd($email) {
- if (empty($email)) throw new Exception("Proszę podać adres email");
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) throw new Exception("Proszę podać poprawny adres email");
- // BŁĄD: Brak zarejestrowanego użytkownika o wprowadzonym adresie email.
- Theme_Auth_panel_biall_net::fetchUser($email);
- $remindKey = Theme_Auth_panel_biall_net::generateRemindKey($email);
- $resetLink = $this->getLink('rp', [ 'login' => $email, 'key' => $remindKey ]);
- Theme_Auth_panel_biall_net::sendRemindPasswd($email, $resetLink);
- }
- function rpAction() {
- if ('set' == V::get('_postTask', '', $_POST)) {
- try {
- $email = V::get('ADM_ACCOUNT', '', $_POST);
- $remindKey = V::get('REMIND_KEY', '', $_POST);
- $newPasswd = V::get('ADM_PASSWD', '', $_POST);
- Theme_Auth_panel_biall_net::setPasswd($email, $newPasswd, $remindKey);
- } catch (Exception $e) {
- $this->sendNewPasswdForm(array_merge($_GET, [ 'errors' => [ $e->getMessage() ] ]));
- }
- return $this->sendRemindPasswdSet();
- }
- $this->sendNewPasswdForm($_GET);
- exit;
- }
- function sendNewPasswdForm($args = []) {
- UI::gora();
- UI::tryCatchView([ $this, 'setNewPassForm' ], [ 'args' => $args ]);
- UI::dol();
- exit;
- }
- function sendRemindPasswdSet() {
- UI::gora();
- Theme::remindNewPasswordSet($data = [ 'msg' => "Twoje nowe hasło zostało zapisane." ]);
- UI::dol();
- exit;
- }
- function setNewPassForm($args) {
- $login = V::get('login', '', $args);
- $remindKey = V::get('key', '', $args);
- if (empty($login)) throw new Exception("Missing login!");
- if (empty($remindKey)) throw new Exception("Missing key!");
- Theme::remindSetNewPassword($args);
- }
- function sendRemindPasswdForm($data = []) {
- UI::gora();
- Theme::remind($data);
- UI::dol();
- exit;
- }
- function sendRemindPasswdSent() {
- UI::gora();
- Theme::remindSent($data = []);
- UI::dol();
- exit;
- }
- function sendAlreadyLoggedIn() {
- UI::gora();
- // Theme::top();
- echo UI::h('h1', [], "TODO: Already logged in");
- UI::dol();
- exit;
- }
- function defaultAction() {
- UI::gora();
- // Theme::top();
- echo '<h1>ReminPasswd Tool</h1>';
- // UI::inlineJS(__FILE__ . '.example.js', [
- // 'URL_TEST_AJAX_ACTION' => $this->getLink('testAjax'),
- // ]);
- UI::dol();
- }
- // function testAjaxAction() {
- // Response::sendTryCatchJson(array($this, 'testAjax'), $_REQUEST); // args from request
- // // Response::sendTryCatchJson(array($this, 'testAjax'), $args = 'JSON_FROM_REQUEST_BODY'); // args from json request
- // }
- // function testAjax($args) { // args given by sendTryCatchJson
- // $items = [
- // [ 'ID' => 1, 'name' => 'x', 'desc' => 'a' ],
- // [ 'ID' => 2, 'name' => 'y', 'desc' => 'b' ],
- // [ 'ID' => 3, 'name' => 'z', 'desc' => 'c' ],
- // ];
- // return [
- // 'type' => 'success',
- // 'msg' => 'OK',
- // 'body' => [
- // 'items' => $items,
- // ]
- // ];
- // }
- }
|