1 | <?php |
||
61 | class User { |
||
62 | use |
||
63 | Accessor, |
||
64 | Singleton, |
||
65 | User_data, |
||
66 | User_group, |
||
67 | User_management, |
||
68 | User_permission, |
||
69 | User_profile; |
||
70 | /** |
||
71 | * Id of system guest user |
||
72 | */ |
||
73 | const GUEST_ID = 1; |
||
74 | /** |
||
75 | * Id of first, primary system administrator |
||
76 | */ |
||
77 | const ROOT_ID = 2; |
||
78 | /** |
||
79 | * Id of system group for administrators |
||
80 | */ |
||
81 | const ADMIN_GROUP_ID = 1; |
||
82 | /** |
||
83 | * Id of system group for users |
||
84 | */ |
||
85 | const USER_GROUP_ID = 2; |
||
86 | /** |
||
87 | * Status of active user |
||
88 | */ |
||
89 | const STATUS_ACTIVE = 1; |
||
90 | /** |
||
91 | * Status of inactive user |
||
92 | */ |
||
93 | const STATUS_INACTIVE = 0; |
||
94 | /** |
||
95 | * Status of not activated user |
||
96 | */ |
||
97 | const STATUS_NOT_ACTIVATED = -1; |
||
98 | /** |
||
99 | * @var Cache\Prefix |
||
100 | */ |
||
101 | protected $cache; |
||
102 | /** |
||
103 | * Whether to use memory cache (locally, inside object, may require a lot of memory if working with many users together) |
||
104 | * @var bool |
||
105 | */ |
||
106 | protected $memory_cache = true; |
||
107 | /** |
||
108 | * Returns database index |
||
109 | * |
||
110 | * @return int |
||
111 | */ |
||
112 | 28 | protected function cdb () { |
|
125 | /** |
||
126 | * Check number of sign in attempts (is used by system) |
||
127 | * |
||
128 | * @param string $login_hash Hash (sha224) from login (hash from lowercase string) |
||
129 | * |
||
130 | * @return int Number of attempts |
||
1 ignored issue
–
show
|
|||
131 | */ |
||
132 | function get_sign_in_attempts_count ($login_hash) { |
||
150 | /** |
||
151 | * Process sign in result (is used by system) |
||
152 | * |
||
153 | * @param bool $success |
||
154 | * @param string $login_hash Hash (sha224) from login (hash from lowercase string) |
||
155 | */ |
||
156 | function sign_in_result ($success, $login_hash) { |
||
157 | if (!preg_match('/^[0-9a-z]{56}$/', $login_hash)) { |
||
158 | return; |
||
159 | } |
||
160 | $ip = ip2hex(Request::instance()->ip); |
||
161 | $time = time(); |
||
162 | if ($success) { |
||
163 | $this->db_prime()->q( |
||
164 | "DELETE FROM `[prefix]sign_ins` |
||
165 | WHERE |
||
166 | `expire` > $time AND |
||
167 | ( |
||
168 | `login_hash` = '%s' OR `ip` = '%s' |
||
169 | )", |
||
170 | $login_hash, |
||
171 | $ip |
||
172 | ); |
||
173 | } else { |
||
174 | $Config = Config::instance(); |
||
175 | $this->db_prime()->q( |
||
176 | "INSERT INTO `[prefix]sign_ins` |
||
177 | ( |
||
178 | `expire`, |
||
179 | `login_hash`, |
||
180 | `ip` |
||
181 | ) VALUES ( |
||
182 | '%s', |
||
183 | '%s', |
||
184 | '%s' |
||
185 | )", |
||
186 | $time + $Config->core['sign_in_attempts_block_time'], |
||
187 | $login_hash, |
||
188 | $ip |
||
189 | ); |
||
190 | if ($this->db_prime()->id() % $Config->core['inserts_limit'] == 0) { |
||
191 | $this->db_prime()->q("DELETE FROM `[prefix]sign_ins` WHERE `expire` < $time"); |
||
192 | } |
||
193 | } |
||
194 | } |
||
195 | /** |
||
196 | * Get data item of current user |
||
197 | * |
||
198 | * @param string|string[] $item |
||
199 | * |
||
200 | * @return false|int|mixed[]|string|User\Properties If <i>$item</i> is integer - cs\User\Properties object will be returned |
||
201 | */ |
||
202 | 20 | function __get ($item) { |
|
208 | /** |
||
209 | * Set data item of current user |
||
210 | * |
||
211 | * @param array|int|string $item Item-value array may be specified for setting several items at once |
||
212 | * @param mixed|null $value |
||
213 | * |
||
214 | * @return bool |
||
1 ignored issue
–
show
|
|||
215 | */ |
||
216 | function __set ($item, $value = null) { |
||
217 | $this->set($item, $value); |
||
218 | } |
||
219 | /** |
||
220 | * Is admin |
||
221 | * |
||
222 | * Proxy to \cs\Session::instance()->admin() for convenience |
||
223 | * |
||
224 | * @return bool |
||
225 | */ |
||
226 | 8 | function admin () { |
|
229 | /** |
||
230 | * Is user |
||
231 | * |
||
232 | * Proxy to \cs\Session::instance()->user() for convenience |
||
233 | * |
||
234 | * @return bool |
||
235 | */ |
||
236 | function user () { |
||
239 | /** |
||
240 | * Is guest |
||
241 | * |
||
242 | * Proxy to \cs\Session::instance()->guest() for convenience |
||
243 | * |
||
244 | * @return bool |
||
245 | */ |
||
246 | function guest () { |
||
249 | /** |
||
250 | * Disable memory cache |
||
251 | * |
||
252 | * Memory cache stores users data inside User class in order to get data faster next time. |
||
253 | * But in case of working with large amount of users this cache can be too large. Disabling will cause some performance drop, but save a lot of RAM. |
||
254 | */ |
||
255 | function disable_memory_cache () { |
||
260 | } |
||
261 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.