|
@@ 282-295 (lines=14) @@
|
| 279 |
|
* @param string $email |
| 280 |
|
* @throws Exception If couldn't reset failed logins |
| 281 |
|
*/ |
| 282 |
|
private function resetFailedLogins($email){ |
| 283 |
|
|
| 284 |
|
$database = Database::openConnection(); |
| 285 |
|
$query = "UPDATE failed_logins SET last_failed_login = NULL, " . |
| 286 |
|
"failed_login_attempts = 0 WHERE user_email = :user_email"; |
| 287 |
|
|
| 288 |
|
$database->prepare($query); |
| 289 |
|
$database->bindValue(':user_email', $email); |
| 290 |
|
$result = $database->execute(); |
| 291 |
|
|
| 292 |
|
if(!$result){ |
| 293 |
|
throw new Exception("Couldn't reset failed logins for User Email " . $email); |
| 294 |
|
} |
| 295 |
|
} |
| 296 |
|
|
| 297 |
|
/** |
| 298 |
|
* What if user forgot his password? |
|
@@ 494-507 (lines=14) @@
|
| 491 |
|
* @param integer $userId |
| 492 |
|
* @throws Exception If couldn't reset password token |
| 493 |
|
*/ |
| 494 |
|
private function resetPasswordToken($userId){ |
| 495 |
|
|
| 496 |
|
$database = Database::openConnection(); |
| 497 |
|
$query = "UPDATE forgotten_passwords SET password_token = NULL, " . |
| 498 |
|
"password_last_reset = NULL, forgotten_password_attempts = 0 ". |
| 499 |
|
"WHERE user_id = :user_id LIMIT 1"; |
| 500 |
|
|
| 501 |
|
$database->prepare($query); |
| 502 |
|
$database->bindValue(':user_id', $userId); |
| 503 |
|
$result = $database->execute(); |
| 504 |
|
if(!$result){ |
| 505 |
|
throw new Exception("Couldn't reset password token"); |
| 506 |
|
} |
| 507 |
|
} |
| 508 |
|
|
| 509 |
|
/** |
| 510 |
|
* It checks if the token for email verification is valid or not. |
|
@@ 574-592 (lines=19) @@
|
| 571 |
|
* @param boolean $isValid |
| 572 |
|
* @throws Exception If couldn't reset email verification token |
| 573 |
|
*/ |
| 574 |
|
public function resetEmailVerificationToken($userId, $isValid){ |
| 575 |
|
|
| 576 |
|
$database = Database::openConnection(); |
| 577 |
|
|
| 578 |
|
if($isValid){ |
| 579 |
|
$query = "UPDATE users SET email_token = NULL, " . |
| 580 |
|
"email_last_verification = NULL, is_email_activated = 1 ". |
| 581 |
|
"WHERE id = :id LIMIT 1"; |
| 582 |
|
}else{ |
| 583 |
|
$query = "DELETE FROM users WHERE id = :id"; |
| 584 |
|
} |
| 585 |
|
|
| 586 |
|
$database->prepare($query); |
| 587 |
|
$database->bindValue(':id', $userId); |
| 588 |
|
$result = $database->execute(); |
| 589 |
|
if(!$result){ |
| 590 |
|
throw new Exception("Couldn't reset email verification token"); |
| 591 |
|
} |
| 592 |
|
} |
| 593 |
|
|
| 594 |
|
/** |
| 595 |
|
* Logout by removing the Session and Cookies. |