Test Failed
Push — master ( a3ba5a...4fa899 )
by Jean-Christophe
18:16
created

AuthControllerOverrideTrait::fromCookie()   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 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Ubiquity\controllers\auth;
4
5
use Ubiquity\cache\ClassUtils;
6
use Ubiquity\utils\http\USession;
7
use Ubiquity\utils\http\UCookie;
8
9
trait AuthControllerOverrideTrait {
10
	
11
	abstract public function badLogin();
12
	abstract public function bad2FACode();
13
	
14
	/**
15
	 * To override
16
	 * Return the base route for this Auth controller
17
	 * @return string
18
	 */
19
	public function _getBaseRoute(){
20
		return ClassUtils::getClassSimpleName(get_class($this));
21
	}
22
	
23
	/**
24
	 * Processes the data posted by the login form
25
	 * Have to return the connected user instance
26
	 */
27
	abstract protected function _connect();
28
	
29
	/**
30
	 * To override
31
	 * For creating a new user account.
32
	 */
33
	protected function _create(string $login,string $password):?bool{
2 ignored issues
show
Unused Code introduced by
The parameter $password is not used and could be removed. ( Ignorable by Annotation )

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

33
	protected function _create(string $login,/** @scrutinizer ignore-unused */ string $password):?bool{

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $login is not used and could be removed. ( Ignorable by Annotation )

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

33
	protected function _create(/** @scrutinizer ignore-unused */ string $login,string $password):?bool{

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
		return false;
35
	}
36 1
	
37 1
	/**
38 1
	 * @param object $connected
39
	 */
40
	abstract protected function onConnect($connected);
41
	
42
	/**
43
	 * To override for defining a new action when creditentials are invalid.
44 1
	 */
45 1
	protected function onBadCreditentials(){
46
		$this->badLogin();
47
	}
48
	
49
	/**
50
	 * To override for defining a new action when 2FA code is invalid.
51
	 */
52 1
	protected function onBad2FACode(){
53 1
		$this->bad2FACode();
54
	}
55
	
56
	/**
57
	 * To override
58
	 * Send the 2FA code to the user (email, sms, phone call...)
59
	 * @param string $code
60
	 * @param mixed $connected
61
	 */
62
	protected function _send2FACode(string $code,$connected){
2 ignored issues
show
Unused Code introduced by
The parameter $connected is not used and could be removed. ( Ignorable by Annotation )

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

62
	protected function _send2FACode(string $code,/** @scrutinizer ignore-unused */ $connected){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $code is not used and could be removed. ( Ignorable by Annotation )

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

62
	protected function _send2FACode(/** @scrutinizer ignore-unused */ string $code,$connected){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
		
64
	}
65
	
66
	/**
67
	 * To override
68
	 * Returns true if the creation of $accountName is possible.
69
	 * @param string $accountName
70
	 * @return bool
71
	 */
72
	protected function newAccountCreationRule(string $accountName):?bool{
1 ignored issue
show
Unused Code introduced by
The parameter $accountName is not used and could be removed. ( Ignorable by Annotation )

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

72
	protected function newAccountCreationRule(/** @scrutinizer ignore-unused */ string $accountName):?bool{

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
73
		
74
	}
75
	
76
	/**
77
	 * To override for defining user session key, default : "activeUser"
78
	 * @return string
79
	 */
80
	public function _getUserSessionKey(){
81
		return 'activeUser';
82
	}
83
	
84
	/**
85
	 * To override for getting active user, default : USession::get("activeUser")
86
	 * @return string
87
	 */
88
	public function _getActiveUser(){
89
		return USession::get($this->_getUserSessionKey());
90
	}
91
	
92
	/**
93
	 * Checks if user is valid for the action
94
	 * @param string $action
95 1
	 * return boolean true if activeUser is valid
96 1
	 */
97
	abstract public function _isValidUser($action=null);
98
	
99
	/**
100
	 * Returns the value from connected user to save it in the cookie for auto connection
101
	 * @param object $connected
102
	 */
103
	protected function toCookie($connected){
104
		return;
105
	}
106
	
107
	/**
108
	 * Sends an email for email checking.
109
	 * @param string $email
110
	 * @param string $validationURL
111
	 */
112
	protected function _sendEmailValidation(string $email,string $validationURL){
2 ignored issues
show
Unused Code introduced by
The parameter $validationURL is not used and could be removed. ( Ignorable by Annotation )

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

112
	protected function _sendEmailValidation(string $email,/** @scrutinizer ignore-unused */ string $validationURL){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $email is not used and could be removed. ( Ignorable by Annotation )

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

112
	protected function _sendEmailValidation(/** @scrutinizer ignore-unused */ string $email,string $validationURL){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
113
		
114
	}
115
	
116
	/**
117
	 * Loads the user from database using the cookie value
118
	 * @param string $cookie
119
	 */
120
	protected function fromCookie($cookie){
121
		return;
122
	}
123
	
124
	
125
	/**
126
	 * Saves the connected user identifier in a cookie
127
	 * @param object $connected
128
	 */
129
	protected function rememberMe($connected){
130
		$id= $this->toCookie($connected);
131
		if(isset($id)){
132
			UCookie::set($this->_getUserSessionKey(),$id);
133
		}
134
	}
135
	
136
	/**
137
	 * Returns the cookie for auto connection
138
	 * @return NULL|string
139
	 */
140
	protected function getCookieUser(){
141
		return UCookie::get($this->_getUserSessionKey());
142
	}
143
	
144
	/**
145
	 * To override for changing view files
146
	 * @return AuthFiles
147
	 */
148
	protected function getFiles ():AuthFiles{
149
		return new AuthFiles();
150
	}
151
	
152
	/**
153
	 * To override
154
	 * @param mixed $account
155
	 * @return string
156
	 */
157
	protected function getEmailFromNewAccount($account):string{
158
		return $account;
159
	}
160
}
161
162