-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccountBase.php
155 lines (140 loc) · 4.22 KB
/
AccountBase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
declare(strict_types=1);
namespace Webiik\Account;
abstract class AccountBase implements AccountInterface
{
/**
* Common authentication status codes and messages
*/
public const FAILURE = 0,
METHOD_IS_NOT_IMPLEMENTED = 1,
INVALID_CREDENTIAL = 2,
INVALID_PASSWORD = 3,
INVALID_TOKEN = 4,
INVALID_KEY = 5,
ACCOUNT_DOES_NOT_EXIST = 6,
ACCOUNT_ALREADY_EXISTS = 7,
ACCOUNT_IS_NOT_ACTIVATED = 8,
ACCOUNT_IS_BANNED = 9,
ACCOUNT_IS_DISABLED = 10,
ACCOUNT_IS_OK = 20;
public const MSG_FAILURE = 'Failure.',
MSG_METHOD_IS_NOT_IMPLEMENTED = 'Method is not implemented.',
MSG_INVALID_CREDENTIAL = 'Invalid credential(s).',
MSG_INVALID_PASSWORD = 'Invalid password.',
MSG_INVALID_TOKEN = 'Invalid token.',
MSG_ACCOUNT_DOES_NOT_EXIST = 'Account does not exist.',
MSG_ACCOUNT_ALREADY_EXISTS = 'Account already exists.',
MSG_ACCOUNT_IS_NOT_ACTIVATED = 'Account requires activation.',
MSG_ACCOUNT_IS_BANNED = 'Account is banned.',
MSG_ACCOUNT_IS_DISABLED = 'Account is disabled.',
MSG_ACCOUNT_IS_OK = 'Account is ok';
/**
* Account namespace
* @var string
*/
public $namespace = '';
/**
* @param array $credentials
* @return User
* @throws AccountException
*/
public function auth(array $credentials): User
{
throw new AccountException('Method auth() is not implemented.', self::METHOD_IS_NOT_IMPLEMENTED);
}
/**
* @param string $uid
* @return User
* @throws AccountException
*/
public function reAuth(string $uid): User
{
throw new AccountException('Method reAuth() is not implemented.', self::METHOD_IS_NOT_IMPLEMENTED);
}
/**
* @param array $credentials
* @return User
* @throws AccountException
*/
public function signup(array $credentials): User
{
throw new AccountException('Method signup() is not implemented.', self::METHOD_IS_NOT_IMPLEMENTED);
}
/**
* @param int $uid
* @param array $data
* @return User
* @throws AccountException
*/
public function update(int $uid, array $data): User
{
throw new AccountException('Method update() is not implemented.', self::METHOD_IS_NOT_IMPLEMENTED);
}
/**
* @param int $uid
* @param int $reason
* @param array $data
* @return User
* @throws AccountException
*/
public function disable(int $uid, int $reason, array $data = []): User
{
throw new AccountException('Method disable() is not implemented.', self::METHOD_IS_NOT_IMPLEMENTED);
}
/**
* @param int $uid
* @param array $data
* @return User
* @throws AccountException
*/
public function delete(int $uid, array $data = []): User
{
throw new AccountException('Method delete() is not implemented.', self::METHOD_IS_NOT_IMPLEMENTED);
}
/**
* @param int $uid
* @return string
* @throws AccountException
*/
public function createToken(): string
{
throw new AccountException('Method createToken() is not implemented.', self::METHOD_IS_NOT_IMPLEMENTED);
}
/**
* @param string $token
* @return User
* @throws AccountException
*/
public function activate(string $token): User
{
throw new AccountException('Method activate() is not implemented.', self::METHOD_IS_NOT_IMPLEMENTED);
}
/**
* @param string $token
* @param string $password
* @return User
* @throws AccountException
*/
public function resetPassword(string $token, string $password): User
{
throw new AccountException('Method resetPassword() is not implemented.', self::METHOD_IS_NOT_IMPLEMENTED);
}
/**
* @param string $password
* @return string
*/
protected function hashPassword(string $password): string
{
return password_hash($password, PASSWORD_BCRYPT);
}
/**
* @param string $password
* @param string $hash
* @return bool
*/
protected function verifyPassword(string $password, string $hash): bool
{
return password_verify($password, $hash);
}
}