blob: 971f8506c51b33413d7e05e5edb4f50c82afe3b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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('/');
}
}
|