-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy pathuser.php
More file actions
30 lines (25 loc) · 706 Bytes
/
user.php
File metadata and controls
30 lines (25 loc) · 706 Bytes
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
<?php
include './db.php';
class User
{
public $login;
public $isAdmin;
public function __construct($login, $isAdmin)
{
$this->login = $login;
$this->isAdmin = $isAdmin;
}
static function login($login, $password)
{
$db = DB::getConnection();
$statement = $db->prepare('SELECT * FROM users WHERE login=:login AND password=:password;');
$statement->bindValue(':login', $login);
$statement->bindValue(':password', $password);
$res = $statement->execute();
$user = $res->fetchArray();
if (!$user) {
return null;
}
return new User($login, $user['admin'] ? true : false);
}
}