1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nicklas\Comment\Modules; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* A database driven model. |
7
|
|
|
*/ |
8
|
|
|
class User extends ActiveRecordModelExtender |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var string $tableName name of the database table. |
13
|
|
|
*/ |
14
|
|
|
protected $tableName = "ramverk1_users"; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Columns in the table. |
18
|
|
|
* |
19
|
|
|
* @var integer $id primary key auto incremented. |
20
|
|
|
*/ |
21
|
|
|
public $id; |
22
|
|
|
public $name; |
23
|
|
|
public $email; |
24
|
|
|
public $pass; |
25
|
|
|
public $authority = "user"; |
26
|
|
|
public $question; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Check if user exists |
30
|
|
|
* |
31
|
|
|
* @param string $name |
32
|
|
|
* |
33
|
|
|
* @return boolean true if user exists in database else false |
34
|
|
|
*/ |
35
|
1 |
|
public function userExists($name) |
36
|
|
|
{ |
37
|
1 |
|
$user = $this->find("name", $name); |
38
|
1 |
|
return !$user ? false : true; |
39
|
|
|
} |
40
|
|
|
/** |
41
|
|
|
* Returns gravatar link |
42
|
|
|
* |
43
|
|
|
* @param string $email |
|
|
|
|
44
|
|
|
* |
45
|
|
|
* @return string as gravatar link |
46
|
|
|
*/ |
47
|
5 |
|
public function setGravatar() |
48
|
|
|
{ |
49
|
5 |
|
$this->img = $this->gravatar($this->email); |
|
|
|
|
50
|
5 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Returns gravatar link |
54
|
|
|
* |
55
|
|
|
* @param string $name |
56
|
|
|
* |
57
|
|
|
* @return string as gravatar link |
58
|
|
|
*/ |
59
|
4 |
|
public function getGravatar($name) |
60
|
|
|
{ |
61
|
4 |
|
$this->find("name", $name); |
62
|
4 |
|
return $this->gravatar($this->email); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Set the pass. |
70
|
|
|
* |
71
|
|
|
* @param string $pass the pass to use. |
72
|
|
|
* |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
5 |
|
public function setPassword($pass) |
76
|
|
|
{ |
77
|
5 |
|
$this->pass = password_hash($pass, PASSWORD_DEFAULT); |
78
|
5 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Verify the name and the pass, if successful the object contains |
82
|
|
|
* all details from the database row. |
83
|
|
|
* |
84
|
|
|
* @param string $name name to check. |
85
|
|
|
* @param string $pass the pass to use. |
86
|
|
|
* |
87
|
|
|
* @return boolean true if name and pass matches, else false. |
88
|
|
|
*/ |
89
|
3 |
|
public function verifyPassword($name, $pass) |
90
|
|
|
{ |
91
|
3 |
|
$this->find("name", $name); |
92
|
3 |
|
return password_verify($pass, $this->pass); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Verify the name and the anaswer, if successful the object contains |
97
|
|
|
* all details from the database row. |
98
|
|
|
* |
99
|
|
|
* @param string $name name to check. |
100
|
|
|
* @param string $answer the answer. |
101
|
|
|
* |
102
|
|
|
* @return boolean true if name and pass matches, else false. |
103
|
|
|
*/ |
104
|
1 |
|
public function verifyQuestion($name, $answer) |
105
|
|
|
{ |
106
|
1 |
|
$this->find("name", $name); |
107
|
1 |
|
return ($this->question == $answer); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Check if a post belongs to user |
113
|
|
|
* |
114
|
|
|
* |
115
|
|
|
* @return boolean |
116
|
|
|
*/ |
117
|
1 |
|
public function controlAuthority($loggedUser, $name) |
118
|
|
|
{ |
119
|
1 |
|
$this->find("name", $loggedUser); |
120
|
|
|
// IF AUTHORITY == admin, then continue |
121
|
1 |
|
if ($this->authority != "admin") { |
122
|
1 |
|
return ($this->name == $name); |
123
|
|
|
} |
124
|
1 |
|
return true; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.