Ubiquity  2.0.3
php rapid development framework
WithAuthTrait.php
Go to the documentation of this file.
1 <?php
3 
6 
12 
16  protected $authController;
17 
18  public function initialize(){
19  parent::initialize();
21  if(!URequest::isAjax()){
22  if(!$authController->_displayInfoAsString()){
23  $authController->info();
24  }
25  if($this->isValid(Startup::getAction())){
27  }else{
28  if($authController->_checkConnectionTimeout()!=null)
29  $this->jquery->clearInterval("_checkConnection");
30  }
31  }
32  }
33 
38  public function loadView($viewName, $pData = NULL, $asString = false) {
39  if(!URequest::isAjax() && $this->_getAuthController()->_displayInfoAsString()){
40  $this->view->setVar("_userInfo",$this->_getAuthController()->info());
41  }
42  return parent::loadView ($viewName,$pData,$asString);
43  }
44 
49  public function isValid($action) {
50  $authCtrl=$this->_getAuthController();
51  $isValid=$authCtrl->_isValidUser($action);
52  if(!$isValid){
53  $authCtrl->_autoConnect();
54  return $authCtrl->_isValidUser($action);
55  }
56  return $isValid;
57  }
58 
63  public function onInvalidControl() {
64  $auth=$this->_getAuthController();
65  if(URequest::isAjax()){
66  $this->jquery->get($auth->_getBaseRoute()."/noAccess/".implode(".", Startup::$urlParts),$auth->_getBodySelector(),["historize"=>false]);
67  echo $this->jquery->compile($this->view);
68  }else{
69  $auth->initialize();
70  $auth->noAccess(Startup::$urlParts);
71  $auth->finalize();
72  }
73  exit();
74  }
75 
79  protected function _getAuthController():AuthController{
80  if(!isset($this->authController)){
81  $this->authController=$this->getAuthController();
82  Startup::injectDependences($this->authController, Startup::getConfig());
83  }
84  return $this->authController;
85  }
86 
87  protected abstract function getAuthController():AuthController;
88 
89 
90  protected function checkConnection($authController){
91  if($authController->_checkConnectionTimeout()!=null){
92  $authController->_disconnected();
93  $this->jquery->ajaxInterval("get",$authController->_getBaseRoute()."/_checkConnection/",$authController->_checkConnectionTimeout(),"_checkConnection","",["jsCallback"=>"data=($.isPlainObject(data))?data:JSON.parse(data);if(!data.valid){ $('#disconnected-modal').modal({closable: false}).modal('show');clearInterval(window._checkConnection);}"]);
94  }
95 
96  }
97 
98 }
loadView($viewName, $pData=NULL, $asString=false)
static injectDependences($controller, $config)
Definition: Startup.php:115
static isAjax()
Returns true if the request is an Ajax request.
Definition: URequest.php:101