public function socialLogin($action = "")
 {
     if ($action == "auth") {
         // process authentication
         try {
             Hybrid_Endpoint::process();
         } catch (Exception $e) {
             // redirect back to http://URL/social/
             return Redirect::route('hybridauth');
         }
         return;
     }
     try {
         // create a HybridAuth object
         $socialAuth = new Hybrid_Auth(app_path() . '/config/hybridauth.php');
         if ($action == 'google') {
             $provider = $socialAuth->authenticate("Google");
         } else {
             if ($action == 'facebook') {
                 $provider = $socialAuth->authenticate("facebook");
             }
         }
         // fetch user profile
         $userProfile = $provider->getUserProfile();
         // logout
         $provider->logout();
     } catch (Exception $e) {
         // exception codes can be found on HybBridAuth's web site
         return $e->getMessage();
     }
     //check user to login or create new
     $user = User::where('email', $userProfile->email)->first();
     if (isset($user->email)) {
         //can update user and login
         $user->lastest_login = date("Y-m-d H:i:s");
         if ($action == 'facebook' && empty($user->facebook_id)) {
             $user->facebook_id = $userProfile->identifier;
             $user->save();
         } elseif ($action == 'google' && empty($user->google_id)) {
             $user->google_id = $userProfile->identifier;
             $user->save();
         }
         //return Redirect::to('/login')->with('notice',Lang::get('user_texts.social_is_exist'));
         if (!empty($user->authy)) {
             $authcontroller = new AuthController();
             $auth_controller = $authcontroller->getAuthy();
             $requestSms = $auth_controller->requestSms($user->authy);
             // echo "<pre>errors: "; print_r($requestSms->errors()); echo "</pre>";
             // echo "<pre>requestSms: "; print_r($requestSms); echo "</pre>";
             if ($requestSms->ok()) {
                 //$notices =  $requestSms->ok(); //return true
                 return Redirect::to('sms-verify')->with('authy_id', $user->authy)->with('user_login', $user->id);
             } else {
                 //not_sent_token
                 $errors = $requestSms->errors();
                 return Redirect::to('login')->with('error', $errors->message);
             }
         } else {
             Auth::login($user);
             return Redirect::to('/');
         }
     } else {
         //create new user and login
         $user = new User();
         $user->firstname = $userProfile->firstName;
         $user->lastname = $userProfile->lastName;
         $user->email = $userProfile->email;
         $user->username = $userProfile->identifier;
         $user->password = $userProfile->identifier;
         $user->password_confirmation = $userProfile->identifier;
         $user->banned = 0;
         $user->confirmed = 1;
         $user->referral = '';
         $trade_key = md5($user->username . $user->email . time());
         $user->trade_key = $trade_key;
         $user->ip_lastlogin = $this->get_client_ip();
         $user->lastest_login = date("Y-m-d H:i:s");
         if ($action == 'facebook' && empty($user->facebook_id)) {
             $user->facebook_id = $userProfile->identifier;
         } elseif ($action == 'google' && empty($user->google_id)) {
             $user->google_id = $userProfile->identifier;
         }
         $user->save();
         // echo "<pre>user2" . print_r( $user->email, true ) . "</pre><br />";
         if ($user->id) {
             $user->addRole('User');
             $input = array('email' => $userProfile->email, 'username' => $userProfile->email, 'password' => $userProfile->identifier, 'remember' => 0);
             //login
             if ($c = Confide::logAttempt($input, Config::get('confide::signup_confirm'))) {
                 return Redirect::to('/');
             } else {
                 $user = new User();
                 // Check if there was too many login attempts
                 if (Confide::isThrottled($input)) {
                     $err_msg = Lang::get('confide::confide.alerts.too_many_attempts');
                 } elseif ($user->checkUserExists($input) and !$user->isConfirmed($input)) {
                     $err_msg = Lang::get('confide::confide.alerts.not_confirmed');
                 } else {
                     $err_msg = Lang::get('confide::confide.alerts.wrong_credentials');
                 }
                 return Redirect::action('UserController@login')->with('error', $err_msg);
             }
         } else {
             $error = $user->errors()->all(':message');
             return Redirect::to('user/register')->withInput(Input::except('password'))->with('error', $error);
         }
     }
 }