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 initialize(){ |
21
|
|
|
$file=new UConfigFile($this->getConfigFilename()); |
22
|
|
|
$this->config=$file->load(); |
23
|
|
|
parent::initialize(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
abstract protected function getConfigFilename():string; |
27
|
|
|
|
28
|
|
|
protected function useAjax():bool{ |
29
|
|
|
return $this->config['useAjax']??true; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function attemptsNumber() { |
33
|
|
|
return $this->config['attemptsNumber']??null; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function _getUserSessionKey(): string { |
37
|
|
|
return $this->config['userSessionKey']??'activeUser'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function attemptsTimeout():int{ |
41
|
|
|
return $this->config['attemptsTimeout']??(3*60); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function _displayInfoAsString():bool{ |
45
|
|
|
return $this->config['_displayInfoAsString']??false; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function _getLoginInputName():string{ |
49
|
|
|
return $this->config['loginInputName']??'email'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function loginLabel():string{ |
53
|
|
|
return $this->config['loginLabel']??\ucfirst($this->_getLoginInputName()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function _getPasswordInputName():string{ |
57
|
|
|
return $this->config['passwordInputName']??'password'; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function passwordLabel(): string { |
61
|
|
|
return $this->config['passwordLabel']??\ucfirst ( $this->_getPasswordInputName () ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function passwordConfLabel(): string { |
65
|
|
|
return $this->config['passwordConfLabel']??(\ucfirst ( $this->_getPasswordInputName () ).' confirmation'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function _getBodySelector():string { |
69
|
|
|
return $this->config['bodySelector']??'main .container'; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected function rememberCaption():string { |
73
|
|
|
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
|
|
|
protected function hasAccountCreation():bool{ |
85
|
|
|
return $this->config['hasAccountCreation']??false; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
protected function hasAccountRecovery():bool{ |
89
|
|
|
return $this->config['hasAccountRecovery']??false; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
protected function recoveryAccountCaption():string{ |
93
|
|
|
return $this->config['recoveryAccountCaption']??'Forgot your password?'; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public static function init(?string $name=null,?array $config=null){ |
97
|
|
|
$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
|
|
|
$name??=\lcfirst(ClassUtils::getClassSimpleName(static::class)); |
118
|
|
|
$file=new UConfigFile($name); |
119
|
|
|
$file->setData($config); |
120
|
|
|
$file->save(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|