<?php

namespace Shm\ShmAuth;

use Shm\ShmCmd\Cmd;
use Shm\ShmDB\mDB;
use Shm\ShmTypes\StructureType;
use Shm\ShmUtils\Response;
use Shm\ShmUtils\ShmTwig;

class AuthSessionRevoke
{

  public static function init()
  {

    //Если запрос пришел из CLI, то не меняем таймзону
    if (Cmd::cli()) {
      return;
    }


    $f3 = \Base::instance();


    $f3->route('GET /account/session/revoke/([a-f0-9]{128})', function ($f3) {


      $token = $f3->get('PARAMS[1]');

      mDB::_collection(Auth::$token_collection)->deleteOne([
        'cancelKey' => $token
      ]);

      $html = ShmTwig::render('@shm/session-revoked');
      Response::html($html);
    });
  }
}
