Example #1
0
 private function __construct()
 {
     $this->args = isset($_GET['arg']) ? explode('/', trim($_GET['arg'], '/')) : ['home'];
     $this->client = Client::getBy('name', 'Guest');
     $this->controller = ucfirst($this->args[0]) . "Ctrl";
     $this->method = $_SERVER['REQUEST_METHOD'];
 }
Example #2
0
 public static function create()
 {
     // TODO: Remplacer 'root' par '' en prod absolument !!
     $public_key = $_SERVER['HTTP_X_PUBLIC_KEY'] ?? 'root';
     // TODO: Remplacer 'hash_hmac(...)' par '' en prod absolument !!
     $received_hash = $_SERVER['HTTP_X_HASH'] ?? hash_hmac('sha256', 'root', 'root');
     if (Client::exists('public_key', $public_key)) {
         $client = Client::getBy('public_key', $public_key);
         $expected_hash = hash_hmac('sha256', $client->name, $client->private_key);
         if ($received_hash == $expected_hash) {
             $token = Token::generate();
             $ttl = 600;
             Token::insertIntoDb([$token, Utils::time(), $ttl, $client->id]);
             Data::get()->add('token', $token);
             return null;
         }
     }
     Data::get()->add('error', 'Wrong keypair');
 }