Ubiquity
2.5.2
php rapid development framework
Loading...
Searching...
No Matches
WithAuthTrait.php
Go to the documentation of this file.
1
<?php
2
namespace
Ubiquity\controllers\auth
;
3
4
use
Ubiquity\utils\http\URequest
;
5
use
Ubiquity\controllers\Startup
;
6
20
class
WithAuthTrait
{
21
22
protected
$_checkConnectionContent
;
23
28
protected
$authController
;
29
30
public
function
initialize
() {
31
$authController
= $this->
_getAuthController
();
32
$authController
->_init();
33
parent::initialize();
34
if
(! URequest::isAjax() || URequest::has(
'_userInfo'
)) {
35
if
(!
$authController
->_displayInfoAsString()) {
36
$authController
->info();
37
}
38
if
($this->
isValid
(
Startup::getAction
())) {
39
$this->_checkConnectionContent = $this->
checkConnection
(
$authController
);
40
}
else
{
41
if
(
$authController
->_checkConnectionTimeout() !==
null
)
42
$this->jquery->clearInterval(
'_checkConnection'
);
43
}
44
}
45
}
46
52
public
function
loadView
(
string
$viewName, $pData = NULL,
bool
$asString =
false
) {
53
if
((! URequest::isAjax() && $this->
_getAuthController
()->_displayInfoAsString()) || URequest::has(
'_userInfo'
)) {
54
$this->view->setVar(
'_userInfo'
, $this->
_getAuthController
()
55
->info());
56
}
57
return
parent::loadView($viewName, $pData, $asString);
58
}
59
65
public
function
isValid
($action) {
66
$authCtrl = $this->
_getAuthController
();
67
$isValid = $authCtrl->_isValidUser($action);
68
if
(! $isValid) {
69
$authCtrl->_autoConnect();
70
return
$authCtrl->_isValidUser($action);
71
}
72
return
$isValid;
73
}
74
80
public
function
onInvalidControl
() {
81
$auth = $this->
_getAuthController
();
82
if
(URequest::isAjax()) {
83
$this->jquery->get($auth->_getBaseRoute() .
'/noAccess/'
. \implode(
'.'
,
Startup::$urlParts
), $auth->_getBodySelector(), [
84
'historize'
=>
false
85
]);
86
echo $this->jquery->compile($this->view);
87
}
else
{
88
$this->
initialize
();
89
$auth->noAccess(
Startup::$urlParts
);
90
$this->
finalize
();
91
}
92
exit();
93
}
94
99
protected
function
_getAuthController
():
AuthController
{
100
if (! isset($this->authController)) {
101
$this->authController = $this->
getAuthController
();
102
Startup::injectDependencies
($this->authController);
103
}
104
return
$this->authController
;
105
}
106
107
protected
abstract
function
getAuthController
():
AuthController
;
108
109
protected
function
checkConnection
($authController) {
110
if
($authController->_checkConnectionTimeout() !==
null
) {
111
$ret = $authController->_disconnected();
112
$this->jquery->ajaxInterval(
"get"
, $authController->_getBaseRoute() .
'/checkConnection/'
, $authController->_checkConnectionTimeout(),
'_checkConnection'
,
''
, [
113
'historize'
=>
false
,
114
'jsCallback'
=>
"data=($.isPlainObject(data))?data:JSON.parse(data);if(!data.valid){ $('#disconnected-modal').modal({closable: false}).modal('show');clearInterval(window._checkConnection);}"
115
]);
116
return
$ret;
117
}
118
}
119
120
public
function
finalize
() {
121
parent::finalize();
122
if
(isset($this->_checkConnectionContent)) {
123
echo $this->_checkConnectionContent;
124
}
125
}
126
}
Ubiquity\controllers\Startup
Starts the framework.
Definition
Startup.php:19
Ubiquity\controllers\Startup\$urlParts
static $urlParts
Definition
Startup.php:21
Ubiquity\controllers\Startup\injectDependencies
static injectDependencies($controller)
Injects the dependencies from the di config key in a controller.
Definition
Startup.php:225
Ubiquity\controllers\Startup\getAction
static getAction()
Returns tha active action.
Definition
Startup.php:318
Ubiquity\controllers\auth\AuthController
Definition
AuthController.php:26
Ubiquity\controllers\auth\WithAuthTrait
Definition
WithAuthTrait.php:20
Ubiquity\controllers\auth\WithAuthTrait\loadView
loadView(string $viewName, $pData=NULL, bool $asString=false)
{}
Definition
WithAuthTrait.php:52
Ubiquity\controllers\auth\WithAuthTrait\_getAuthController
_getAuthController()
Definition
WithAuthTrait.php:99
Ubiquity\controllers\auth\WithAuthTrait\$authController
$authController
Definition
WithAuthTrait.php:28
Ubiquity\controllers\auth\WithAuthTrait\initialize
initialize()
Definition
WithAuthTrait.php:30
Ubiquity\controllers\auth\WithAuthTrait\checkConnection
checkConnection($authController)
Definition
WithAuthTrait.php:109
Ubiquity\controllers\auth\WithAuthTrait\finalize
finalize()
Definition
WithAuthTrait.php:120
Ubiquity\controllers\auth\WithAuthTrait\onInvalidControl
onInvalidControl()
{}
Definition
WithAuthTrait.php:80
Ubiquity\controllers\auth\WithAuthTrait\$_checkConnectionContent
$_checkConnectionContent
Definition
WithAuthTrait.php:22
Ubiquity\controllers\auth\WithAuthTrait\isValid
isValid($action)
{}
Definition
WithAuthTrait.php:65
Ubiquity\controllers\auth\WithAuthTrait\getAuthController
getAuthController()
Ubiquity\utils\http\URequest
Http Request utilities, wrapper for accessing to $_GET, $_POST and php://input.
Definition
URequest.php:18
Ubiquity\controllers\auth
Definition
AuthController.php:3
C:
Users
myadd
Documents
GitHub
ubiquity-doc-api
vendor
phpmv
ubiquity
src
Ubiquity
controllers
auth
WithAuthTrait.php
Generated on Sun Dec 10 2023 15:04:17 for
Ubiquity
by
doxygen
1.9.8