Удобная авторизация в ЦА
v >= 6.5.4 / fpm и cgi режим
1
class My_Auth
2
{
3
static public function onBeforeSendHeaders($response)
4
{
5
if(in_array($response->getStatus(), array(401, 403)) && Core_Array::getSession('HOSTCMS_HTTP_AUTH_FLAG') === TRUE && strpos(Core_Array::get($_SERVER, 'REQUEST_URI'), '/admin/') !== FALSE)
6
{
7
$_SESSION['HOSTCMS_HTTP_AUTH_FLAG'] = FALSE;
8
unset($_SESSION['HOSTCMS_HTTP_AUTH_FLAG']);
9
10
$_SESSION['HOSTCMS_LOCATION_ADMIN'] = Core_Array::get($_SERVER, 'REQUEST_URI');
11
12
header('Location: /admin/');
13
exit();
14
}
15
}
16
17
static public function onAfterLogin($null, $args)
18
{
19
if(!is_null(Core_Array::getSession('HOSTCMS_LOCATION_ADMIN')))
20
{
21
$location = $_SESSION['HOSTCMS_LOCATION_ADMIN'];
22
23
unset($_SESSION['HOSTCMS_LOCATION_ADMIN']);
24
25
header('Location: ' . $location);
26
exit();
27
}
28
}
29
}
30
31
Core_Event::attach('Core_Response.onBeforeSendHeaders', array('My_Auth', 'onBeforeSendHeaders'));
32
Core_Event::attach('Core_Auth.onAfterLogin', array('My_Auth', 'onAfterLogin'));
Last modified 3mo ago