Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
WithAuthTrait.php
Go to the documentation of this file.
1<?php
3
6
21
23
28 protected $authController;
29
30 public function initialize() {
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 }
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}
Starts the framework.
Definition Startup.php:19
static injectDependencies($controller)
Injects the dependencies from the di config key in a controller.
Definition Startup.php:225
static getAction()
Returns tha active action.
Definition Startup.php:318
loadView(string $viewName, $pData=NULL, bool $asString=false)
{}
Http Request utilities, wrapper for accessing to $_GET, $_POST and php://input.
Definition URequest.php:18