<commit_before><?php

/*
 * This file is part of the Silex framework.
 *
 * Copyright (c) 2013 clover studio official account
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Silex\Application;

function abortManually($errMessage){
    $arr = array('message' => $errMessage, 'error' => 'logout');
    header("HTTP/1.0 403 Forbidden");
    echo json_encode($arr);
    die();
}

$beforeTokenCheker = function (Request $request, Application $app) {
    
    $tokenReceived = $request->headers->get('token');
    $useridReceived = $request->headers->get('user_id');
    
    if(empty($tokenReceived) || empty($useridReceived)){
     	abortManually("No token sent");
    }
    
    $query = "?key=" . urlencode('"' . $useridReceived . '"');
    $result = $app['spikadb']->doGetRequest("/_design/app/_view/find_user_by_id{$query}",false);
    $userData = json_decode($result, true);
    
    if(!isset($userData['rows'][0]['value']['_id']) || $userData['rows'][0]['value']['_id'] != $useridReceived){
	    abortManually("No token sent");
    }
    <commit_msg>fixed the problem create user didn't work<commit_after><?php

/*
 * This file is part of the Silex framework.
 *
 * Copyright (c) 2013 clover studio official account
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Silex\Application;

function abortManually($errMessage){
    $arr = array('message' => $errMessage, 'error' => 'logout');
    header("HTTP/1.0 403 Forbidden");
    echo json_encode($arr);
    die();
}

$beforeTokenCheker = function (Request $request, Application $app) {
    
    $tokenReceived = $request->headers->get('token');
    $useridReceived = $request->headers->get('user_id');
    $isCreateUserRequest = false;
    
    $app['monolog']->addDebug("token : {$tokenReceived}");
    $app['monolog']->addDebug("medhod : " . $request->getMethod());
    $app['monolog']->addDebug("user id : {$useridReceived}");

    if($request->getMethod() == "POST" && $useridReceived == "create_user"){
	    $isCreateUserRequest = true;
	    return;
    }
    
    if(empty($tokenReceived) || empty($useridReceived)){
     	abortManually("No token sent");
    }
    
    $query = "?key=" . urlencode('"' . $useridReceived . '"');
    $result = $app['spikadb']->doGetRequest("/_design/app/_view/find_user_by_id{$query}",false);
    $userData = json_decode($result, true);
    
    if(!isset($userData['rows'][0]['value']['_id']) || $userData['rows'][0]['value']['_id'] != $useridReceived){
	    abortManually("No token sent");
    }
    
{'fraction_non_alphanumeric': 0.17344456030587418, 'fraction_numerical': 0.0076468543621828295, 'mean_word_length': 4.2327272727272724, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, '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': '1313140', 'n_tokens_mistral': 904, 'n_tokens_neox': 892, 'n_words': 190}