Skip to content

Commit

Permalink
added additional socialite handlers with examples ready to go, change…
Browse files Browse the repository at this point in the history
…d out login form HTML form with Laravel FORM/HTML conventions
  • Loading branch information
jeremykenedy committed Oct 25, 2015
1 parent c91d644 commit 79ccbbf
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 60 deletions.
30 changes: 29 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,32 @@ TW_REDIRECT=http://yourwebsiteURLhere.com/social/handle/twitter
# https://console.developers.google.com/ - NEED OAUTH CREDS
GOOGLE_ID=YOURGOOGLEPLUSidHERE
GOOGLE_SECRET=YOURGOOGLEPLUSsecretHERE
GOOGLE_REDIRECT=http://yourwebsiteURLhere.com/social/handle/google
GOOGLE_REDIRECT=http://yourwebsiteURLhere.com/social/handle/google

# https://github.com/settings/applications/new
GITHUB_ID=YOURIDHERE
GITHUB_SECRET=YOURSECRETHERE
GITHUB_URL=https://larablog.io/social/handle/github

# https://developers.google.com/youtube/v3/getting-started
YOUTUBE_KEY=YOURKEYHERE
YOUTUBE_SECRET=YOURSECRETHERE
YOUTUBE_REDIRECT_URI=https://larablog.io/social/handle/youtube

# http://www.twitch.tv/kraken/oauth2/clients/new
TWITCH_KEY=YOURKEYHERE
TWITCH_SECRET=YOURSECRETHERE
TWITCH_REDIRECT_URI=http://laravel-admin.local/social/handle/twitch

# https://instagram.com/developer/register/
INSTAGRAM_KEY=YOURKEYHERE
INSTAGRAM_SECRET=YOURSECRETHERE
INSTAGRAM_REDIRECT_URI=http://laravel-admin.local/social/handle/instagram

# https://basecamp.com/
# https://github.com/basecamp/basecamp-classic-api
37SIGNALS_KEY=YOURKEYHERE
37SIGNALS_SECRET=YOURSECRETHERE
37SIGNALS_REDIRECT_URI=http://laravel-admin.local/social/handle/37signals


2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015
Copyright (c) 2015 jeremykenedy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function getSocialHandle( $provider )
$new_social_user->activation_code = $the_activation_code;
$new_social_user->save();
$social_data = new Social;
$social_data->social_id = $user->id;
$social_data->social_id = $user->id;
$social_data->provider = $provider;
$new_social_user->social()->save($social_data);

Expand All @@ -228,12 +228,12 @@ public function getSocialHandle( $provider )
if( $this->auth->user()->hasRole('user'))
{
//return redirect()->route('user.home');
return redirect('pages.home');
return redirect('app');
}

if( $this->auth->user()->hasRole('administrator'))
{
return redirect('pages.home');
return redirect('app');
//return redirect()->route('admin.home');
}

Expand Down
5 changes: 4 additions & 1 deletion app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
| http://laravel.com/docs/5.1/authorization
| http://laravel.com/docs/5.1/routing
| http://laravel.com/docs/5.0/schema
| http://socialiteproviders.github.io/
|
*/

Expand Down Expand Up @@ -59,7 +60,9 @@
Route::get('home', function () {
return redirect('/');
});

Route::get('app', function () {
return redirect('/');
});

//***************************************************************************************//
//***************************** USER ROUTING EXAMPLES BELOW *****************************//
Expand Down
2 changes: 1 addition & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
*
* @var array
*/
protected $fillable = ['name', 'email', 'password'];
protected $fillable = ['name', 'first_name', 'last_name', 'email', 'password'];

/**
* The attributes excluded from the model's JSON form.
Expand Down
7 changes: 7 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class EventServiceProvider extends ServiceProvider {
'event.name' => [
'EventListener',
],
'SocialiteProviders\Manager\SocialiteWasCalled' => [
'SocialiteProviders\YouTube\YouTubeExtendSocialite@handle',
'SocialiteProviders\Twitch\TwitchExtendSocialite@handle',
'SocialiteProviders\Instagram\InstagramExtendSocialite@handle',
'SocialiteProviders\ThirtySevenSignals\ThirtySevenSignalsExtendSocialite@handle',
],

];

/**
Expand Down
11 changes: 1 addition & 10 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
*
* @var array
*/
protected $fillable = ['name', 'email', 'password'];
protected $fillable = ['name', 'first_name', 'last_name', 'email', 'password'];

