/**
  * Logs the user in by supplying a username and a login token
  */
 public function sso_server(Request $request)
 {
     $ckey_in = NULL;
     $token_in = NULL;
     $location = NULL;
     //Get the token and the ckey from the request
     $ckey_in = $request->input('ckey');
     $token_in = $request->input('token');
     $location = $request->input('location');
     $user_ip = $_SERVER['REMOTE_ADDR'];
     if ($ckey_in == NULL | $token_in == NULL) {
         abort(404);
     }
     //Check if a sso entry for the ckey and token exists
     $valid_until = Carbon::now();
     $valid_until->subHours(config('aurora.token_valid_time'));
     $count = DB::connection('server')->table('web_sso')->where('ckey', $ckey_in)->where('token', $token_in)->where('ip', $user_ip)->where('created_at', '>', $valid_until->toDateTimeString())->count();
     if ($count == 0) {
         abort(404);
     }
     //Check if a user with a linked byond account exists in the forum db
     $user = ForumUserModel::where('user_byond', $ckey_in)->first();
     if ($user == NULL) {
         return view('errors.no_user_linked', array('ckey' => $ckey_in));
     }
     //Auth the user
     Auth::login($user);
     //Delete the sso entry from the db
     DB::connection('server')->table('web_sso')->where('ckey', $ckey_in)->delete();
     //Redirect User to Destination
     switch ($location) {
         case "user_dashboard":
             return redirect()->route('user.dashboard');
             break;
         case "contract_overview":
             return redirect()->route('syndie.contracts.index');
             break;
         case "contract_details":
             return redirect()->route('syndie.contracts.show', ['contract' => $request->input('contract')]);
             break;
         case "security_incident":
             return redirect()->route('server.incidents.show.get', ['contract' => $request->input('incident')]);
             break;
         default:
             return redirect()->route('user.dashboard');
             break;
     }
 }
 /**
  * Retrieve a user by by their unique identifier and "remember me" token.
  *
  * @param  mixed  $identifier
  * @param  string $token
  *
  * @return \Illuminate\Contracts\Auth\Authenticatable|null
  */
 public function retrieveByToken($identifier, $token)
 {
     if ($this->use_remember_me == TRUE) {
         $qry = ForumUserModel::where('username_clean', '=', strtolower($identifier))->where('wi_remember_token', '=', $token);
         if ($qry->count() > 0) {
             $user = $qry->select('user_id', 'username', 'username_clean', 'user_password', 'user_email', 'user_byond', 'user_byond_linked')->first();
             if ($this->log_logins) {
                 Log::debug('login.retrievebytoken.success', ['username_clean' => strtolower($identifier)]);
             }
             return $user;
         }
         if ($this->log_logins) {
             Log::debug('login.retrievebytoken.fail', ['username_clean' => strtolower($identifier)]);
         }
     }
     if ($this->log_logins) {
         Log::debug('login.retrievebytoken.disabled', ['username_clean' => strtolower($identifier)]);
     }
     return NULL;
 }
 public function retrieveByCredentials(array $credentials)
 {
     $qry = ForumUser::where('username_clean', '=', strtolower($credentials['username']));
     if ($qry->count() > 0) {
         $user = $qry->select('user_id', 'username', 'username_clean', 'user_password', 'user_email', 'user_new_privmsg', 'user_unread_privmsg', 'user_byond', 'user_byond_linked')->first();
         if ($this->log_logins) {
             Log::debug('login.retrievebycredentials.success', ['username_clean' => strtolower($credentials['username'])]);
         }
         return $user;
     }
     if ($this->log_logins) {
         Log::debug('login.retrievebycredentials.fail', ['username_clean' => strtolower($credentials['username'])]);
     }
     return NULL;
 }
 /**
  * Logs the user in by supplying a username and a login token
  */
 public function sso_server(Request $request)
 {
     $ckey_in = NULL;
     $token_in = NULL;
     $location = NULL;
     //Get the token and the ckey from the request
     $ckey_in = $request->input('ckey');
     $token_in = $request->input('token');
     $location = $request->input('location');
     $user_ip = $_SERVER['REMOTE_ADDR'];
     if (Auth::check()) {
         $this->redirect_after_sso($location, $request);
     }
     if ($ckey_in == NULL | $token_in == NULL) {
         abort(404);
     }
     //Check if a sso entry for the ckey and token exists
     $valid_until = Carbon::now();
     $valid_until->subHours(config('aurora.token_valid_time'));
     $count = DB::connection('server')->table('web_sso')->where('ckey', $ckey_in)->where('token', $token_in)->where('ip', $user_ip)->where('created_at', '>', $valid_until->toDateTimeString())->count();
     if ($count == 0) {
         abort(404);
     }
     //Check if a user with a linked byond account exists in the forum db
     $user = ForumUserModel::where('user_byond', $ckey_in)->first();
     if ($user == NULL) {
         return view('errors.no_user_linked', array('ckey' => $ckey_in));
     }
     //Auth the user
     Auth::login($user);
     //Delete the sso entry from the db
     DB::connection('server')->table('web_sso')->where('ckey', $ckey_in)->delete();
     $this->redirect_after_sso($location, $request);
 }