<commit_before><?php

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\ApiController;
use Illuminate\Http\Request;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
use Tymon\JWTAuth\Exceptions\TokenInvalidException;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\DB;
use Tymon\JWTAuth\JWTAuth;
use App\User;

class AuthController extends ApiController
{
    /**
     * @var \Tymon\JWTAuth\JWTAuth
     */
    protected $jwt;

    public function __construct(JWTAuth $jwt)
    {
        $this->jwt = $jwt;
    }

    /**
     * login
     *
     * @param Request $request
     * @return mixed
     */
    public function login(Request $request)
    {
        $this->validate($request, [
            'email'    => 'required|email|max:255',
            'password' => '<PASSWORD>'
        ]);

        try {
            if (! $token = $this->jwt->attempt($request->only('email', 'password'))) {
                return $this->respondWithError('User not found.');
            }
        } catch (TokenExpiredException $e) {
            return $this->respondWithUnauthorised($e->getMessage());
        } catch (TokenInvalidException $e) {
            return $this->respondWithUnauthorised($e->getMessage());<commit_msg>return error the same way as request validator in lumen would when failed attempt to login<commit_after><?php

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\ApiController;
use Illuminate\Http\Request;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
use Tymon\JWTAuth\Exceptions\TokenInvalidException;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\DB;
use Tymon\JWTAuth\JWTAuth;
use App\User;

class AuthController extends ApiController
{
    /**
     * @var \Tymon\JWTAuth\JWTAuth
     */
    protected $jwt;

    public function __construct(JWTAuth $jwt)
    {
        $this->jwt = $jwt;
    }

    /**
     * login
     *
     * @param Request $request
     * @return mixed
     */
    public function login(Request $request)
    {
        $this->validate($request, [
            'email'    => 'required|email|max:255',
            'password' => '<PASSWORD>'
        ]);

        try {
            if (! $token = $this->jwt->attempt($request->only('email', 'password'))) {
                // return error same way validation would.
                return $this->setStatusCode(422)->respond(['general' => ['No user found matching these credentials.']]);
            }
        } catch (TokenExpiredException $e) {
            return $this->respondWithUnauthorised($e->getMessage());
        } catch (TokenInvalidException $e) {
            return $this->respondWithUnauthorised($e->getMessage());
{'fraction_non_alphanumeric': 0.13210943124550037, 'fraction_numerical': 0.003959683225341973, 'mean_word_length': 2.695478723404255, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, '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': '5099138', 'n_tokens_mistral': 861, 'n_tokens_neox': 868, 'n_words': 162}