/**
* The attributes excluded from the model's JSON form.
Expand Down Expand Up @@ -71,13 +71,4 @@ public function social()
return $this->hasMany('App\Models\Social');
}










}
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "laravel/laravel",
"name": "jeremykenedy/laravel-auth",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
Expand All @@ -9,7 +9,11 @@
"laravel/framework": "5.1.*",
"illuminate/html": "5.*",
"google/recaptcha": "~1.1",
"laravel/socialite": "^2.0"
"laravel/socialite": "^2.0",
"socialiteproviders/youtube": "^1.1",
"socialiteproviders/twitch": "^1.1",
"socialiteproviders/instagram": "^1.1",
"socialiteproviders/37signals": "^1.1"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
Expand Down
14 changes: 11 additions & 3 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@
App\Providers\ConfigServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Illuminate\Html\HtmlServiceProvider::class,
Laravel\Socialite\SocialiteServiceProvider::class
Illuminate\Html\HtmlServiceProvider::class, // https://github.com/illuminate/html
Laravel\Socialite\SocialiteServiceProvider::class,
SocialiteProviders\Manager\ServiceProvider::class,
],

/*
Expand Down Expand Up @@ -195,7 +196,14 @@
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'Socialite' => Laravel\Socialite\Facades\Socialite::class,

// ADD BACK IN LARAVEL FORM CLASSES WITH ALIASES - https://github.com/illuminate/html
'HTML' => Illuminate\Html\HtmlFacade::class,
'Form' => Illuminate\Html\FormFacade::class,

// ADD SOCIALITE
'Socialite' => Laravel\Socialite\Facades\Socialite::class,

],

];
34 changes: 33 additions & 1 deletion config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
| default location for this type of information, allowing packages
| to have a conventional place to find your various credentials.
|
| # http://socialiteproviders.github.io/
|
*/

'mailgun' => [
Expand Down Expand Up @@ -51,6 +53,36 @@
'client_id' => env('GOOGLE_ID'),
'client_secret' => env('GOOGLE_SECRET'),
'redirect' => env('GOOGLE_REDIRECT')
]
],

'github' => [
'client_id' => env('GITHUB_ID'),
'client_secret' => env('GITHUB_SECRET'),
'redirect' => env('GITHUB_URL'),
],

'youtube' => [
'client_id' => env('YOUTUBE_KEY'),
'client_secret' => env('YOUTUBE_SECRET'),
'redirect' => env('YOUTUBE_REDIRECT_URI'),
],

'twitch' => [
'client_id' => env('TWITCH_KEY'),
'client_secret' => env('TWITCH_SECRET'),
'redirect' => env('TWITCH_REDIRECT_URI'),
],

'instagram' => [
'client_id' => env('INSTAGRAM_KEY'),
'client_secret' => env('INSTAGRAM_SECRET'),
'redirect' => env('INSTAGRAM_REDIRECT_URI'),
],

'37signals' => [
'client_id' => env('37SIGNALS_KEY'),
'client_secret' => env('37SIGNALS_SECRET'),
'redirect' => env('37SIGNALS_REDIRECT_URI'),
],

];
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function up()
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->string('name')->unique();
$table->string('first_name');
$table->string('last_name');
$table->string('email')->unique()->nullable();
Expand Down
13 changes: 12 additions & 1 deletion resources/lang/en/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'anEmailWasSent' => 'An email was sent to :email on :date.',
'clickHereResend' => 'Click here to resend the email.',

//LABELS
'whoops' => 'Whoops!',
'someProblems' => 'There were some problems with your input.',
'email' => 'E-Mail Address',
Expand All @@ -27,12 +28,22 @@
'confirmPassword' => 'Confirm Password',
'register' => 'Register',

//PLACEHOLDERS
'ph_name' => 'Username',
'ph_email' => 'E-mail Address',

'ph_firstname' => 'First Name',
'ph_lastname' => 'Last Name',
'ph_password' => 'Password',
'ph_password_conf' => 'Confirm Password',

//
'sendResetLink' => 'Send Password Reset Link',
'resetPassword' => 'Reset Password',

'loggedIn' => 'You are logged in!',

//emails
//EMAIL
'pleaseActivate' => 'Please activate your account.',
'clickHereReset' => 'Click here to reset your password: ',
'clickHereActivate' => 'Click here to activate your account: ',
Expand Down
68 changes: 33 additions & 35 deletions resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<div class="panel panel-default">
<div class="panel-heading">{{ Lang::get('titles.login') }}</div>
<div class="panel-body">

@if (count($errors) > 0)
<div class="alert alert-danger">
<strong>{{ Lang::get('auth.whoops') }}</strong>{{ Lang::get('auth.someProblems') }}<br><br>
Expand All @@ -18,53 +19,50 @@
</div>
@endif

