<commit_before><?php

namespace Controllers\Sso;

use \Models\Sso\Token;
use \Auth;
use \Request;
use \Redirect;
use \Response;
use \Input;

class Authentication extends \Controllers\BaseController {
    public function getLogin(){
        // Did we receive a token?  If we didn't get rid of them!
        if(!Input::get("token", false)){
            die("SOME GENERIC ERROR");
        }

        // Check expired/invalid
        $ssoToken = Input::get("token");
        try {
            $ssoToken = Token::where("token", "=", $ssoToken)->firstOrFail();
        } catch(Exception $e){
            die("TOKEN NOT FOUND");
        }

        // Got the token, let's do something.
        if(!Request::query("return")){
            // Let's extend the expiry of this token for a minute or two....
            $ssoToken->expires_at = \Carbon\Carbon::now("GMT")->addMinutes(3)->toDateTimeString();
            $ssoToken->save();

            // Now let's send them off to the login shizzle!
            return Redirect::to("/mship/auth/login?returnURL=".urlencode(url("/sso/auth/login?token=".Request::query("token")."&return=1")));
        } else {
            // We're successfully authenticated it seems... We can now return the access token.
            $ssoToken->account_id = Auth::user()->get()->account_id;
            $ssoToken->expires_at = \Carbon\Carbon::now("GMT")->addSeconds(30)->toDateTimeString();
            $ssoToken->save();

            return Redirect::to($ssoToken->return_url);
        }
    }
}<commit_msg>Fix failed catching of ModelNotFoundException<commit_after><?php

namespace Controllers\Sso;

use \Models\Sso\Token;
use \Auth;
use \Request;
use \Redirect;
use \Response;
use \Input;
use Illuminate\Database\Eloquent\ModelNotFoundException;

class Authentication extends \Controllers\BaseController {
    public function getLogin(){
        // Did we receive a token?  If we didn't get rid of them!
        if(!Input::get("token", false)){
            die("SOME GENERIC ERROR");
        }

        // Check expired/invalid
        $ssoToken = Input::get("token");
        try {
            $ssoToken = Token::where("token", "=", $ssoToken)->firstOrFail();
        } catch (ModelNotFoundException $e) {
            die("TOKEN NOT FOUND");
        }

        // Got the token, let's do something.
        if(!Request::query("return")){
            // Let's extend the expiry of this token for a minute or two....
            $ssoToken->expires_at = \Carbon\Carbon::now("GMT")->addMinutes(3)->toDateTimeString();
            $ssoToken->save();

            // Now let's send them off to the login shizzle!
            return Redirect::to("/mship/auth/login?returnURL=".urlencode(url("/sso/auth/login?token=".Request::query("token")."&return=1")));
        } else {
            // We're successfully authenticated it seems... We can now return the access token.
            $ssoToken->account_id = Auth::user()->get()->account_id;
            $ssoToken->expires_at = \Carbon\Carbon::now("GMT")->addSeconds(30)->toDateTimeString();
            $ssoToken->save();

            return Redirect::to($ssoToken->return_url);
        }
    }
}
{'fraction_non_alphanumeric': 0.1550632911392405, 'fraction_numerical': 0.002531645569620253, 'mean_word_length': 2.443355119825708, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '7043505', 'n_tokens_mistral': 947, 'n_tokens_neox': 925, 'n_words': 217}