Advertisement
roga122

Untitled

Jan 24th, 2022
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  1. <?php
  2. include_once "$_SERVER[DOCUMENT_ROOT]/core/loader.php";
  3.  
  4. $router->get('/', function () use ($user) {
  5.   if ($user) {
  6.     echo 'index page<pre>';
  7.     print_r($user);
  8.   } else  {
  9.     header("Location: /auth");
  10.   }
  11. });
  12.  
  13. $router->mount('/reports', function () use ($router) {
  14.   $router->get('/', function () {
  15.     echo 'reports overview';
  16.   });
  17.   $router->get('/{id}', function ($id) {
  18.     echo 'report id ' . htmlentities($id);
  19.   });
  20.   $router->post('/new', function () {
  21.     echo 'add report';
  22.     print_r($_POST);
  23.   });
  24. });
  25.  
  26.  
  27. $router->mount('/auth', function () use ($router,$url,$fsite_google,$auth,$user) {
  28.   $router->get('/', function () use ($url, $fsite_google,$user) {
  29.     $title = 'Авторизация';
  30.     if ($user) {
  31.       echo "Вы уже авторизованы";
  32.     } else {
  33.       include_once "$_SERVER[DOCUMENT_ROOT]/style/auth_form.tpl";
  34.       $_SESSION['error_auth'] = '';
  35.     }
  36.   });
  37.   $router->post('/', function () use ($auth) {
  38.     if ($auth->check($_POST, $_SERVER['REMOTE_ADDR'])) {
  39.       header("Location: /");
  40.     } else {
  41.       $_SESSION['error_auth'] = 'Не правильный пароль';
  42.       header("Location: /auth");
  43.     }
  44.   });
  45.   $router->get('/logout', function () {
  46.     session_unset();
  47.     header("Location: /");
  48.   });
  49. });
  50.  
  51. $router->run();
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement