Merge social media login #98
@ -152,6 +152,19 @@ class LoginController extends Controller
|
|||||||
return $this->processSocialMediaLogin($request, 'facebook_id', $facebookUser);
|
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)
|
private function processSocialMediaLogin(Request $request, $socialMediaIdField, $socialMediaUser)
|
||||||
{
|
{
|
||||||
$userBySocialMediaId = User::where($socialMediaIdField, $socialMediaUser->getId())->first();
|
$userBySocialMediaId = User::where($socialMediaIdField, $socialMediaUser->getId())->first();
|
||||||
@ -163,20 +176,25 @@ class LoginController extends Controller
|
|||||||
return redirect(route('home'));
|
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($userByEmailAddress))
|
if (!is_null($socialMediaUser->email))
|
||||||
{
|
{
|
||||||
// We have an existing user with the e-mail address associated with the Facebook account
|
$userByEmailAddress = User::where('email', $socialMediaUser->getEmail())->first();
|
||||||
// Prompt for the password for that account
|
|
||||||
$request->getSession()->put('ssoLoginData', [
|
|
||||||
'name' => $socialMediaUser->getName(),
|
|
||||||
'email' => $socialMediaUser->getEmail(),
|
|
||||||
$socialMediaIdField => $socialMediaUser->getId(),
|
|
||||||
'is_activated' => true
|
|
||||||
]);
|
|
||||||
|
|
||||||
return redirect(route('auth.login_sso'));
|
if (!is_null($userByEmailAddress))
|
||||||
|
{
|
||||||
|
// We have an existing user with the e-mail address associated with the Facebook account
|
||||||
|
// Prompt for the password for that account
|
||||||
|
$request->getSession()->put('ssoLoginData', [
|
||||||
|
'name' => $socialMediaUser->getName(),
|
||||||
|
'email' => $socialMediaUser->getEmail(),
|
||||||
|
$socialMediaIdField => $socialMediaUser->getId(),
|
||||||
|
'is_activated' => true
|
||||||
|
]);
|
||||||
|
|
||||||
|
return redirect(route('auth.login_sso'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't have an existing user - prompt for registration
|
// We don't have an existing user - prompt for registration
|
||||||
|
@ -16,7 +16,7 @@ class User extends Authenticatable
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
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>
|
<label for="name" class="col-md-4 col-form-label text-md-right">@lang('forms.realname_label')</label>
|
||||||
|
|
||||||
<div class="col-md-6">
|
<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'))
|
@if ($errors->has('name'))
|
||||||
<div class="invalid-feedback">
|
<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>
|
<label for="email" class="col-md-4 col-form-label text-md-right">@lang('forms.email_label')</label>
|
||||||
|
|
||||||
<div class="col-md-6">
|
<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 type="hidden" name="email" value="{{ $register_data['email'] }}">
|
||||||
<input id="email" type="email" class="form-control" value="{{ $register_data['email'] }}" readonly>
|
<input id="email" type="email" class="form-control" value="{{ $register_data['email'] }}" readonly>
|
||||||
@else
|
@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
|
@endif
|
||||||
|
|
||||||
@if ($errors->has('email'))
|
@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>
|
<label for="password" class="col-md-4 col-form-label text-md-right">@lang('forms.password_label')</label>
|
||||||
|
|
||||||
<div class="col-md-6">
|
<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'))
|
@if ($errors->has('password'))
|
||||||
<div class="invalid-feedback">
|
<div class="invalid-feedback">
|
||||||
|
Loading…
Reference in New Issue
Block a user