<form class="form-horizontal" role="form" method="POST" action="{{ url('/auth/login') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">

<div class="form-group">
<label class="col-md-4 control-label">{{ Lang::get('auth.email') }}</label>
<div class="col-md-6">
<input type="email" class="form-control" name="email" value="{{ old('email') }}">
{!! Form::open(array('url' => 'auth/login', 'method' => 'POST', 'class' => 'lockscreen-credentials form-horizontal', 'role' => 'form')) !!}
{!! csrf_field() !!}
<div class="form-group has-feedback">
{!! Form::label('email', Lang::get('auth.email') , array('class' => 'col-sm-4 control-label')); !!}
<div class="col-sm-6">
{!! Form::email('email', null, array('id' => 'email', 'class' => 'form-control', 'placeholder' => Lang::get('auth.ph_email'), 'required' => 'required',)) !!}
<span class="glyphicon glyphicon-envelope form-control-feedback" aria-hidden="true"></span>
</div>
</div>

<div class="form-group">
<label class="col-md-4 control-label">{{ Lang::get('auth.password') }}</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password">
<div class="form-group has-feedback">
{!! Form::label('password', Lang::get('auth.password') , array('class' => 'col-sm-4 control-label')); !!}
<div class="col-sm-6">
{!! Form::password('password', array('id' => 'password', 'class' => 'form-control', 'placeholder' => Lang::get('auth.ph_password'), 'required' => 'required',)) !!}
<span class="glyphicon glyphicon-lock form-control-feedback" aria-hidden="true"></span>
</div>
</div>

<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="col-sm-6 col-xs-offset-1 col-sm-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember"> {{ Lang::get('auth.rememberMe') }}
</label>
{!! Form::checkbox('remember', 'remember', true, array('id' => 'remember')); !!}
{!! Form::label('remember', Lang::get('auth.rememberMe')); !!}
</div>
</div>
</div>

<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">{{ Lang::get('auth.login') }}</button>

<a class="btn btn-link" href="{{ url('/password/email') }}">{{ Lang::get('auth.forgot') }}</a>
<div class="col-sm-6 col-sm-offset-4">
{!! Form::button(Lang::get('auth.login'), array('class' => 'btn btn-primary','type' => 'submit')) !!}
{!! HTML::link(url('/password/email'), Lang::get('auth.forgot'), array('id' => 'forgot', 'class' => 'btn btn-link')) !!}
</div>
</div>


<p class="or-social">Or Use Social Login</p>

<a href="{{ route('social.redirect', ['provider' => 'facebook']) }}" class="btn btn-lg btn-primary btn-block facebook" type="submit">Facebook</a>
<a href="{{ route('social.redirect', ['provider' => 'twitter']) }}" class="btn btn-lg btn-primary btn-block twitter" type="submit">Twitter</a>
<a href="{{ route('social.redirect', ['provider' => 'google']) }}" class="btn btn-lg btn-primary btn-block google" type="submit">Google</a>





</form>
<p class="text-center">Or</p>
<div class="form-group">
<div class="col-sm-6 col-sm-offset-3">
{!! HTML::link(route('social.redirect', ['provider' => 'facebook']), 'Facebook', array('class' => 'btn btn-lg btn-primary btn-block facebook')) !!}
{!! HTML::link(route('social.redirect', ['provider' => 'twitter']), 'Twitter', array('class' => 'btn btn-lg btn-primary btn-block twitter')) !!}
{!! HTML::link(route('social.redirect', ['provider' => 'google']), 'Google +', array('class' => 'btn btn-lg btn-primary btn-block google')) !!}
{!! HTML::link(route('social.redirect', ['provider' => 'github']), 'GitHub', array('class' => 'btn btn-lg btn-primary btn-block github')) !!}
{!! HTML::link(route('social.redirect', ['provider' => 'youtube']), 'YouTube', array('class' => 'btn btn-lg btn-primary btn-block youtube')) !!}
{!! HTML::link(route('social.redirect', ['provider' => 'twitch']), 'Twitch', array('class' => 'btn btn-lg btn-primary btn-block twitch')) !!}
{!! HTML::link(route('social.redirect', ['provider' => 'instagram']), 'Instagram', array('class' => 'btn btn-lg btn-primary btn-block instagram')) !!}
{!! HTML::link(route('social.redirect', ['provider' => '37signals']), 'Basecamp 37signals', array('class' => 'btn btn-lg btn-primary btn-block 37signals')) !!}
</div>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
Expand Down

0 comments on commit 79ccbbf

Please sign in to comment.