<commit_before><?php namespace App\Http\Controllers\API;
use App\Models\User;
use App\Models\Role;
use JWTAuth;
use Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Validator;
use Hash;
use Mail;
class AuthController extends Controller {
    /**
    * Authenticate a user
    *
    * @param  Request  $request
    * @return Response
    */
    public function login(Request $request)
    {
        $credentials = $request->only('email', 'password');
        $validator = Validator::make($credentials, [
            'email' => 'required|email',
            'password'   => '<PASSWORD>',
        ]);
        if ($validator->fails()) {
            return $validator->errors()->all();
        }
        else {
	        if (Auth::attempt(['email' => $request['email'], 'password' => $request['password']])) {
	            $roles = Auth::user()->roles()->get()->lists('name');
	            $token = JWTAuth::fromUser(Auth::user(),['exp' => strtotime('+1 year'),'roles'=>$roles, 'slug'=>Auth::user()->slug(), 'user_id'=>Auth::user()->id]);
	            return compact('token');
	        }
    	}
    	// Probably a better way to do this
		return response()->json(['error' => 'invalid_credentials'], 401);
    }

    /**
    * Register a user
    *
    * @param  Request  $request
    * @return Response
    */
    public function signUp(Request $request)
    {
        if(intval(config('app.phase')) < 2)
            return ['error'=>'applications are not open'];

        $validator = Validator::make($request->all(), [
            'email'   => 'required|email|unique:users',
            'password'    => '<PASSWORD>',
        ]);

        if ($validator->fails()) {
            return $validator->errors()->all();
        }
        else {
            $code = str_random(24);
            $user = new User;
            $user->password = <PASSWORD>($request['password']);
            $user->email = $request['email'];
            $user->confirmation_code = $code;
            $user->save();

            $user->postSignupActions(); // Attach roles

            $roles = $user->roles()->get()->lists('name');
            $token = JWTAuth::fromUser($user,['exp' => strtotime('+1 year'),'roles'=>$roles, 'slug'=>$user->slug(), 'user_id'=>$user->id]);

            $link = env('FRONTEND_ADDRESS')."/confirm?tok=".$code;
            Mail::send('emails.welcome', ['user' => $user,'link'=>$link], function ($message) use ($user,$link) {
    			$message->from('<EMAIL>', 'BoilerMake');
    			$message->to($user->email)->subject("Welcome to BoilerMake!");
			});
			
            return compact('token');
        }
    }

    /**
    * Confirm a user
    *
    * @param  Request  $request
    * @return Response
    */
    public function confirm(Request $request)
    {
        if(!isset($request->code))
            return response()->json(['error' => 'Code Required'], 401);
        $user = User::where('confirmation_code', $request->code)->where('confirmed', 0)->first();
        if($user) {
            $user->confirmed = 1;
            $user->save();
            return response()->json(['success' => 'Email Confirmed'], 200);
        }
        return response()->json(['error' => 'Invalid Code'], 401);
    }

	public function debug()
	{
		$user = JWTAuth::parseToken()->authenticate();
		return $user;
	}
}<commit_msg>temp fix for confirmation issues<commit_after><?php namespace App\Http\Controllers\API;
use App\Models\User;
use App\Models\Role;
use JWTAuth;
use Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Validator;
use Hash;
use Mail;
class AuthController extends Controller {
    /**
    * Authenticate a user
    *
    * @param  Request  $request
    * @return Response
    */
    public function login(Request $request)
    {
        $credentials = $request->only('email', 'password');
        $validator = Validator::make($credentials, [
            'email' => 'required|email',
            'password'   => '<PASSWORD>',
        ]);
        if ($validator->fails()) {
            return $validator->errors()->all();
        }
        else {
	        if (Auth::attempt(['email' => $request['email'], 'password' => $request['password']])) {
	            $roles = Auth::user()->roles()->get()->lists('name');
	            $token = JWTAuth::fromUser(Auth::user(),['exp' => strtotime('+1 year'),'roles'=>$roles, 'slug'=>Auth::user()->slug(), 'user_id'=>Auth::user()->id]);
	            return compact('token');
	        }
    	}
    	// Probably a better way to do this
		return response()->json(['error' => 'invalid_credentials'], 401);
    }

    /**
    * Register a user
    *
    * @param  Request  $request
    * @return Response
    */
    public function signUp(Request $request)
    {
        if(intval(config('app.phase')) < 2)
            return ['error'=>'applications are not open'];

        $validator = Validator::make($request->all(), [
            'email'   => 'required|email|unique:users',
            'password'    => '<PASSWORD>',
        ]);

        if ($validator->fails()) {
            return $validator->errors()->all();
        }
        else {
            $code = str_random(24);
            $user = new User;
            $user->password = <PASSWORD>($request['password']);
            $user->email = $request['email'];
            $user->confirmation_code = $code;
            $user->save();

            $user->postSignupActions(); // Attach roles

            $roles = $user->roles()->get()->lists('name');
            $token = JWTAuth::fromUser($user,['exp' => strtotime('+1 year'),'roles'=>$roles, 'slug'=>$user->slug(), 'user_id'=>$user->id]);

            $link = env('FRONTEND_ADDRESS')."/confirm?tok=".$code;
            Mail::send('emails.welcome', ['user' => $user,'link'=>$link], function ($message) use ($user,$link) {
    			$message->from('<EMAIL>', 'BoilerMake');
    			$message->to($user->email)->subject("Welcome to BoilerMake!");
			});
			
            return compact('token');
        }
    }

    /**
    * Confirm a user
    *
    * @param  Request  $request
    * @return Response
    */
    public function confirm(Request $request)
    {
        if(!isset($request->code))
            return response()->json(['error' => 'Code Required'], 401);
        $user = User::where('confirmation_code', $request->code)->first();
        if($user) {
            $user->confirmed = 1;
            $user->save();
            return response()->json(['success' => 'Email Confirmed'], 200);
        }
        return response()->json(['error' => 'Invalid Code'], 401);
    }

	public function debug()
	{
		$user = JWTAuth::parseToken()->authenticate();
		return $user;
	}
}
{'fraction_non_alphanumeric': 0.1942111577684463, 'fraction_numerical': 0.005548890221955609, 'mean_word_length': 2.407766990291262, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 128, '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': '2482998', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1969, 'n_words': 381}