private function get_update_token() { $is_token_valid = false; try { $is_token_valid = $this->token->exists() && $this->token->read() == self::$token_file_content; } catch (IOException $ioe) { $is_token_valid = false; } if (!$is_token_valid) { throw new TokenNotFoundException($this->token->get_path_from_root()); } }
private function generate_token() { $length = 32; $value = ''; $keys = array_merge(range(0, 9), range('a', 'f')); for ($i = 0; $i < $length; $i++) { $value .= $keys[array_rand($keys)]; } $check = new Token(); $check->where('value', $value)->get(); if ($check->exists()) { $token = $this->generate_token(); } $token = new Token(); $token->value = $value; return $token; }
public function all_get($token) { $token_entry = new Token(); $token_entry->get_by_valid_token($token)->get(); if ($token_entry->exists()) { $settings = new Setting(); $settings->get(); $response = new stdClass(); $response->status = true; $response->settings = new stdClass(); foreach ($settings as $setting) { $response->settings->{$setting->setting_key} = $setting->setting_value; } $this->response($response); } else { $response = new stdClass(); $response->status = false; $response->error = 'Token not found or session expired'; $this->response($response); } }
public function weekTotal_get($token) { //YEARWEEK(FROM_UNIXTIME(stop_time)) = YEARWEEK(CURRENT_DATE) $token_entry = new Token(); $token_entry->get_by_valid_token($token)->get(); $response = new stdClass(); if ($token_entry->exists()) { //TODO $timer_entries = new Timer_entry(); //Selecting the entry $timer_entries->getThisWeek()->where('active', 0)->select_sum('(stop_time - start_time)', 'totalTime')->get(); $response->status = true; $response->totalThisWeek = 0; if ($timer_entries->exists()) { if (!$timer_entries->totalTime) { $response->totalThisWeek = from_unix_timespan_to_string(0); } $response->totalThisWeek = from_unix_timespan_to_string($timer_entries->totalTime); } } else { $response->status = false; $response->error = 'Token not found or session expired'; } $this->response($response); }
public function user_delete($id, $token) { $token_entry = new Token(); $token_entry->get_by_valid_token($token)->get(); $response = new stdClass(); if ($token_entry->exists() && $token_entry->user->get()->is_admin) { if ($token_entry->user_id != $id) { $user = new User(); $user->get_by_id($id); $user->delete(); $response->status = TRUE; $this->response($response); } else { $response->status = FALSE; $response->error = 'Cannot delete active user!'; $this->response($response); } } else { $response->status = FALSE; $response->error = 'Token not found, not an admin or session expired'; $this->response($response); } }
require_once System::get()->getSystem() . 'Model.php'; require_once System::get()->getSystem() . 'Entry.php'; require_once System::get()->getSystem() . 'Utils.php'; require_once System::get()->getSystem() . 'Request.php'; require_once System::get()->getSystem() . 'Data.php'; require_once System::get()->getSystem() . 'HTTPError.php'; // Models require_once System::get()->getModels() . 'Client.php'; require_once System::get()->getModels() . 'Controller.php'; require_once System::get()->getModels() . 'Permission.php'; require_once System::get()->getModels() . 'Rank.php'; require_once System::get()->getModels() . 'Token.php'; Token::flush(); // TODO: Remplacer 'root' par '' en prod absolument !! $tokenString = $_SERVER['HTTP_X_TOKEN'] ?? 'root'; if (Token::exists('token', $tokenString)) { $token = Token::getBy('token', $tokenString); Request::get()->setClient(new Client($token->client_id)); } $controller = Controller::getBy('uri', Request::get()->getArg(0)); $filename = System::get()->getControllers() . $controller->uri . '.php'; $classname = ucfirst($controller->uri) . "Ctrl"; if (!file_exists($filename)) { HTTPError::NotFound(); exit; } if (!in_array(Request::get()->getMethod(), array('GET', 'POST'))) { parse_str(file_get_contents('php://input'), $_POST); } require_once System::get()->getSystem() . 'ControllerInterface.php'; require_once $filename;
/** * Create a new project * @route POST projects/ */ public function index_post() { $token_entry = new Token(); $token_entry->get_by_valid_token($this->post('token'))->get(); $response = new stdClass(); if ($token_entry->exists()) { $project = new Project(); $project->name = $this->post('name'); $project->customer_id = $this->post('customer_id'); if ($project->save()) { $response->status = true; } else { $response->status = false; $response->error = 'Project not saved!'; } } else { $response->status = false; $response->error = 'Token not found or session expired'; } $this->response($response); }