|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ubiquity\controllers\auth; |
|
4
|
|
|
|
|
5
|
|
|
use Ubiquity\utils\http\URequest; |
|
6
|
|
|
use Ubiquity\utils\http\USession; |
|
7
|
|
|
use Ubiquity\utils\flash\FlashMessage; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @author jcheron <[email protected]> |
|
11
|
|
|
* @property \Ubiquity\controllers\Auth\AuthFiles $authFiles |
|
12
|
|
|
* @property string $_loginCaption |
|
13
|
|
|
* @property \Ajax\php\ubiquity\JsUtils $jquery |
|
14
|
|
|
*/ |
|
15
|
|
|
trait AuthControllerCoreTrait { |
|
16
|
|
|
abstract public function loadView($viewName, $pData = NULL, $asString = false); |
|
17
|
|
|
abstract protected function attemptsTimeout(); |
|
18
|
|
|
abstract protected function getFiles ():AuthFiles; |
|
19
|
|
|
abstract public function _getBodySelector(); |
|
20
|
|
|
abstract public function _getBaseRoute(); |
|
21
|
|
|
|
|
22
|
1 |
|
protected function getBaseUrl(){ |
|
23
|
1 |
|
return URequest::getUrl($this->_getBaseRoute()); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
1 |
|
public function message($type,$header,$body,$icon="info",$id=null){ |
|
27
|
1 |
|
return $this->loadView($this->_getFiles()->getViewMessage(),get_defined_vars(),true); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
1 |
|
protected function fMessage(FlashMessage $fMessage,$id=null){ |
|
31
|
1 |
|
return $this->message($fMessage->getType(), $fMessage->getTitle(), $fMessage->getContent(),$fMessage->getIcon(),$id); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
protected function noAttempts(){ |
|
35
|
|
|
$timeout=$this->attemptsTimeout(); |
|
36
|
|
|
$plus=""; |
|
37
|
|
|
if(is_numeric($timeout)){ |
|
38
|
|
|
$this->jquery->exec("$('._login').addClass('disabled');",true); |
|
39
|
|
|
$plus=" You can try again {_timer}"; |
|
40
|
|
|
$this->jquery->exec("var startTimer=function(duration, display) {var timer = duration, minutes, seconds; |
|
41
|
|
|
var interval=setInterval(function () { |
|
42
|
|
|
minutes = parseInt(timer / 60, 10);seconds = parseInt(timer % 60, 10); |
|
43
|
|
|
minutes = minutes < 10 ? '0' + minutes : minutes; |
|
44
|
|
|
seconds = seconds < 10 ? '0' + seconds : seconds; |
|
45
|
|
|
display.html(minutes + ':' + seconds); |
|
46
|
|
|
if (--timer < 0) {clearInterval(interval);$('#timeout-message').hide();$('#bad-login').removeClass('attached');$('._login').removeClass('disabled');} |
|
47
|
|
|
}, 1000); |
|
48
|
|
|
}",true); |
|
49
|
|
|
$timeToLeft=USession::getTimeout($this->_attemptsSessionKey); |
|
50
|
|
|
$this->jquery->exec("startTimer({$timeToLeft},$('#timer'));",true); |
|
51
|
|
|
$this->jquery->compile($this->view); |
|
52
|
|
|
} |
|
53
|
|
|
return new FlashMessage("<i class='ui warning icon'></i> You have no more attempt of connection !".$plus,null,"bottom attached error",""); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
1 |
|
protected function authLoadView($viewName,$vars=[]){ |
|
58
|
1 |
|
$files=$this->_getFiles(); |
|
59
|
1 |
|
$mainTemplate=$files->getBaseTemplate(); |
|
60
|
1 |
|
if(isset($mainTemplate)){ |
|
61
|
|
|
$vars["_viewname"]=$viewName; |
|
62
|
|
|
$vars["_base"]=$mainTemplate; |
|
63
|
|
|
$this->loadView($files->getViewBaseTemplate(),$vars); |
|
64
|
|
|
}else{ |
|
65
|
1 |
|
$this->loadView($viewName,$vars); |
|
66
|
|
|
} |
|
67
|
1 |
|
} |
|
68
|
|
|
|
|
69
|
1 |
|
protected function getOriginalURL(){ |
|
70
|
1 |
|
return USession::get("urlParts"); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
protected function _getFiles():AuthFiles{ |
|
74
|
1 |
|
if(!isset($this->authFiles)){ |
|
75
|
1 |
|
$this->authFiles=$this->getFiles(); |
|
76
|
|
|
} |
|
77
|
1 |
|
return $this->authFiles; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
protected function getViewVars($viewname){ |
|
81
|
|
|
return ["authURL"=>$this->getBaseUrl(),"bodySelector"=>$this->_getBodySelector(),"_loginCaption"=>$this->_loginCaption]; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
|