| @@ 100-105 (lines=6) @@ | ||
| 97 | ||
| 98 | // 2. validate only presence |
|
| 99 | $validation = new Validation(); |
|
| 100 | if(!$validation->validate([ |
|
| 101 | "Your Email" => [$email, 'required'], |
|
| 102 | "Your Password" => [$password, 'required']])){ |
|
| 103 | $this->errors = $validation->errors(); |
|
| 104 | return false; |
|
| 105 | } |
|
| 106 | ||
| 107 | // 3. check if user has previous failed login attempts |
|
| 108 | $database = Database::openConnection(); |
|
| @@ 117-121 (lines=5) @@ | ||
| 114 | ||
| 115 | // check if the failed login attempts exceeded limits |
|
| 116 | // @see Validation::attempts() |
|
| 117 | if(!$validation->validate([ |
|
| 118 | 'Failed Login' => [["last_time" => $last_time, "count" => $count], 'attempts']])){ |
|
| 119 | $this->errors = $validation->errors(); |
|
| 120 | return false; |
|
| 121 | } |
|
| 122 | ||
| 123 | // 4. get user from database |
|
| 124 | $database->prepare("SELECT * FROM users WHERE email = :email AND is_email_activated = 1 LIMIT 1"); |
|
| @@ 324-327 (lines=4) @@ | ||
| 321 | $last_time = isset($forgottenPassword["password_last_reset"])? $forgottenPassword["password_last_reset"]: null; |
|
| 322 | $count = isset($forgottenPassword["forgotten_password_attempts"])? $forgottenPassword["forgotten_password_attempts"]: null; |
|
| 323 | ||
| 324 | if(!$validation->validate(['Failed Login' => [["last_time" => $last_time, "count" => $count], 'attempts']])){ |
|
| 325 | $this->errors = $validation->errors(); |
|
| 326 | return false; |
|
| 327 | } |
|
| 328 | ||
| 329 | // You need to get the new password token from the database after updating/inserting it |
|
| 330 | $newPasswordToken = $this->generateForgottenPasswordToken($user["id"], $forgottenPassword); |
|
| @@ 461-466 (lines=6) @@ | ||
| 458 | public function updatePassword($userId, $password, $confirmPassword){ |
|
| 459 | ||
| 460 | $validation = new Validation(); |
|
| 461 | if(!$validation->validate([ |
|
| 462 | 'Password' => [$password, "required|equals(".$confirmPassword.")|minLen(6)|password"], |
|
| 463 | 'Password Confirmation' => [$confirmPassword, 'required']])){ |
|
| 464 | $this->errors = $validation->errors(); |
|
| 465 | return false; |
|
| 466 | } |
|
| 467 | ||
| 468 | $hashedPassword = password_hash($password, PASSWORD_DEFAULT, array('cost' => Config::get('HASH_COST_FACTOR'))); |
|
| 469 | $database = Database::openConnection(); |
|
| @@ 102-107 (lines=6) @@ | ||
| 99 | public function create($userId, $title, $content){ |
|
| 100 | ||
| 101 | $validation = new Validation(); |
|
| 102 | if(!$validation->validate([ |
|
| 103 | 'Title' => [$title, "required|minLen(2)|maxLen(60)"], |
|
| 104 | 'Content' => [$content, "required|minLen(4)|maxLen(1800)"]])) { |
|
| 105 | $this->errors = $validation->errors(); |
|
| 106 | return false; |
|
| 107 | } |
|
| 108 | ||
| 109 | $database = Database::openConnection(); |
|
| 110 | $query = "INSERT INTO posts (user_id, title, content) VALUES (:user_id, :title, :content)"; |
|
| @@ 140-145 (lines=6) @@ | ||
| 137 | public function update($postId, $title, $content){ |
|
| 138 | ||
| 139 | $validation = new Validation(); |
|
| 140 | if(!$validation->validate([ |
|
| 141 | 'Title' => [$title, "required|minLen(2)|maxLen(60)"], |
|
| 142 | 'Content' => [$content, "required|minLen(4)|maxLen(1800)"]])) { |
|
| 143 | $this->errors = $validation->errors(); |
|
| 144 | return false; |
|
| 145 | } |
|
| 146 | ||
| 147 | $database = Database::openConnection(); |
|
| 148 | $query = "UPDATE posts SET title = :title, content = :content WHERE id = :id LIMIT 1"; |
|