diff --git a/.env.example b/.env.example index f59c9211..530a37be 100644 --- a/.env.example +++ b/.env.example @@ -22,4 +22,8 @@ SMS_PASSWORD=dummy # QUEUES IRON_PROJECT=dummy -IRON_TOKEN=dummy \ No newline at end of file +IRON_TOKEN=dummy + +# TWITTER +TWITTER_CLIENT_ID=dummy +TWITTER_CLIENT_SECRET=dummy \ No newline at end of file diff --git a/app/TeenQuotes/Api/V1/Controllers/UsersController.php b/app/TeenQuotes/Api/V1/Controllers/UsersController.php index 3ddf47bf..ce39e30d 100644 --- a/app/TeenQuotes/Api/V1/Controllers/UsersController.php +++ b/app/TeenQuotes/Api/V1/Controllers/UsersController.php @@ -1,10 +1,9 @@ userValidator->validateSignup($data); // Store the new user + $avatar = Session::get('avatar', null); + // If the new user has got a Gravatar, set the avatar - $avatar = null; - if (Gravatar::exists($data['email'])) + if (is_null($avatar) AND Gravatar::exists($data['email'])) $avatar = Gravatar::src($data['email'], 150); $user = $this->userRepo->create($data['login'], $data['email'], $data['password'], diff --git a/app/TeenQuotes/Auth/AuthServiceProvider.php b/app/TeenQuotes/Auth/AuthServiceProvider.php index 478cd1d1..b2ea79ac 100644 --- a/app/TeenQuotes/Auth/AuthServiceProvider.php +++ b/app/TeenQuotes/Auth/AuthServiceProvider.php @@ -37,6 +37,7 @@ private function registerAuthRoutes() $this->app['router']->group($this->getRouteGroupParams(), function() use ($controller) { $this->app['router']->get('signin', ['as' => 'signin', 'uses' => $controller.'@getSignin']); $this->app['router']->get('logout', ['as' => 'logout', 'uses' => $controller.'@getLogout']); + $this->app['router']->get('auth/twitter', ['as' => 'auth.twitter', 'uses' => $controller.'@getAuthTwitter']); $this->app['router']->post('signin', $controller.'@postSignin'); }); } @@ -57,7 +58,7 @@ private function registerAuthViewComposers() $this->app['view']->composer([ 'auth.signin', 'auth.signup' - ], 'TeenQuotes\Tools\Composers\DeepLinksComposer'); + ], 'TeenQuotes\Tools\Composers\DeepLinksComposer'); } private function registerReminderRoutes() @@ -78,11 +79,11 @@ private function registerReminderViewComposers() $this->app['view']->composer([ 'password.reset' ], $this->getNamespaceComposers().'ResetComposer'); - + // For deeps link $this->app['view']->composer([ 'password.remind' - ], 'TeenQuotes\Tools\Composers\DeepLinksComposer'); + ], 'TeenQuotes\Tools\Composers\DeepLinksComposer'); } /** diff --git a/app/TeenQuotes/Auth/Controllers/AuthController.php b/app/TeenQuotes/Auth/Controllers/AuthController.php index 6ca080fc..76bcb92b 100644 --- a/app/TeenQuotes/Auth/Controllers/AuthController.php +++ b/app/TeenQuotes/Auth/Controllers/AuthController.php @@ -1,15 +1,8 @@ beforeFilter('guest', ['only' => 'getSignin']); $this->beforeFilter('auth', ['only' => 'getLogout']); $this->userValidator = $userValidator; + // $this->socialite = $socialite; } /** @@ -102,4 +101,36 @@ public function getLogout() return Redirect::route('home')->with('success', Lang::get('auth.logoutSuccessfull', compact('login'))); } + + public function getAuthTwitter() + { + $hasCode = Request::has('code'); + + if (! $hasCode) return $this->getTwitterAuthorization(); + + $user = $this->getTwitterUser(); + // Prefill the signup view + Session::flash('login', $user->getNickname()); + Session::flash('email', $user->getEmail()); + // Store the URL of the avatar is session + // It'll be saved when calling the API + Session::set('avatar', $user->getAvatar()); + + return Redirect::route('signup'); + } + + /** + * @return \Symfony\Component\HttpFoundation\RedirectResponse + */ + private function getTwitterAuthorization() + { + return $this->socialite->driver('twitter')->redirect(); + } + /** + * @return \Laravel\Socialite\Contracts\User + */ + private function getTwitterUser() + { + return $this->socialite->driver('twitter')->user(); + } } \ No newline at end of file diff --git a/app/config/services.php b/app/config/services.php index 5dcde793..bcd60416 100644 --- a/app/config/services.php +++ b/app/config/services.php @@ -37,4 +37,10 @@ 'apiKey' => getenv('EASYREC_APIKEY'), 'tenantID' => 'teenquotes_'.App::environment() ], + + 'twitter' => [ + 'client_id' => getenv('TWITTER_CLIENT_ID'), + 'client_secret' => getenv('TWITTER_CLIENT_SECRET'), + 'redirect' => 'http://'.Config::get('app.domain').'/auth/twitter' + ], ]; \ No newline at end of file