public function actionAuthentication() { if (!empty($_POST['username']) && !empty($_POST['password'])) { try { $condition = []; $condition['username'] = $_POST['username']; $condition['password'] = $_POST['password']; $condition['status'] = 1; $user = User::findByCondition($condition)[0]; Application::setCurrentByKey(['username' => $user->getUsername(), 'role' => $user->getUserRole()]); $logger = new Logger(); $logger->info('SUCCESSFUL LOGIN', ['code' => 100, 'info' => $condition]); setcookie('lastuser', $user->getUserName(), time() + 86400, '/'); setcookie('lastdate', time(), time() + 86400, '/'); header('Location: /'); } catch (E404Exception $e) { Application::catchException($e); } } else { $logger = new Logger(); $logger->notice('empty field exists!', ['code' => 101, 'info' => $_POST]); $_SESSION['notice'] = 'empty field exists!'; header('Location: /auth/login'); } }
public function __construct() { if (static::class == 'App\\Controllers\\Edit' && Application::getCurrentByKey('role') != 'supervisor' || static::class == 'App\\Controllers\\Admin' && Application::getCurrentByKey('role') != 'admin') { throw new E403Exception(['class' => static::class, 'role' => Application::getCurrentByKey('role')]); } $this->view = new View(); }
public function actionEditing() { if (Application::getCurrentByKey('pageid')) { $condWhere['id'] = Application::getCurrentByKey('pageid'); if ('operator' == Application::getCurrentByKey('role')) { $condWhere['author'] = Application::getCurrentByKey('username'); } $this->view->items = Stuff::findByCondition($condWhere)[0]; } $this->view->display($this->path . 'editing.php'); }
public function logToJson($level, $message, $context) { $fileName = __DIR__ . '/../logs/' . date('ymdHis', time()); Application::createFile($fileName); $obj = new \stdClass(); $obj->date = date('d.m.y H:i:s', time()); $obj->level = $level; $obj->message = $message; $obj->context = $context; $json = json_encode($obj); file_put_contents($fileName, $json); }
public function actionLog() { $dateBegin = !empty($_POST['dateBegin']) ? $_POST['dateBegin'] : date('Y-m-d', time()) . 'T00:00'; $dateEnd = !empty($_POST['dateEnd']) ? $_POST['dateEnd'] : date('Y-m-d\\TH:i', time()); echo $dateBegin . '<br>'; echo $dateEnd . '<br>'; $timestampBegin = Application::createTimestampFronInputDatelocal($dateBegin); $timestampEnd = Application::createTimestampFronInputDatelocal($dateEnd); $this->view->logBegin = date('ymdHis', $timestampBegin); $this->view->logEnd = date('ymdHis', $timestampEnd); $this->view->display($this->path . 'log_show.php'); }
public function actionSpecific() { if (Application::getCurrentByKey('pageid')) { $condWhere['id'] = Application::getCurrentByKey('pageid'); if ('operator' == Application::getCurrentByKey('role')) { $condWhere['author'] = Application::getCurrentByKey('username'); } $this->view->items = Stuff::findByCondition($condWhere)[0]; $this->view->display($this->path . 'specific.php'); } else { header('Location: /'); } }
<!------ ДЗ выполнено на кнопке класса .inset, вместо кнопок другого цвета - форма выбора цвета кнопок formColor -------------> <head lang="en"> <meta charset="UTF-8"> <link type="text/css" rel="stylesheet" href="/style.css"/> <?php $rgb = isset($_GET['color']) ? $_GET['color'] : '#ff0000'; $r = \App\Classes\Application::getR($rgb); $g = \App\Classes\Application::getG($rgb); $b = \App\Classes\Application::getB($rgb); $h = \App\Classes\Application::getH($rgb); $s = \App\Classes\Application::getS($rgb); $l = \App\Classes\Application::getL($rgb); $hNeon = \App\Classes\Application::getH('#0f192a'); $sNeon = \App\Classes\Application::getS('#0f192a'); $lNeon = \App\Classes\Application::getL('#0f192a'); ?> <style> a { color: inherit; text-decoration: none; } .clearfix:before, .clearfix:after { content: ""; display: table; } .clearfix:after { clear: both; }
<title>Main page</title> <link type="text/css" rel="stylesheet" href="/style.css"/> </head> <body> <div id="wrapper"> <a href="/show/blog/">to blog</a><br> <a href="/show/polaroid/">to polaroid</a><br> <div class="form"> <form action="/show/specific/" method="post" enctype="multipart/form-data" name="uploadform"> <span> search by id: </span> <input type="search" id="search" name="id" value=""><input type="submit"> </form> <br><a href="/auth/exit/">exit</a><br> <?php if ('admin' == \App\Classes\Application::getCurrentByKey('role')) { ?> <br><a href="/admin/log_request/">Просмотр логов</a><br> <?php } ?> <h1>Страница новостей</h1> <a href="/edit/editing/">Добавить новость</a> <br><br> <ul> <?php foreach ($items as $item) { ?> <li> <a href="/show/specific/<?php echo $item->getStuffId();
$action = 'login'; } else { switch (true) { case !empty($urlParts): Application::setCurrentByKey(['pageid' => array_shift($urlParts)]); break; case !empty($_POST['id']): Application::setCurrentByKey(['pageid' => $_POST['id']]); break; case empty($control): Application::unsetCurrentByKey('pageid'); break; default: break; } } /************** call Controller's Method ******************************/ $ctrl = $control ?: 'show'; $ctrlClassName = 'App\\Controllers\\' . ucfirst($ctrl); $act = $action ?: 'all'; $method = 'action' . ucfirst($act); try { $controller = new $ctrlClassName(); $controller->{$method}(); } catch (E403Exception $e) { Application::catchException($e); } catch (E404Exception $e) { Application::catchException($e); } catch (E405Exception $e) { Application::catchException($e); }
<?php use App\Classes\Application; ?> <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>Main page</title> <link type="text/css" rel="stylesheet" href="/style.css"/> </head> <body> <div id="wrapper"> <div id="log"> <p><?php Application::fetchLogByTerm($logBegin, $logEnd); ?> </p> <br><br> <a href="/">на главную</a> <br><br> <a href="/admin/log_request/">Просмотр логов</a> <br><br> <copyright></copyright> </div> </div> </body> </html>