]> git.bts.cx Git - cx.git/blob - cx/lib/admin.php
Added post title to page title
[cx.git] / cx / lib / admin.php
1 <?php
2
3 cx_require('lib', 'sessions.php');
4 cx_require('lib', 'users.php');
5
6 define('CX_ADMIN_SESSION_LIFETIME', (86400 * 1)); // 86400 = 1 day
7
8 function cx_admin_logged_in() {
9 return isset($_COOKIE['cx_session']) && cx_sessions_active_session_user($_COOKIE['cx_session'], CX_ADMIN_SESSION_LIFETIME) != null;
10 }
11
12 function cx_admin_login($username, $password) {
13 $password_hash = cx_users_hash_password_for_user($username, $password);
14
15 $user = cx_users_find_user(name: $username, password_hash: $password_hash);
16 if ($user == null) {
17 return false;
18 } else {
19 $session_uid = cx_sessions_create_session($user);
20 setcookie('cx_session', $session_uid, time() + CX_ADMIN_SESSION_LIFETIME, "/");
21 return true;
22 }
23 }
24
25 function cx_admin_logout() {
26 if (isset($_COOKIE['cx_session'])) {
27 cx_sessions_close_session($_COOKIE['cx_session']);
28 }
29 setcookie('cx_session', null, time(), "/");
30 }