Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
authentication.php
1<?php
2
3
5
6
12
13final class Authentication extends Base
14{
15 const ERROR_INVALID_AUTHENTICATION = 'invalid_authentication';
16
20 private $enableRedirect;
21
22 public function __construct($enableRedirect = false)
23 {
24 $this->enableRedirect = $enableRedirect;
25 parent::__construct();
26 }
27
28 public function onBeforeAction(Event $event)
29 {
30 global $USER;
31
32 if (!($USER instanceof \CUser) || !$USER->getId())
33 {
34 $isAjax = $this->getAction()->getController()->getRequest()->getHeader('BX-Ajax');
35 if ($this->enableRedirect && !$isAjax)
36 {
37 LocalRedirect(
38 SITE_DIR .
39 'auth/?backurl=' .
40 urlencode(\Bitrix\Main\Application::getInstance()->getContext()->getRequest()->getRequestUri())
41 );
42
43 return new EventResult(EventResult::ERROR, null, null, $this);
44 }
45
46 Context::getCurrent()->getResponse()->setStatus(401);
47 $this->addError(new Error(
48 Loc::getMessage("MAIN_ENGINE_FILTER_AUTHENTICATION_ERROR"), self::ERROR_INVALID_AUTHENTICATION)
49 );
50
51 return new EventResult(EventResult::ERROR, null, null, $this);
52 }
53
54 return null;
55 }
56}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29