Passed
Push — master ( 6a78e3...31c3ef )
by Jean-Christophe
19:36
created

AuthControllerConfig::rememberCaption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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