|
1
|
|
|
<?php |
|
2
|
|
|
namespace Ubiquity\controllers\auth; |
|
3
|
|
|
|
|
4
|
|
|
use Ubiquity\utils\http\URequest; |
|
5
|
|
|
use Ubiquity\controllers\Startup; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* ControllerBase |
|
9
|
|
|
**/ |
|
10
|
|
|
trait WithAuthTrait{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var AuthController |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $authController; |
|
16
|
|
|
|
|
17
|
|
|
public function initialize(){ |
|
18
|
|
|
parent::initialize(); |
|
19
|
|
|
if(!URequest::isAjax() && !$this->_getAuthController()->_displayInfoAsString()){ |
|
20
|
|
|
$this->_getAuthController()->info(); |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritDoc} |
|
26
|
|
|
* @see \Ubiquity\controllers\Controller::loadView() |
|
27
|
|
|
*/ |
|
28
|
|
|
public function loadView($viewName, $pData = NULL, $asString = false) { |
|
29
|
|
|
if(!URequest::isAjax() && $this->_getAuthController()->_displayInfoAsString()){ |
|
30
|
|
|
$this->view->setVar("_userInfo",$this->_getAuthController()->info()); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
return parent::loadView ($viewName,$pData,$asString); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritDoc} |
|
37
|
|
|
* @see \Ubiquity\controllers\Controller::isValid() |
|
38
|
|
|
*/ |
|
39
|
|
|
public function isValid() { |
|
40
|
|
|
return $this->_getAuthController()->_isValidUser(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritDoc} |
|
45
|
|
|
* @see \Ubiquity\controllers\Controller::onInvalidControl() |
|
46
|
|
|
*/ |
|
47
|
|
|
public function onInvalidControl() { |
|
48
|
|
|
$auth=$this->_getAuthController(); |
|
49
|
|
|
$auth->initialize(); |
|
50
|
|
|
$auth->noAccess(Startup::$urlParts); |
|
51
|
|
|
$auth->finalize(); |
|
52
|
|
|
exit(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return \Ubiquity\controllers\auth\AuthController |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function _getAuthController():AuthController{ |
|
59
|
|
|
if(!isset($this->authController)){ |
|
60
|
|
|
$this->authController=$this->getAuthController(); |
|
61
|
|
|
} |
|
62
|
|
|
return $this->authController; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
protected abstract function getAuthController():AuthController; |
|
66
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: