public function github()
 {
     $ch = curl_init('https://github.com/login/oauth/access_token');
     curl_setopt($ch, CURLOPT_POSTFIELDS, array('client_id' => Config::get('github.client_id'), 'client_secret' => Config::get('github.client_secret'), 'code' => Input::get('code')));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
     curl_setopt($ch, CURLOPT_USERAGENT, 'SWAMP');
     $response = curl_exec($ch);
     $status = array();
     parse_str($response, $status);
     // a GitHub access_token has been granted
     //
     if (array_key_exists('access_token', $status)) {
         Session::set('github_access_token', $status["access_token"]);
         Session::set('github_access_time', gmdate('U'));
         // Load user
         //
         $ch = curl_init('https://api.github.com/user');
         curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: token {$status['access_token']}"));
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
         curl_setopt($ch, CURLOPT_USERAGENT, 'SWAMP');
         $response = curl_exec($ch);
         $github_user = json_decode($response);
         $account = LinkedAccount::where('user_external_id', '=', $github_user->id)->where('linked_account_provider_code', '=', 'github')->first();
         // linked account record exists for this github user
         //
         if ($account) {
             // a SWAMP user account for the github user exists
             //
             $user = User::getIndex($account->user_uid);
             if ($user) {
                 // github linked account disabled?
                 //
                 if (LinkedAccountProvider::where('linked_account_provider_code', '=', 'github')->first()->enabled_flag != '1') {
                     return Redirect::to(Config::get('app.cors_url') . '/#github/error/github-auth-disabled');
                 }
                 // github authentication disabled?
                 //
                 if ($account->enabled_flag != '1') {
                     return Redirect::to(Config::get('app.cors_url') . '/#github/error/github-account-disabled');
                 }
                 // continue checking basic user credentials
                 //
                 if ($user->hasBeenVerified()) {
                     if ($user->isEnabled()) {
                         return Redirect::to(Config::get('app.cors_url') . '/#github/login');
                     } else {
                         return Redirect::to(Config::get('app.cors_url') . '/#github/error/not-enabled');
                     }
                 } else {
                     return Redirect::to(Config::get('app.cors_url') . '/#github/error/not-verified');
                 }
             } else {
                 // SWAMP user not found for existing linked account.
                 //
                 LinkedAccount::where('user_external_id', '=', $github_user->id)->where('linked_account_provider_code', '=', 'github')->delete();
                 return Redirect::to(Config::get('app.cors_url') . "/#github/prompt");
             }
         } else {
             return Redirect::to(Config::get('app.cors_url') . "/#github/prompt");
         }
         // a GitHub access_token has not been granted
         //
     } else {
         return Response::make('Unable to authenticate with GitHub.', 401);
     }
 }
 public function getDescriptionAttribute()
 {
     return LinkedAccountProvider::where('linked_account_provider_code', '=', $this->linked_account_provider_code)->first()->description;
 }