Test Failed
Push — master ( 8ca2f4...a87d59 )
by Jean-Christophe
22:35
created

AuthControllerConfig::_init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Ubiquity\controllers\auth;
4
5
use Ubiquity\cache\ClassUtils;
6
use Ubiquity\utils\base\UConfigFile;
7
8
/**
9
 * 
10
 * Ubiquity\controllers\auth$AuthControllerConfig
11
 * This class is part of Ubiquity
12
 * @author jc
13
 * @version 1.0.0
14
 *
15
 */
16
abstract class AuthControllerConfig extends AuthController {
17
	
18
	protected array $config;
19
20 1
	public function initialize(){
21 1
		$this->_init();
22 1
		parent::initialize();
23 1
	}
24
	
25
	public function _init(){
26
		$file=new UConfigFile($this->getConfigFilename());
27
		$this->config=$file->load();
28 1
	}
29 1
30
	abstract protected function getConfigFilename():string;
31
32 1
	protected function useAjax():bool{
33 1
		return $this->config['useAjax']??true;
34
	}
35
36 1
	protected function attemptsNumber() {
37 1
		return $this->config['attemptsNumber']??null;
38
	}
39
40
	public function _getUserSessionKey(): string {
41
		return $this->config['userSessionKey']??'activeUser';
42
	}
43
44 1
	public function attemptsTimeout():int{
45 1
		return $this->config['attemptsTimeout']??(3*60);
46
	}
47
48 1
	public function _displayInfoAsString():bool{
49 1
		return $this->config['displayInfoAsString']??false;
50
	}
51
52 1
	public function _getLoginInputName():string{
53 1
		return $this->config['loginInputName']??'email';
54
	}
55
56 1
	public function loginLabel():string{
57 1
		return $this->config['loginLabel']??\ucfirst($this->_getLoginInputName());
58
	}
59
60 1
	public function _getPasswordInputName():string{
61 1
		return $this->config['passwordInputName']??'password';
62
	}
63
64 1
	protected function passwordLabel(): string {
65 1
		return $this->config['passwordLabel']??\ucfirst ( $this->_getPasswordInputName () );
66
	}
67
68 1
	protected function passwordConfLabel(): string {
69 1
		return $this->config['passwordConfLabel']??(\ucfirst ( $this->_getPasswordInputName () ).' confirmation');
70
	}
71
72 1
	public function _getBodySelector():string {
73 1
		return $this->config['bodySelector']??'main .container';
74
	}
75
76
	protected function rememberCaption():string {
77
		return $this->config['rememberCaption']??'Remember me';
78
	}
79
80
	protected function getTokenSize():int{
81
		return $this->config['2FA.tokenSize']??6;
82
	}
83
84 1
	protected function towFACodePrefix():string{
85 1
		return $this->config['2FA.codePrefix']??'U-';
86
	}
87
88 1
	protected function hasAccountCreation():bool{
89 1
		return $this->config['hasAccountCreation']??false;
90
	}
91
92 1
	protected function hasAccountRecovery():bool{
93 1
		return $this->config['hasAccountRecovery']??false;
94
	}
95
96 1
	protected function recoveryAccountCaption():string{
97 1
		return $this->config['recoveryAccountCaption']??'Forgot your password?';
98
	}
99
100
	public static function init(?string $name=null,?array $config=null){
101
		$config??=[
102
			'attempsNumber'=>null,
103
			'userSessionKey'=>'activeUser',
104
			'useAjax'=>true,
105
			'attemptsTimeout'=>3*60,
106
			'displayInfoAsString'=>false,
107
			'loginInputName'=>'email',
108
			'loginLabel'=>'Email',
109
			'passwordInputName'=>'password',
110
			'passwordLabel'=>'Password',
111
			'passwordConfLabel'=>'Password confirmation',
112
			'rememberCaption'=>'Remember me',
113
			'bodySelector'=>'main .container',
114
			'2FA.tokenSize'=>6,
115
			'2FA.codePrefix'=>'U-',
116
			'hasAccountCreation'=>false,
117 1
			'hasAccountRecovery'=>false,
118 1
			'recoveryAccountCaption'=>'Forgot your password?'
119 1
120 1
		];
121
		$name??=\lcfirst(ClassUtils::getClassSimpleName(static::class));
122
		$file=new UConfigFile($name);
123
		$file->setData($config);
124
		$file->save();
125
	}
126
127
}
128
129