Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $userId = User::checkUserData($email, $password);
- public function actionLogin() {
- $email = '';
- $password = '';
- if (isset($_POST['submit'])) {
- $email = $_POST['email'];
- $password = $_POST['password'];
- $errors = false;
- $userId = User::checkUserData($email, $password);
- if ($userId == false) {
- $errors[] = "Неверные E-mail или пароль.";
- }
- else {
- User::auth($userId);
- header("Location: /cabinet/");
- }
- }
- require_once ROOT.'/views/user/login.php';
- return true;
- }
- public static function checkUserData($email, $password) {
- $db = Db::getConnection();
- $sql = "SELECT * FROM user WHERE email = :email AND password = :password";
- $result = $db->prepare($sql);
- $result->bindParam(':email', $email, PDO::PARAM_STR);
- $result->bindParam(':password', $password, PDO::PARAM_STR);
- $result->execute();
- $user = $result->fetch();
- if ($user) {
- return $user['id'];
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement