1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use DBAL\db_mysql; |
4
|
|
|
use Modules\sn_module; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* User: Gorlum |
8
|
|
|
* Date: 10.10.2015 |
9
|
|
|
* Time: 6:05 |
10
|
|
|
*/ |
11
|
|
|
class auth_abstract extends sn_module { |
12
|
|
|
public $manifest = []; |
13
|
|
|
|
14
|
|
|
public $provider_id = ACCOUNT_PROVIDER_NONE; |
15
|
|
|
|
16
|
|
|
protected $features = array(); |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var Account |
20
|
|
|
*/ |
21
|
|
|
public $account = null; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Статус входа аккаунта в игру |
25
|
|
|
* |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
public $account_login_status = LOGIN_UNDEFINED; |
29
|
|
|
public $account_login_message = ''; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var db_mysql $db |
33
|
|
|
*/ |
34
|
|
|
// TODO Should be PROTECTED |
35
|
|
|
public $db; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $filename |
39
|
|
|
*/ |
40
|
|
|
public function __construct($filename = __FILE__) { |
41
|
|
|
if ($this->provider_id == ACCOUNT_PROVIDER_NONE) { |
|
|
|
|
42
|
|
|
die('У всех провайдеров должен быть $provider_id!'); |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
parent::__construct($filename); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return int |
50
|
|
|
*/ |
51
|
|
|
public function login() { |
52
|
|
|
return $this->account_login_status; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* |
57
|
|
|
*/ |
58
|
|
|
public function logout() { |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Меняет пароль у аккаунта с проверкой старого пароля |
63
|
|
|
* |
64
|
|
|
* @param $old_password_unsafe |
65
|
|
|
* @param $new_password_unsafe |
66
|
|
|
* @param null $salt_unsafe |
|
|
|
|
67
|
|
|
* |
68
|
|
|
* @return array|bool|resource |
69
|
|
|
*/ |
70
|
|
|
public function password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe = null) { |
71
|
|
|
return |
72
|
|
|
$this->is_feature_supported(AUTH_FEATURE_PASSWORD_CHANGE) |
73
|
|
|
&& is_object($this->account) |
74
|
|
|
&& $this->account->password_change($old_password_unsafe, $new_password_unsafe, $salt_unsafe); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param $account_to_impersonate |
79
|
|
|
*/ |
80
|
|
|
public function impersonate($account_to_impersonate) { |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Меняет пароль на пристыкованном аккаунте |
85
|
|
|
* |
86
|
|
|
* @param $password_unsafe |
87
|
|
|
* |
88
|
|
|
* @return bool |
89
|
|
|
*/ |
90
|
|
|
public function password_check($password_unsafe) { |
91
|
|
|
return |
92
|
|
|
$this->is_feature_supported(AUTH_FEATURE_HAS_PASSWORD) |
93
|
|
|
&& is_object($this->account) |
94
|
|
|
&& $this->account->password_check($password_unsafe); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Проверка на поддержку фичи |
99
|
|
|
* |
100
|
|
|
* @param $feature |
101
|
|
|
* |
102
|
|
|
* @return bool |
103
|
|
|
*/ |
104
|
|
|
public function is_feature_supported($feature) { |
105
|
|
|
return !empty($this->features[$feature]); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Функция предлогает имя игрока (`users`) по данным аккаунта |
110
|
|
|
* |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function player_name_suggest() { |
114
|
|
|
$name = ''; |
115
|
|
|
if (is_object($this->account) && !empty($this->account->account_email)) { |
116
|
|
|
list($name) = explode('@', $this->account->account_email); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
empty($name) && is_object($this->account) && !empty($this->account->account_name) ? $name = $this->account->account_name : false; |
120
|
|
|
|
121
|
|
|
return $name; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|