Passed
Push — master ( 439a7d...a647b4 )
by Jean-Christophe
01:38
created

AuthControllerCoreTrait::noAttempts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 20
rs 9.9
c 0
b 0
f 0
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
	
21
	protected  function getBaseUrl(){
22
		return URequest::getUrl($this->_getBaseRoute());
0 ignored issues
show
Bug introduced by
It seems like _getBaseRoute() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
		return URequest::getUrl($this->/** @scrutinizer ignore-call */ _getBaseRoute());
Loading history...
23
	}
24
	
25
	public function message($type,$header,$body,$icon="info",$id=null){
26
		return $this->loadView($this->_getFiles()->getViewMessage(),get_defined_vars(),true);
27
	}
28
	
29
	protected function fMessage(FlashMessage $fMessage,$id=null){
30
		return $this->message($fMessage->getType(), $fMessage->getTitle(), $fMessage->getContent(),$fMessage->getIcon(),$id);
31
	}
32
	
33
	protected function noAttempts(){
34
		$timeout=$this->attemptsTimeout();
35
		$plus="";
36
		if(is_numeric($timeout)){
37
			$this->jquery->exec("$('._login').addClass('disabled');",true);
38
			$plus=" You can try again {_timer}";
39
			$this->jquery->exec("var startTimer=function(duration, display) {var timer = duration, minutes, seconds;
40
    										var interval=setInterval(function () {
41
        										minutes = parseInt(timer / 60, 10);seconds = parseInt(timer % 60, 10);
42
										        minutes = minutes < 10 ? '0' + minutes : minutes;
43
        										seconds = seconds < 10 ? '0' + seconds : seconds;
44
										        display.html(minutes + ':' + seconds);
45
										        if (--timer < 0) {clearInterval(interval);$('#timeout-message').hide();$('#bad-login').removeClass('attached');$('._login').removeClass('disabled');}
46
    										}, 1000);
47
										}",true);
48
			$timeToLeft=USession::getTimeout($this->_attemptsSessionKey);
49
			$this->jquery->exec("startTimer({$timeToLeft},$('#timer'));",true);
50
			$this->jquery->compile($this->view);
51
		}
52
		return new FlashMessage("<i class='ui warning icon'></i> You have no more attempt of connection !".$plus,null,"bottom attached error","");
53
	}
54
	
55
	
56
	protected function authLoadView($viewName,$vars=[]){
57
		$files=$this->_getFiles();
58
		$mainTemplate=$files->getBaseTemplate();
59
		if(isset($mainTemplate)){
60
			$vars["_viewname"]=$viewName;
61
			$vars["_base"]=$mainTemplate;
62
			$this->loadView($files->getViewBaseTemplate(),$vars);
63
		}else{
64
			$this->loadView($viewName,$vars);
65
		}
66
	}
67
	
68
	protected function getOriginalURL(){
69
		return USession::get("urlParts");
70
	}
71
	
72
	protected  function _getFiles():AuthFiles{
73
		if(!isset($this->authFiles)){
74
			$this->authFiles=$this->getFiles();
75
		}
76
		return $this->authFiles;
77
	}
78
	
79
	protected function getViewVars($viewname){
80
		return ["authURL"=>$this->getBaseUrl(),"bodySelector"=>$this->_getBodySelector(),"_loginCaption"=>$this->_loginCaption];
81
	}
82
}
83
84