Advertisement
Guest User

Untitled

a guest
Feb 8th, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. $userId = User::checkUserData($email, $password);
  2.  
  3. public function actionLogin() {
  4.  
  5. $email = '';
  6. $password = '';
  7.  
  8. if (isset($_POST['submit'])) {
  9. $email = $_POST['email'];
  10. $password = $_POST['password'];
  11.  
  12. $errors = false;
  13.  
  14. $userId = User::checkUserData($email, $password);
  15.  
  16. if ($userId == false) {
  17. $errors[] = "Неверные E-mail или пароль.";
  18. }
  19. else {
  20. User::auth($userId);
  21.  
  22. header("Location: /cabinet/");
  23. }
  24. }
  25.  
  26. require_once ROOT.'/views/user/login.php';
  27.  
  28. return true;
  29.  
  30. }
  31.  
  32. public static function checkUserData($email, $password) {
  33.  
  34. $db = Db::getConnection();
  35.  
  36. $sql = "SELECT * FROM user WHERE email = :email AND password = :password";
  37.  
  38. $result = $db->prepare($sql);
  39. $result->bindParam(':email', $email, PDO::PARAM_STR);
  40. $result->bindParam(':password', $password, PDO::PARAM_STR);
  41. $result->execute();
  42.  
  43. $user = $result->fetch();
  44. if ($user) {
  45. return $user['id'];
  46. }
  47.  
  48. return false;
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement