Passed
Push — master ( 8a8111...583a39 )
by Jean-Christophe
19:52
created

AuthControllerConfig::hasAccountRecovery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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