1
|
|
|
<?php |
2
|
|
|
namespace Ubiquity\controllers\auth; |
3
|
|
|
|
4
|
|
|
use Ubiquity\utils\http\URequest; |
5
|
|
|
use Ubiquity\controllers\Startup; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* ControllerBase |
9
|
|
|
* @property \Ajax\php\ubiquity\JsUtils $jquery |
10
|
|
|
* @property \Ubiquity\views\View $view |
11
|
|
|
**/ |
12
|
|
|
trait WithAuthTrait{ |
13
|
|
|
protected $_checkConnectionContent; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var AuthController |
17
|
|
|
*/ |
18
|
|
|
protected $authController; |
19
|
|
|
|
20
|
1 |
|
public function initialize(){ |
21
|
1 |
|
parent::initialize(); |
22
|
1 |
|
$authController=$this->_getAuthController(); |
23
|
1 |
|
if(!URequest::isAjax()){ |
24
|
1 |
|
if(!$authController->_displayInfoAsString()){ |
25
|
1 |
|
$authController->info(); |
26
|
|
|
} |
27
|
1 |
|
if($this->isValid(Startup::getAction())){ |
28
|
1 |
|
$this->_checkConnectionContent=$this->checkConnection($authController); |
29
|
|
|
}else{ |
30
|
|
|
if($authController->_checkConnectionTimeout()!==null) |
31
|
|
|
$this->jquery->clearInterval("_checkConnection"); |
32
|
|
|
} |
33
|
|
|
} |
34
|
1 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritDoc} |
38
|
|
|
* @see \Ubiquity\controllers\Controller::loadView() |
39
|
|
|
*/ |
40
|
1 |
|
public function loadView($viewName, $pData = NULL, $asString = false) { |
41
|
1 |
|
if(!URequest::isAjax() && $this->_getAuthController()->_displayInfoAsString()){ |
42
|
|
|
$this->view->setVar("_userInfo",$this->_getAuthController()->info()); |
43
|
|
|
} |
44
|
1 |
|
return parent::loadView ($viewName,$pData,$asString); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritDoc} |
49
|
|
|
* @see \Ubiquity\controllers\Controller::isValid() |
50
|
|
|
*/ |
51
|
1 |
|
public function isValid($action) { |
52
|
1 |
|
$authCtrl=$this->_getAuthController(); |
53
|
1 |
|
$isValid=$authCtrl->_isValidUser($action); |
54
|
1 |
|
if(!$isValid){ |
55
|
1 |
|
$authCtrl->_autoConnect(); |
56
|
1 |
|
return $authCtrl->_isValidUser($action); |
57
|
|
|
} |
58
|
1 |
|
return $isValid; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritDoc} |
63
|
|
|
* @see \Ubiquity\controllers\Controller::onInvalidControl() |
64
|
|
|
*/ |
65
|
1 |
|
public function onInvalidControl() { |
66
|
1 |
|
$auth=$this->_getAuthController(); |
67
|
1 |
|
if(URequest::isAjax()){ |
68
|
|
|
$this->jquery->get($auth->_getBaseRoute()."/noAccess/".implode(".", Startup::$urlParts),$auth->_getBodySelector(),["historize"=>false]); |
69
|
|
|
echo $this->jquery->compile($this->view); |
70
|
|
|
}else{ |
71
|
1 |
|
parent::initialize(); |
72
|
1 |
|
$auth->noAccess(Startup::$urlParts); |
73
|
1 |
|
parent::finalize(); |
74
|
|
|
} |
75
|
1 |
|
exit(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return \Ubiquity\controllers\auth\AuthController |
80
|
|
|
*/ |
81
|
1 |
|
protected function _getAuthController():AuthController{ |
82
|
1 |
|
if(!isset($this->authController)){ |
83
|
1 |
|
$this->authController=$this->getAuthController(); |
84
|
1 |
|
Startup::injectDependences($this->authController); |
85
|
|
|
} |
86
|
1 |
|
return $this->authController; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
protected abstract function getAuthController():AuthController; |
90
|
|
|
|
91
|
|
|
|
92
|
1 |
|
protected function checkConnection($authController){ |
93
|
1 |
|
if($authController->_checkConnectionTimeout()!==null){ |
94
|
|
|
$ret=$authController->_disconnected(); |
95
|
|
|
$this->jquery->ajaxInterval("get",$authController->_getBaseRoute()."/checkConnection/",$authController->_checkConnectionTimeout(),"_checkConnection","",["historize"=>false,"jsCallback"=>"data=($.isPlainObject(data))?data:JSON.parse(data);if(!data.valid){ $('#disconnected-modal').modal({closable: false}).modal('show');clearInterval(window._checkConnection);}"]); |
96
|
|
|
return $ret; |
97
|
|
|
} |
98
|
1 |
|
} |
99
|
|
|
|
100
|
1 |
|
public function finalize(){ |
101
|
1 |
|
parent::finalize(); |
102
|
1 |
|
if(isset($this->_checkConnectionContent)){ |
103
|
|
|
echo $this->_checkConnectionContent; |
104
|
|
|
} |
105
|
1 |
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|