1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: root |
5
|
|
|
* Date: 2017-09-27 |
6
|
|
|
* Time: 10:27 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Radchasay\User; |
10
|
|
|
|
11
|
|
|
use \Anax\Database\ActiveRecordModel; |
12
|
|
|
|
13
|
|
|
class User extends ActiveRecordModel |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string $tableName name of the database table. |
18
|
|
|
*/ |
19
|
|
|
protected $tableName = "Users"; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Columns in the table. |
23
|
|
|
* |
24
|
|
|
* @var integer $id primary key auto incremented. |
25
|
|
|
*/ |
26
|
|
|
public $id; |
27
|
|
|
public $name; |
28
|
|
|
public $email; |
29
|
|
|
public $age; |
30
|
|
|
public $password; |
31
|
|
|
public $created; |
32
|
|
|
public $updated; |
33
|
|
|
public $deleted; |
34
|
|
|
public $active; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Set the password. |
39
|
|
|
* |
40
|
|
|
* @param string $password the password to use. |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function setPassword($password) |
45
|
|
|
{ |
46
|
|
|
$this->password = password_hash($password, PASSWORD_DEFAULT); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Verify the email and the password, if successful the object contains |
52
|
|
|
* all details from the database row. |
53
|
|
|
* |
54
|
|
|
* @param $email |
55
|
|
|
* @param string $password the password to use. |
56
|
|
|
* @return bool true if email and password matches, else false. |
57
|
|
|
* @internal param string $email email to check. |
58
|
|
|
*/ |
59
|
|
|
public function verifyPassword($email, $password) |
60
|
|
|
{ |
61
|
|
|
$this->find("email", $email); |
62
|
|
|
return password_verify($password, $this->password); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getInformation($email) |
66
|
|
|
{ |
67
|
|
|
$res = $this->find("email", $email); |
68
|
|
|
return $res; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getInformationById($id) |
72
|
|
|
{ |
73
|
|
|
$res = $this->find("id", $id); |
74
|
|
|
return $res; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getInformationLimit($number) |
78
|
|
|
{ |
79
|
|
|
$res = $this->findAllLimit($number); |
80
|
|
|
return $res; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function returnPermissions($email) |
84
|
|
|
{ |
85
|
|
|
$userInfo = $this->find("email", $email); |
86
|
|
|
$permissions = $userInfo->permissions; |
87
|
|
|
return $permissions; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function checkUserExists($email) |
91
|
|
|
{ |
92
|
|
|
$res = $this->find("email", $email); |
93
|
|
|
return !$res ? true : false; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|