1 | <?php |
||
5 | class UserService |
||
6 | { |
||
7 | private $userStorage; |
||
8 | private $session; |
||
9 | |||
10 | |||
11 | |||
12 | /** |
||
13 | * Constructor for UserService |
||
14 | * @param object $di dependency injection. |
||
15 | */ |
||
16 | 9 | public function __construct($di) |
|
22 | |||
23 | |||
24 | |||
25 | /** |
||
26 | * Create user. |
||
27 | * |
||
28 | * @param object $user User object to store. |
||
29 | * @return void |
||
30 | */ |
||
31 | 1 | public function createUser($user) |
|
41 | |||
42 | |||
43 | |||
44 | /** |
||
45 | * Update user. |
||
46 | * |
||
47 | * @param object $user User object to update. |
||
48 | * @return void |
||
49 | */ |
||
50 | 2 | public function updateUser($user) |
|
54 | |||
55 | |||
56 | |||
57 | /** |
||
58 | * Delete user. Validates if user is admin to be able to delete |
||
59 | * |
||
60 | * @param integer $id user id. |
||
61 | * |
||
62 | * @return boolean |
||
63 | */ |
||
64 | 2 | public function deleteUser($id) |
|
71 | |||
72 | |||
73 | |||
74 | /** |
||
75 | * Dynamicly get user by propertie. |
||
76 | * |
||
77 | * @param string $field field to search by. |
||
78 | * |
||
79 | * @param array $data to search for. |
||
80 | * |
||
81 | * @return User |
||
82 | * |
||
83 | */ |
||
84 | 10 | public function getUserByField($field, $data) |
|
98 | |||
99 | |||
100 | |||
101 | /** |
||
102 | * Find all users stored. |
||
103 | * |
||
104 | * @return array Of users |
||
105 | */ |
||
106 | 2 | public function findAllUsers() |
|
110 | |||
111 | |||
112 | |||
113 | /** |
||
114 | * Check if user is logged in. |
||
115 | * |
||
116 | * @return boolean |
||
117 | */ |
||
118 | 2 | public function checkLoggedin() |
|
122 | |||
123 | |||
124 | |||
125 | /** |
||
126 | * Login user and redirect to admin. |
||
127 | * |
||
128 | * @return boolean |
||
129 | */ |
||
130 | 2 | public function login($username, $password) |
|
156 | |||
157 | |||
158 | |||
159 | /** |
||
160 | * Check if a user is logged in and returns that user |
||
161 | * |
||
162 | * @return obj user or null |
||
163 | */ |
||
164 | 6 | public function getCurrentLoggedInUser() |
|
168 | |||
169 | |||
170 | |||
171 | /** |
||
172 | * Validate pasword |
||
173 | * |
||
174 | * @method password_verify Method to verify password |
||
175 | * |
||
176 | * @param string $password Password to be validated. |
||
177 | * |
||
178 | * @return boolean Return true if valid else false. |
||
179 | */ |
||
180 | 1 | private function validatePassword($password, $dbpassword) |
|
184 | |||
185 | |||
186 | |||
187 | /** |
||
188 | * Check if logged in user is valid and admin. |
||
189 | * |
||
190 | * @return boolean Returns true or false if user is valid administrator. |
||
191 | */ |
||
192 | 2 | public function validLoggedInAdmin() |
|
203 | |||
204 | |||
205 | |||
206 | /** |
||
207 | * Generate gravatar from email or return default avatar. |
||
208 | * |
||
209 | * @param string $email email adress |
||
210 | * @return string Gravatar url. |
||
211 | */ |
||
212 | 1 | public function generateGravatarUrl($email = "") |
|
219 | } |
||
220 |