public function __construct($request, $origin) { parent::__construct($request); // Abstracted out for example $APIKey = new Models\APIKey(); $User = new Models\User(); if (!array_key_exists('apiKey', $this->request)) { throw new Exception('No API Key provided'); } elseif (!$APIKey->verifyKey($this->request['apiKey'], $origin)) { throw new Exception('Invalid API Key'); } elseif (array_key_exists('token', $this->request) && !$User->get('token', $this->request['token'])) { throw new Exception('Invalid User Token'); } $this->User = $User; }
public function ban() { if (!isset($_SESSION['userId']) || $_SESSION['admin'] != true) { header('Location: /php_project/application/public/'); exit; } $user_id = $this->input->get(0); $userDb = new \Models\User(); $user = $userDb->get('user_id = ' . $user_id); if (!is_numeric($user_id) || !$user) { header('Location: /php_project/application/public/'); exit; } $userUpdate = array(); $userUpdate['banned'] = 1; $userUpdate['user_id'] = $user_id; $userDb->update('user', $userUpdate); header('Location: /php_project/application/public/admin/index'); exit; }
private function getUser() { $userDb = new \Models\User(); $this->user = $userDb->get('user_id = ' . $_SESSION['userId']); }