Merge social media login #98
@ -152,6 +152,19 @@ class LoginController extends Controller
|
||||
return $this->processSocialMediaLogin($request, 'facebook_id', $facebookUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the user information from Twitter.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function handleTwitterCallback(Request $request)
|
||||
{
|
||||
$socialite = $this->setSocialiteConfigs();
|
||||
$twitterUser = $socialite->driver('twitter')->user();
|
||||
|
||||
return $this->processSocialMediaLogin($request, 'twitter_id', $twitterUser);
|
||||
}
|
||||
|
||||
private function processSocialMediaLogin(Request $request, $socialMediaIdField, $socialMediaUser)
|
||||
{
|
||||
$userBySocialMediaId = User::where($socialMediaIdField, $socialMediaUser->getId())->first();
|
||||
@ -163,7 +176,11 @@ class LoginController extends Controller
|
||||
return redirect(route('home'));
|
||||
}
|
||||
|
||||
$userByEmailAddress = User::where('email', $socialMediaUser->email)->first();
|
||||
// Some providers (*cough*Twitter*cough*) don't give e-mail addresses without explicit permission/additional
|
||||
// verification
|
||||
if (!is_null($socialMediaUser->email))
|
||||
{
|
||||
$userByEmailAddress = User::where('email', $socialMediaUser->getEmail())->first();
|
||||
|
||||
if (!is_null($userByEmailAddress))
|
||||
{
|
||||
@ -178,6 +195,7 @@ class LoginController extends Controller
|
||||
|
||||
return redirect(route('auth.login_sso'));
|
||||
}
|
||||
}
|
||||
|
||||
// We don't have an existing user - prompt for registration
|
||||
$request->getSession()->put('ssoRegisterData', [
|
||||
|
@ -16,7 +16,7 @@ class User extends Authenticatable
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password', 'is_admin', 'is_activated', 'activation_token', 'enable_profile_page', 'profile_alias', 'facebook_id'
|
||||
'name', 'email', 'password', 'is_admin', 'is_activated', 'activation_token', 'enable_profile_page', 'profile_alias', 'facebook_id', 'twitter_id'
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddUserTwitterIdColumn extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table)
|
||||
{
|
||||
$table->string('twitter_id')->nullable(true);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table)
|
||||
{
|
||||
$table->dropColumn('twitter_id');
|
||||
});
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
<label for="name" class="col-md-4 col-form-label text-md-right">@lang('forms.realname_label')</label>
|
||||
|
||||
<div class="col-md-6">
|
||||
<input id="name" type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" value="{{ old('name', $is_sso ? $register_data['name'] : '') }}"{{ $is_sso ? ' autofocus' : '' }}>
|
||||
<input id="name" type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" value="{{ old('name', $is_sso ? $register_data['name'] : '') }}"{{ !$is_sso ? ' autofocus' : '' }}>
|
||||
|
||||
@if ($errors->has('name'))
|
||||
<div class="invalid-feedback">
|
||||
@ -30,11 +30,11 @@
|
||||
<label for="email" class="col-md-4 col-form-label text-md-right">@lang('forms.email_label')</label>
|
||||
|
||||
<div class="col-md-6">
|
||||
@if ($is_sso)
|
||||
@if ($is_sso && !empty($register_data['email']))
|
||||
<input type="hidden" name="email" value="{{ $register_data['email'] }}">
|
||||
<input id="email" type="email" class="form-control" value="{{ $register_data['email'] }}" readonly>
|
||||
@else
|
||||
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email', $is_sso ? $register_data['email'] : '') }}">
|
||||
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email', $is_sso ? $register_data['email'] : '') }}"{{ $is_sso && empty($register_data['email']) ? ' autofocus' : '' }}>
|
||||
@endif
|
||||
|
||||
@if ($errors->has('email'))
|
||||
@ -49,7 +49,7 @@
|
||||
<label for="password" class="col-md-4 col-form-label text-md-right">@lang('forms.password_label')</label>
|
||||
|
||||
<div class="col-md-6">
|
||||
<input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password"{{ $is_sso ? ' autofocus' : '' }}>
|
||||
<input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password"{{ $is_sso && !empty($register_data['email']) ? ' autofocus' : '' }}>
|
||||
|
||||
@if ($errors->has('password'))
|
||||
<div class="invalid-feedback">
|
||||
|
Loading…
Reference in New Issue
Block a user