connect()->prepare($sql); $stmt->execute([$userInfo[0]]); $row = $stmt->fetch(); if(isset($_POST['email'])) { if($row) { if($row['password'] == null) { if($row['googleID'] != null) echo "google user doesn't have password set up"; else if($row['facebookID'] != null) echo "facebook user doesn't have password set up"; else if($row['githubID'] != null) echo "github user doesn't have password set up"; } else echo 'user exists'; } else echo "user doesn't exist"; return; } } public function login($userInfo) { if(!filter_var($userInfo[0], FILTER_VALIDATE_EMAIL)) { echo 'error email'; return; } $sql = 'SELECT * FROM users WHERE email = ?'; $stmt = $this->connect()->prepare($sql); $stmt->execute([$userInfo[0]]); $row = $stmt->fetch(); if(password_verify($userInfo[1], $row['password'])) { include_once 'session.inc.php'; $session = new Session(); $session->setSession($userInfo[0]); echo 'success'; } else echo 'wrong password'; } public function pswSet() { if (session_status() == PHP_SESSION_NONE) session_start(); $string = ''; if($_SESSION['password-set'] != 'Not set') { $string = '
'; } echo $string.'
Back
Next
'; die; } public function isIdSet() { if(isset($_SESSION['email'])) echo 'je'; else echo 'ni'; die; } public function newsSaveArticle($title) { $sql = 'SELECT * FROM news n INNER JOIN saved_news sn ON n.id = sn.news_id INNER JOIN users u ON u.id = sn.user_id WHERE n.title = ?'; $stmt = $this->connect()->prepare($sql); $stmt->execute([$title]); $row = $stmt->fetch(); if($row) echo 'saved'; else echo 'not saved'; } } $checkObj = new Check(); if($_SERVER['REQUEST_METHOD'] !== 'POST') return; if(isset($_POST['email'])) $checkObj->email(json_decode($_POST['email'])); else if(isset($_POST['login'])) $checkObj->login(json_decode($_POST['login'])); else if(isset($_POST['pswSet'])) $checkObj->pswSet(); else if(isset($_POST['isIdSet'])) $checkObj->isIdSet(); else if(isset($_POST['newsSaveArticle'])) $checkObj->newsSaveArticle($_POST['newsSaveArticle']);