#5: Added settings for configuring Twitter login, this is getting as far now as presenting the Twitter login screen. Login/register screens now respect the social media provider settings

This commit is contained in:
Andy Heathershaw 2018-08-16 09:18:54 +01:00
parent 5926bbcb33
commit 1ed4f297d2
10 changed files with 113 additions and 13 deletions

View File

@ -123,8 +123,11 @@ class ConfigHelper
'smtp_port' => 25,
'smtp_username' => '',
'social_facebook_login' => false,
'social_twitter_login' => false,
'social_user_profiles' => false,
'theme' => 'default'
'theme' => 'default',
'twitter_app_id' => '',
'twitter_app_secret' => '',
);
}
@ -171,4 +174,10 @@ class ConfigHelper
return $config;
}
public function isSocialMediaLoginEnabled()
{
return $this->get('social_facebook_login') ||
$this->get('social_twitter_login');
}
}

View File

@ -38,7 +38,8 @@ class DefaultController extends Controller
$this->passwordSettingKeys = [
'smtp_password',
'facebook_app_secret'
'facebook_app_secret',
'twitter_app_secret'
];
}
@ -229,6 +230,7 @@ class DefaultController extends Controller
'restrict_original_download',
'smtp_encryption',
'social_facebook_login',
'social_twitter_login',
'social_user_profiles'
];
$updateKeys = [
@ -244,6 +246,8 @@ class DefaultController extends Controller
'smtp_username',
'smtp_password',
'theme',
'twitter_app_id',
'twitter_app_secret',
'recaptcha_site_key',
'recaptcha_secret_key',
'analytics_code'

View File

@ -8,7 +8,9 @@ use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Laravel\Socialite\One\TwitterProvider;
use Laravel\Socialite\Two\FacebookProvider;
use League\OAuth1\Client\Server\Twitter as TwitterServer;
use Socialite;
class LoginController extends Controller
@ -126,6 +128,17 @@ class LoginController extends Controller
return $socialite->driver('facebook')->redirect();
}
/**
* Redirect the user to the Twitter authentication page.
*
* @return \Illuminate\Http\Response
*/
public function redirectToTwitter()
{
$socialite = $this->setSocialiteConfigs();
return $socialite->driver('twitter')->redirect();
}
/**
* Obtain the user information from Facebook.
*
@ -192,6 +205,17 @@ class LoginController extends Controller
return $socialite->buildProvider(FacebookProvider::class, $config);
}
);
$socialite->extend(
'twitter',
function ($app) use ($socialite) {
$config = [
'identifier' => UserConfig::get('twitter_app_id'),
'secret' => decrypt(UserConfig::get('twitter_app_secret')),
'callback_uri' => route('login_callback.twitter')
];
return new TwitterProvider($app['request'], new TwitterServer($config));
}
);
return $socialite;
}

View File

@ -212,7 +212,8 @@ return [
'security_allow_self_registration' => 'Allow self-registration',
'security_allow_self_registration_description' => 'With this option enabled, users can sign up for their own accounts. You can grant permissions to accounts to allow users to upload their own photos or manage yours.',
'social_facebook' => 'Facebook',
'social_tab' => 'Social'
'social_tab' => 'Social',
'social_twitter' => 'Twitter'
],
'select_all_action' => 'Select all',
'select_all_album_active' => 'Any action you select in the list below will apply to all photos in this album.',

View File

@ -49,6 +49,10 @@ return [
'settings_social_facebook_app_secret' => 'Facebook App Secret:',
'settings_social_facebook_login' => 'Allow login/registration with a Facebook account.',
'settings_social_facebook_login_help' => 'With this option enabled, users can register (if enabled) and login with their Facebook account.',
'settings_social_twitter_app_id' => 'Twitter App ID:',
'settings_social_twitter_app_secret' => 'Twitter App Secret:',
'settings_social_twitter_login' => 'Allow login/registration with a Twitter account',
'settings_social_twitter_login_help' => 'With this option enabled, users can register (if enabled) and login with their Twitter account.',
'settings_social_user_profiles' => 'Enable public user profiles',
'settings_social_user_profiles_help' => 'Display public pages for users showing their albums, cameras used and activity.',
'storage_access_key_label' => 'Access key:',

View File

@ -327,6 +327,7 @@
<hr class="mt-4 mb-4"/>
{{-- Facebook --}}
<div class="row">
<div class="col-2 col-sm-1">
<i class="fa fa-facebook fa-fw" style="font-size: xx-large;"></i>
@ -339,7 +340,7 @@
</legend>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="social-facebook-login" name="social_facebook_login" @if (old('social_facebook_login', UserConfig::get('social_facebook_login')))checked="checked"@endif>
<input type="checkbox" class="form-check-input" id="social-facebook-login" name="social_facebook_login" @if (old('social_facebook_login', $config['social_facebook_login']))checked="checked"@endif>
<label class="form-check-label" for="social-facebook-login">
<strong>@lang('forms.settings_social_facebook_login')</strong><br/>
@lang('forms.settings_social_facebook_login_help')
@ -358,7 +359,7 @@
</div>
<div class="form-group mt-3">
<label class="form-control-label" for="facebook-app-id">@lang('forms.settings_social_facebook_app_secret')</label>
<label class="form-control-label" for="facebook-app-secret">@lang('forms.settings_social_facebook_app_secret')</label>
<input type="text" class="form-control{{ $errors->has('facebook_app_secret') ? ' is-invalid' : '' }}" id="facebook-app-secret" name="facebook_app_secret" value="{{ old('facebook_app_secret', $config['facebook_app_secret']) }}">
@if ($errors->has('facebook_app_secret'))
@ -370,6 +371,53 @@
</fieldset>
</div>
</div>
<hr class="mt-4 mb-4"/>
{{-- Twitter --}}
<div class="row">
<div class="col-2 col-sm-1">
<i class="fa fa-twitter fa-fw" style="font-size: xx-large;"></i>
</div>
<div class="col-10 col-sm-11">
<fieldset>
<legend class="mb-3">
@lang('admin.settings.social_twitter')
</legend>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="social-twitter-login" name="social_twitter_login" @if (old('social_twitter_login', $config['social_twitter_login']))checked="checked"@endif>
<label class="form-check-label" for="social-twitter-login">
<strong>@lang('forms.settings_social_twitter_login')</strong><br/>
@lang('forms.settings_social_twitter_login_help')
</label>
</div>
<div class="form-group mt-3">
<label class="form-control-label" for="twitter-app-id">@lang('forms.settings_social_twitter_app_id')</label>
<input type="text" class="form-control{{ $errors->has('twitter_app_id') ? ' is-invalid' : '' }}" id="twitter-app-id" name="twitter_app_id" value="{{ old('twitter_app_id', $config['twitter_app_id']) }}">
@if ($errors->has('twitter_app_id'))
<div class="invalid-feedback">
<strong>{{ $errors->first('twitter_app_id') }}</strong>
</div>
@endif
</div>
<div class="form-group mt-3">
<label class="form-control-label" for="twitter-app-secret">@lang('forms.settings_social_twitter_app_secret')</label>
<input type="text" class="form-control{{ $errors->has('twitter_app_secret') ? ' is-invalid' : '' }}" id="twitter-app-secret" name="twitter_app_secret" value="{{ old('twitter_app_secret', $config['twitter_app_secret']) }}">
@if ($errors->has('twitter_app_secret'))
<div class="invalid-feedback">
<strong>{{ $errors->first('twitter_app_secret') }}</strong>
</div>
@endif
</div>
</fieldset>
</div>
</div>
</div>
</div>

View File

@ -1,8 +1,8 @@
@if (!$is_sso)
<p>@lang('auth.social_login')</p>
<p class="text-center">
<a href="{{ route('login.facebook') }}"><i class="fa fa-facebook fa-fw" style="font-size: xx-large;"></i></a>
</p>
@if (UserConfig::isSocialMediaLoginEnabled())
<p>@lang('auth.social_login')</p>
@include(Theme::viewName('partials.social_login_providers'))
@endif
<p class="mt-5 mb-4">@lang('auth.email_password_login')</p>
@else

View File

@ -1,8 +1,8 @@
@if (!$is_sso)
<p>@lang('auth.social_register')</p>
<p class="text-center">
<a href="{{ route('login.facebook') }}"><i class="fa fa-facebook fa-fw" style="font-size: xx-large;"></i></a>
</p>
@if (UserConfig::isSocialMediaLoginEnabled())
<p>@lang('auth.social_register')</p>
@include(Theme::viewName('partials.social_login_providers'))
@endif
<p class="mt-5 mb-4">@lang('auth.email_password_register')</p>
@else

View File

@ -0,0 +1,8 @@
<p class="text-center" style="font-size: xx-large;">
@if (UserConfig::get('social_facebook_login'))
<a href="{{ route('login.facebook') }}"><i class="fa fa-facebook fa-fw"></i></a>
@endif
@if (UserConfig::get('social_twitter_login'))
<a href="{{ route('login.twitter') }}"><i class="fa fa-twitter fa-fw"></i></a>
@endif
</p>

View File

@ -78,6 +78,8 @@ Route::group(['prefix' => 'install'], function () {
Route::get('login/facebook', 'Auth\LoginController@redirectToFacebook')->name('login.facebook');
Route::get('login/facebook/callback', 'Auth\LoginController@handleFacebookCallback')->name('login_callback.facebook');
Route::get('login/sso', 'Auth\LoginController@showLoginFormSso')->name('auth.login_sso');
Route::get('login/twitter', 'Auth\LoginController@redirectToTwitter')->name('login.twitter');
Route::get('login/twitter/callback', 'Auth\LoginController@handleTwitterCallback')->name('login_callback.twitter');
Route::get('register/sso', 'Auth\RegisterController@showRegistrationFormSso')->name('auth.register_sso');
// Gallery