diff options
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 |