ptim / users.php secret
Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

attempt at Twitter login using OneAuth laravel bundle

View users.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
<?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
Something went wrong with that request. Please try again.