-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadminModel.php
57 lines (43 loc) · 1.29 KB
/
adminModel.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
<?php
class adminModel{
protected $dbCon;
public function __construct()
{
global $config;
$database=$config['database'];
$dbdriver=$database['driver'];
$dbname=$database['name'];
$dbUser=$database['user'];
$dbPass=$database['password'];
$this->dbCon=database::getInstance($dbdriver,$dbname,$dbUser,$dbPass);
}
protected function getAdmin($username,$token){
//check with db if token is correct
$sql = "SELECT password, username FROM `admin_login` WHERE token = ? and username = ? ";
return $this->dbCon->crudQuery($sql,[$token,$username])[0];
}
public function loginTokenCheck($token)
{
//check with db if token is correct
$sql = "SELECT * FROM `admin_login` WHERE token = ? ";
$result=$this->dbCon->crudQuery($sql,[$token]);
if(empty($result)){
return false;
}
return true;
}
public function adminLogin($username, $password,$loginToken){
$admin=$this->getAdmin($username,$loginToken);
if(empty($admin)){
return false;
}//check if the user it match
$hash= $admin['password'];
if(password_verify($password,$hash)!=true){
return false;
}
//start session if the admin is right
//start session
$_SESSION['adminLogIn'] = $loginToken;
return true;
}
}