<commit_before><?php
// config file
@require 'config/config.php';
// loader
@require 'config/loader.php';

// Phalcon API
use Phalcon\Mvc\Micro;
use \Firebase\JWT\ExpiredException;
use \Firebase\JWT\JWT;

$app = new Micro($di);
$app->notFound(function () use ($app){
  $app->response->setStatusCode(404, "Not Found")->sendHeaders();
});

$app->before(function() use ($app) {
  if(!in_array($app->router->getRewriteUri(), $app->routerignore)){
    if(!$app->request->getHeader('Authorization')){
      $app->response->setStatusCode(403, 'Unauthorized');
      $app->response->setContent('You have no rights');
      $app->response->send();
      return false;
    }else{
      try{
        JWT::decode($app->request->getHeader('Authorization'), $app->jwt->secret, $app->jwt->type);
      }catch(ExpiredException $e){
        $app->response->setJsonContent(array('error'=>'Expired token'));
      }
      return $app->response;
    }
  }
  return true;
});

$app->post('/api/auth', function() use ($app){
  $params = $app->request->getJsonRawBody();
  if(!isset($params)) $params = $_POST;
  //error_log(print_r($params, true));
  $app->response->setJsonContent(array('error'=>'No params'));
  if(isset($params)){
    // try login
    if($params['email'] == '<EMAIL>' && $params['pwd'] == <PASSWORD>('<PASSWORD>')){
      $user = (object) array(
        "iat" => 1356999524,
        "nbf" => 1357000000
      );
      $user->name = '<NAME>';
      $user->email = '<EMAIL>';
      $app->response->setJsonContent(array('token'=> JWT::encode($user, $app->jwt->secret)));
      //$app->response->setJsonContent(array('token'=> $user));
    }else{
      $app->response->setJsonContent(array('error'=>'Email or Password not match'));
    }
  }
  return $app->response;
});

$app->error(
  function (Exception $e) {
    echo $e->getMessage();
  }
);
<commit_msg>Success with wrong token fixed<commit_after><?php
// config file
@require 'config/config.php';
// loader
@require 'config/loader.php';

// Phalcon API
use Phalcon\Mvc\Micro;
use \Firebase\JWT\ExpiredException;
use \Firebase\JWT\JWT;

$app = new Micro($di);
$app->notFound(function () use ($app){
  $app->response->setStatusCode(404, "Not Found")->sendHeaders();
});

$app->before(function() use ($app) {
  if(!in_array($app->router->getRewriteUri(), $app->routerignore)){
    if(!$app->request->getHeader('Authorization')){
      $app->response->setStatusCode(403, 'Unauthorized');
      $app->response->setContent('You have no rights');
      $app->response->send();
      return false;
    }else{
      try{
        JWT::decode($app->request->getHeader('Authorization'), $app->jwt->secret, $app->jwt->type);
      }catch(Exception $e){
        $app->response->setJsonContent(array('error'=>'Expired token'));
        $app->response->send();
        return false;
      }
    }
  }
  return true;
});

$app->post('/api/auth', function() use ($app){
  $params = $app->request->getJsonRawBody();
  if(!isset($params)) $params = $_POST;
  //error_log(print_r($params, true));
  $app->response->setJsonContent(array('error'=>'No params'));
  if(isset($params)){
    // try login
    if($params['email'] == '<EMAIL>' && $params['pwd'] == md5('<PASSWORD>')){
      $user = (object) array(
        "iat" => 1356999524,
        "nbf" => 1357000000
      );
      $user->name = '<NAME>';
      $user->email = '<EMAIL>';
      $app->response->setJsonContent(array('token'=> JWT::encode($user, $app->jwt->secret)));
      //$app->response->setJsonContent(array('token'=> $user));
    }else{
      $app->response->setJsonContent(array('error'=>'Email or Password not match'));
    }
  }
  return $app->response;
});

$app->get('/api/user', function() use ($app){
  $app->response->setJsonContent(array('result'=>array('foo', 'bar')));
  return $app->response;
});

$app->error(
  function (Exception $e) {
    echo $e->getMessage();
  }
);

{'fraction_non_alphanumeric': 0.22720247295208656, 'fraction_numerical': 0.013652756311179804, 'mean_word_length': 3.7997527812113723, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 118, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5651145', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1302, 'n_words': 219}