summaryrefslogtreecommitdiff
path: root/localwebsite/handlers/AuthHandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'localwebsite/handlers/AuthHandler.php')
-rw-r--r--localwebsite/handlers/AuthHandler.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/localwebsite/handlers/AuthHandler.php b/localwebsite/handlers/AuthHandler.php
new file mode 100644
index 0000000..971f850
--- /dev/null
+++ b/localwebsite/handlers/AuthHandler.php
@@ -0,0 +1,36 @@
+<?php
+
+class AuthHandler extends RequestHandler {
+
+ protected function before_dispatch(string $method, string $act) {
+ return null;
+ }
+
+ public function GET_auth() {
+ list($error) = $this->input('error');
+ $this->tpl->set(['error' => $error]);
+ $this->tpl->set_title('Авторизация');
+ $this->tpl->render_page('auth.twig');
+ }
+
+ public function POST_auth() {
+ list($username, $password) = $this->input('username, password');
+
+ $result = users::validatePassword($username, $password);
+ if (!$result) {
+ debugError('invalid login attempt: '.$_SERVER['REMOTE_ADDR'].', '.$_SERVER['HTTP_USER_AGENT'].", username=$username, password=$password");
+ redirect('/auth/?error='.urlencode('неверный логин или пароль'));
+ }
+
+ auth::setToken(pwhash($password));
+ redirect('/');
+ }
+
+ public function GET_deauth() {
+ if (auth::id())
+ auth::logout();
+
+ redirect('/');
+ }
+
+}