Esempio n. 1
0
 public function find($value)
 {
     return User::find($value);
 }
 /**
  * Obtain the user information from GitHub.
  *
  * @return Response
  */
 public function handleProviderCallback($provider)
 {
     if ($provider == 'facebook') {
         $user = Socialite::driver('facebook')->user();
         $q = User::where('email', $user->email)->first();
         if ($q) {
             \Auth::login($q);
         } else {
             $r = new User();
             $r->name = $user->getName();
             $r->email = $user->getEmail();
             $r->genero = $user->user['gender'];
             $r->password = $user->token;
             $r->avatar = $user->getAvatar();
             $r->role = 'editor';
             $r->save();
             $p = new Profile();
             $p->user_id = $r->id;
             if ($r->genero == 'mujer') {
                 $p->interes = 'hombre';
             } else {
                 $p->interes = 'mujer';
             }
             $p->edad_min = 18;
             $p->edad_max = 25;
             $p->save();
             \Auth::login($r);
         }
         return Redirect::route('user.compras');
     } elseif ($provider == 'twitter') {
         $user = Socialite::driver('twitter')->user();
         $q = User::where('password', $user->token)->first();
         //dd($user);
         if ($q) {
             \Auth::login($q);
         } else {
             $r = new User();
             $r->name = $user->getName();
             $r->email = str_random(60);
             $r->password = $user->token;
             $r->avatar = $user->avatar_original;
             $r->role = 'editor';
             $r->genero = 'hombre';
             $r->save();
             $p = new Profile();
             $p->user_id = $r->id;
             if ($r->genero == 'hombre') {
                 $p->interes = 'mujer';
             } else {
                 $p->interes = 'hombre';
             }
             $p->edad_min = 18;
             $p->edad_max = 25;
             $p->descripcion = 'Escribe tus gustos :)';
             $p->save();
             \Auth::login($r);
         }
         return Redirect::route('user.compras');
     }
 }