3 cx_require('lib', 'sessions.php');
4 cx_require('lib', 'users.php');
6 define('CX_ADMIN_SESSION_LIFETIME', (86400 * 1)); // 86400 = 1 day
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;
12 function cx_admin_login($username, $password) {
13 $password_hash = cx_users_hash_password_for_user($username, $password);
15 $user = cx_users_find_user(name
: $username, password_hash
: $password_hash);
19 $session_uid = cx_sessions_create_session($user);
20 setcookie('cx_session', $session_uid, time() + CX_ADMIN_SESSION_LIFETIME
, "/");
25 function cx_admin_logout() {
26 if (isset($_COOKIE['cx_session'])) {
27 cx_sessions_close_session($_COOKIE['cx_session']);
29 setcookie('cx_session', null, time(), "/");