diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-07-09 19:40:17 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-07-09 19:40:17 +0300 |
commit | f7bfdf58def6aadc922e1632f407d1418269a0d7 (patch) | |
tree | d7a0b2819e6a26c11d40ee0b27267ea827fbb345 /handler/admin/Login.php |
initial
Diffstat (limited to 'handler/admin/Login.php')
-rw-r--r-- | handler/admin/Login.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/handler/admin/Login.php b/handler/admin/Login.php new file mode 100644 index 0000000..cade137 --- /dev/null +++ b/handler/admin/Login.php @@ -0,0 +1,31 @@ +<?php + +namespace handler\admin; + +use admin; +use csrf; +use RedirectResponse; +use Response; +use UnauthorizedException; + +class Login extends AdminRequestHandler { + + public function get(): Response { + if (admin::isAdmin()) + return new RedirectResponse('/admin/'); + return $this->skin->renderPage('admin/login'); + } + + public function post(): Response { + csrf::check('adminlogin'); + $password = $_POST['password'] ?? ''; + $valid = admin::checkPassword($password); + if ($valid) { + admin::logAuth(); + admin::setCookie(); + return new RedirectResponse('/admin/'); + } + throw new UnauthorizedException('nice try'); + } + +}
\ No newline at end of file |