<commit_before><?php
/**
 * Created by anonymous on 05/12/15 9:00.
 */

namespace Onderdelen\JwtAuth\Controllers;

use Illuminate\Http\Request;
use JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
use Hash;
use Anwendungen\Application\Controller\Controller;
use Onderdelen\JwtAuth\Models\User;

/**
 * Class AuthenticateController
 * @package Onderdelen\JwtAuth\Controllers
 */
class AuthenticateController extends Controller
{
    public function __construct()
    {
        $this->middleware('jwt.auth', ['except' => ['authenticate']]);
    }

    /**
     * @return mixed
     */
    public function index()
    {
        $users = User::all();

        return response()->success($users);
    }

    /**
     * @param Request $request
     * @return mixed
     */
    public function authenticate(Request $request)
    {
        $credentials = $request->only('email', 'password');
        try {
            // verify the credentials and create a token for the user
            if (!$token = JWTAuth::attempt($credentials)) {
                return response()->error('invalid_credentials', 401);
            }
        } catch (JWTException $e) {
            // something went wrong
            return response()->error('could_not_create_token', 500);
        }

        // if no errors are encountered we can return a JWT
        return response()->success(compact('token'));
    }

    /**
     * @return \Illuminate\Http\JsonResponse
     */
    public function getAuthenticatedUser()
    {
        try {
            if (!$user = JWTAuth::parseToken()->authenticate()) {
                return response()->json(['user_not_found'], 404);
            }
        } catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
            return response()->error('token_expired', $e->getStatusCode());
        } catch (Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {
            return response()->error('token_invalid', $e->getStatusCode());
        } catch (Tymon\JWTAuth\Exceptions\JWTException $e) {
            return response()->error('token_absent', $e->getStatusCode());
        }

        // the token is valid and we have found the user via the sub claim
        return response()->success(compact('user'));
    }
}
<commit_msg>Modified AuthenticateController<commit_after><?php
/**
 * Created by anonymous on 05/12/15 9:00.
 */

namespace Onderdelen\JwtAuth\Controllers;

use Anwendungen\Application\Controller\Controller;
use Tymon\JWTAuth\Exceptions\JWTException;
use Onderdelen\JwtAuth\Models\User;
use Illuminate\Http\Request;
use JWTAuth;
use Hash;

/**
 * Class AuthenticateController
 *
 * @package Onderdelen\JwtAuth\Controllers
 */
class AuthenticateController extends Controller
{
    /**
     * construct
     */
    public function __construct()
    {
        $this->middleware('jwt.auth', ['except' => ['authenticate', 'signup']]);
    }

    /**
     * Return the user
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function index()
    {
        $users = User::all();
        return response()->success($users);
    }

    /**
     * Return a JWT
     *
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function authenticate(Request $request)
    {
        $credentials = $request->only('email', 'password');
        try {
            // verify the credentials and create a token for the user
            if (!$token = JWTAuth::attempt($credentials)) {
                return response()->json(['error' => 'invalid_credentials'], 401);
            }
        } catch (JWTException $e) {
            // something went wrong
            return response()->json(['error' => 'could_not_create_token'], 500);
        }

        // if no errors are encountered we can return a JWT
        return response()->json(compact('token'));
    }

    /**
     * Return the authenticated user
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function getAuthenticatedUser()
    {
        try {
            if (!$user = JWTAuth::parseToken()->authenticate()) {
                return response()->json(['user_not_found'], 404);
            }
        } catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
            return response()->json(['token_expired'], $e->getStatusCode());
        } catch (Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {
            return response()->json(['token_invalid'], $e->getStatusCode());
        } catch (Tymon\JWTAuth\Exceptions\JWTException $e) {
            return response()->json(['token_absent'], $e->getStatusCode());
        }

        // the token is valid and we have found the user via the sub claim
        return response()->json(compact('user'));
    }
}
{'fraction_non_alphanumeric': 0.13807708598051674, 'fraction_numerical': 0.007623888182973317, 'mean_word_length': 2.449963476990504, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '3942900', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1343, 'n_words': 295}