-
-
Save ptim/a29bb86b3fb7455c19ba to your computer and use it in GitHub Desktop.
attempt at Twitter login using OneAuth laravel bundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Users_Controller extends Base_Controller { | |
public $restful = true; | |
public function get_index($id = NULL) | |
{ | |
$user = User::find($id); | |
return View::make('user.index') | |
->with('title','Users') | |
->with('user', $user); | |
} | |
public function post_index() | |
{ | |
User::create(array( | |
'username' => Input::get('username'), | |
'email' => Input::get('email'), | |
)); | |
$users = User::all(); | |
return View::make('user.new') | |
->with('users', $users) | |
->with('title','New User'); | |
} | |
// | |
// below is what I'm interested in.. copied from: | |
// http://youtu.be/xlUFiZhwFiE | |
// | |
public function get_social_login() | |
{ | |
$user_data = Session::get( 'oneauth' ); | |
$user = User::where_social_provider( $user_data['provider']) | |
->where_social_uid( $user_data['info']['uid'] ) | |
->first(); | |
Session::forget( 'user_data '); | |
if( !is_null( $user ) ) | |
{ | |
Auth::login( $user->id, true ); | |
return Redirect::to( 'dashboard' ); | |
} | |
else | |
{ | |
return Redirect::to( 'user/login' )->with( 'error', "Sorry, Couldn't log you in." ); | |
} | |
} | |
public function get_social_register() | |
{ | |
$user_data = Session::get( 'oneauth' ); | |
$user = new User; | |
// Used for logging in user | |
$user->social_uid = $user_data['info']['uid']; | |
$user->social_provider = $user_data['provider']; | |
// General Info | |
$user->username -> $user_data['info']['name']; | |
// Proider specific info | |
switch( $user_data['provider'] ) | |
{ | |
case 'twitter' : | |
// Double check that the email exists | |
$email_check = User::where_email( $user_data['info']['email'] ) | |
->count(); | |
if( $email_check == 0 ) | |
$user->email = $user_data['info']['email']; | |
break; | |
} | |
$user->save(); | |
Auth::login( $user->id, true ); | |
Session::forget( 'user_data' ); | |
// Redirect to last viewed page | |
return Redirect::to( 'user/terms' )->with( 'success', 'Welcome to the Invest in this Site community!' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment