public function index() { $authProvider = new GoogleAuthProvider($_GET, ["client_id" => $this->config["GOOGLE_OAUTH_ID"], "client_secret" => $this->config["GOOGLE_OAUTH_SECRET"], "redirect_uri" => $this->config["REDIRECT_URI"]]); $oauth = new OAuth($authProvider, $_GET); $check = $oauth->check(); if ($check === true) { $email = $authProvider->getEmail(); /** @var Users $user */ $users = Users::getByField("email", $email); if (count($users) == 0) { echo $this->accessDenied(); return; } $user = $users[0]; $this->session->data = json_encode(["userId" => $user->id]); $this->session->save(); $this->sessionData = $this->session->data; header("Location: /kritbit"); } else { header("Location: " . $check); } }
protected function isUserLoggedIn() { if (isset($_COOKIE["session"])) { $validSession = Sessions::getByField("sessionid", $_COOKIE["session"]); if ($validSession) { try { $this->session = $validSession[0]; $this->sessionData = json_decode($this->session->data); if ($this->sessionData == null) { return false; } $this->user = \application\models\Users::getByField("id", $this->sessionData->userId)[0]; return true; } catch (\Exception $e) { return false; } } else { return false; } } return false; }