Merge branch 'master' into feature/99-user-settings-page
This commit is contained in:
@@ -104,6 +104,10 @@ class ConfigHelper
|
||||
'date_format' => $this->allowedDateFormats()[0],
|
||||
'default_album_view' => $this->allowedAlbumViews()[0],
|
||||
'enable_visitor_hits' => false,
|
||||
'facebook_app_id' => '',
|
||||
'facebook_app_secret' => '',
|
||||
'google_app_id' => '',
|
||||
'google_app_secret' => '',
|
||||
'hotlink_protection' => false,
|
||||
'items_per_page' => 12,
|
||||
'items_per_page_admin' => 10,
|
||||
@@ -120,8 +124,13 @@ class ConfigHelper
|
||||
'smtp_password' => '',
|
||||
'smtp_port' => 25,
|
||||
'smtp_username' => '',
|
||||
'social_facebook_login' => false,
|
||||
'social_google_login' => false,
|
||||
'social_twitter_login' => false,
|
||||
'social_user_profiles' => false,
|
||||
'theme' => 'default'
|
||||
'theme' => 'default',
|
||||
'twitter_app_id' => '',
|
||||
'twitter_app_secret' => '',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -168,4 +177,10 @@ class ConfigHelper
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
public function isSocialMediaLoginEnabled()
|
||||
{
|
||||
return $this->get('social_facebook_login') ||
|
||||
$this->get('social_twitter_login');
|
||||
}
|
||||
}
|
||||
@@ -29,10 +29,19 @@ use Illuminate\Support\Facades\View;
|
||||
|
||||
class DefaultController extends Controller
|
||||
{
|
||||
private $passwordSettingKeys;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
View::share('is_admin', true);
|
||||
|
||||
$this->passwordSettingKeys = [
|
||||
'smtp_password',
|
||||
'facebook_app_secret',
|
||||
'google_app_secret',
|
||||
'twitter_app_secret'
|
||||
];
|
||||
}
|
||||
|
||||
public function about()
|
||||
@@ -211,9 +220,6 @@ class DefaultController extends Controller
|
||||
{
|
||||
$this->authorizeAccessToAdminPanel('admin:configure');
|
||||
|
||||
$passwordKeys = [
|
||||
'smtp_password'
|
||||
];
|
||||
$checkboxKeys = [
|
||||
'albums_menu_parents_only',
|
||||
'allow_self_registration',
|
||||
@@ -224,12 +230,19 @@ class DefaultController extends Controller
|
||||
'require_email_verification',
|
||||
'restrict_original_download',
|
||||
'smtp_encryption',
|
||||
'social_facebook_login',
|
||||
'social_google_login',
|
||||
'social_twitter_login',
|
||||
'social_user_profiles'
|
||||
];
|
||||
$updateKeys = [
|
||||
'albums_menu_number_items',
|
||||
'app_name',
|
||||
'date_format',
|
||||
'facebook_app_id',
|
||||
'facebook_app_secret',
|
||||
'google_app_id',
|
||||
'google_app_secret',
|
||||
'sender_address',
|
||||
'sender_name',
|
||||
'smtp_server',
|
||||
@@ -237,6 +250,8 @@ class DefaultController extends Controller
|
||||
'smtp_username',
|
||||
'smtp_password',
|
||||
'theme',
|
||||
'twitter_app_id',
|
||||
'twitter_app_secret',
|
||||
'recaptcha_site_key',
|
||||
'recaptcha_secret_key',
|
||||
'analytics_code'
|
||||
@@ -261,7 +276,7 @@ class DefaultController extends Controller
|
||||
}
|
||||
|
||||
$config->value = $request->request->get($key);
|
||||
if (in_array($key, $passwordKeys) && strlen($config->value) > 0)
|
||||
if (in_array($key, $this->passwordSettingKeys) && strlen($config->value) > 0)
|
||||
{
|
||||
$config->value = encrypt($config->value);
|
||||
}
|
||||
@@ -310,6 +325,14 @@ class DefaultController extends Controller
|
||||
$dateFormatsLookup[$dateFormat] = date($dateFormat);
|
||||
}
|
||||
|
||||
foreach ($this->passwordSettingKeys as $passwordSettingKey)
|
||||
{
|
||||
if (isset($config[$passwordSettingKey]) && !empty($config[$passwordSettingKey]))
|
||||
{
|
||||
$config[$passwordSettingKey] = decrypt($config[$passwordSettingKey]);
|
||||
}
|
||||
}
|
||||
|
||||
$themeNamesLookup = UserConfig::allowedThemeNames();
|
||||
|
||||
return Theme::render('admin.settings', [
|
||||
|
||||
@@ -3,9 +3,16 @@
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Facade\Theme;
|
||||
use App\Facade\UserConfig;
|
||||
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 Laravel\Socialite\Two\GoogleProvider;
|
||||
use League\OAuth1\Client\Server\Twitter as TwitterServer;
|
||||
use Socialite;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
@@ -39,6 +46,31 @@ class LoginController extends Controller
|
||||
$this->middleware('guest', ['except' => 'logout']);
|
||||
}
|
||||
|
||||
protected function attemptLogin(Request $request)
|
||||
{
|
||||
$isSuccessful = $this->guard()->attempt($this->credentials($request));
|
||||
|
||||
if ($isSuccessful)
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->guard()->user();
|
||||
|
||||
// Update the social media ID if successful login and it was referred by the SSO provider
|
||||
$loginData = $request->getSession()->get('ssoLoginData');
|
||||
if (!is_null($loginData))
|
||||
{
|
||||
unset($loginData['name']);
|
||||
unset($loginData['email']);
|
||||
$user->fill($loginData);
|
||||
$user->save();
|
||||
|
||||
$request->getSession()->remove('ssoLoginData');
|
||||
}
|
||||
}
|
||||
|
||||
return $isSuccessful;
|
||||
}
|
||||
|
||||
protected function credentials(Request $request)
|
||||
{
|
||||
$result = $request->only($this->username(), 'password');
|
||||
@@ -58,7 +90,187 @@ class LoginController extends Controller
|
||||
{
|
||||
return Theme::render('auth.v2_unified', [
|
||||
'active_tab' => 'login',
|
||||
'info' => $request->session()->get('info')
|
||||
'info' => $request->session()->get('info'),
|
||||
'is_sso' => false
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application's login form (for a social media-linked account).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function showLoginFormSso(Request $request)
|
||||
{
|
||||
// Social media login info
|
||||
$loginData = $request->getSession()->get('ssoLoginData');
|
||||
if (is_null($loginData))
|
||||
{
|
||||
// No SSO data in session, use the normal login screen
|
||||
return redirect(route('login'));
|
||||
}
|
||||
|
||||
return Theme::render('auth.v2_unified', [
|
||||
'active_tab' => 'login',
|
||||
'info' => $request->session()->get('info'),
|
||||
'is_sso' => true,
|
||||
'login_data' => $loginData
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect the user to the Facebook authentication page.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function redirectToFacebook()
|
||||
{
|
||||
$socialite = $this->setSocialiteConfigs();
|
||||
return $socialite->driver('facebook')->redirect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect the user to the Google authentication page.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function redirectToGoogle()
|
||||
{
|
||||
$socialite = $this->setSocialiteConfigs();
|
||||
return $socialite->driver('google')->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.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function handleFacebookCallback(Request $request)
|
||||
{
|
||||
$socialite = $this->setSocialiteConfigs();
|
||||
$facebookUser = $socialite->driver('facebook')->user();
|
||||
|
||||
return $this->processSocialMediaLogin($request, 'facebook_id', $facebookUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the user information from Google.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function handleGoogleCallback(Request $request)
|
||||
{
|
||||
$socialite = $this->setSocialiteConfigs();
|
||||
$googleUser = $socialite->driver('google')->user();
|
||||
|
||||
return $this->processSocialMediaLogin($request, 'google_id', $googleUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
if (!is_null($userBySocialMediaId))
|
||||
{
|
||||
// We have an existing user for this Facebook ID - log them in
|
||||
$this->guard()->login($userBySocialMediaId);
|
||||
return redirect(route('home'));
|
||||
}
|
||||
|
||||
// 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))
|
||||
{
|
||||
// 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
|
||||
$request->getSession()->put('ssoRegisterData', [
|
||||
'name' => $socialMediaUser->getName(),
|
||||
'email' => $socialMediaUser->getEmail(),
|
||||
$socialMediaIdField => $socialMediaUser->getId(),
|
||||
'is_activated' => true
|
||||
]);
|
||||
|
||||
return redirect(route('auth.register_sso'));
|
||||
}
|
||||
|
||||
private function setSocialiteConfigs()
|
||||
{
|
||||
// Force Socialite to use our config from the database instead of hard-coded in config/services.php
|
||||
$socialite = app()->make(\Laravel\Socialite\Contracts\Factory::class);
|
||||
$socialite->extend(
|
||||
'facebook',
|
||||
function ($app) use ($socialite) {
|
||||
$config = [
|
||||
'client_id' => trim(UserConfig::get('facebook_app_id')),
|
||||
'client_secret' => trim(decrypt(UserConfig::get('facebook_app_secret'))),
|
||||
'redirect' => route('login_callback.facebook')
|
||||
];
|
||||
return $socialite->buildProvider(FacebookProvider::class, $config);
|
||||
}
|
||||
);
|
||||
$socialite->extend(
|
||||
'google',
|
||||
function ($app) use ($socialite) {
|
||||
$config = [
|
||||
'client_id' => trim(UserConfig::get('google_app_id')),
|
||||
'client_secret' => trim(decrypt(UserConfig::get('google_app_secret'))),
|
||||
'redirect' => route('login_callback.google')
|
||||
];
|
||||
return $socialite->buildProvider(GoogleProvider::class, $config);
|
||||
}
|
||||
);
|
||||
$socialite->extend(
|
||||
'twitter',
|
||||
function ($app) use ($socialite) {
|
||||
$config = [
|
||||
'identifier' => trim(UserConfig::get('twitter_app_id')),
|
||||
'secret' => trim(decrypt(UserConfig::get('twitter_app_secret'))),
|
||||
'callback_uri' => route('login_callback.twitter')
|
||||
];
|
||||
return new TwitterProvider($app['request'], new TwitterServer($config));
|
||||
}
|
||||
);
|
||||
|
||||
return $socialite;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,25 +85,22 @@ class RegisterController extends Controller
|
||||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
$activationData = [
|
||||
'is_activated' => true
|
||||
];
|
||||
|
||||
if (UserConfig::get('require_email_verification'))
|
||||
if (!isset($data['is_activated']))
|
||||
{
|
||||
$activationData['is_activated'] = false;
|
||||
$activationData['activation_token'] = MiscHelper::randomString();
|
||||
$data['is_activated'] = true;
|
||||
|
||||
if (UserConfig::get('require_email_verification'))
|
||||
{
|
||||
$data['is_activated'] = false;
|
||||
$data['activation_token'] = MiscHelper::randomString();
|
||||
}
|
||||
}
|
||||
|
||||
return User::create(array_merge(
|
||||
[
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => bcrypt($data['password']),
|
||||
'is_admin' => false
|
||||
],
|
||||
$activationData
|
||||
));
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
$data['is_admin'] = false;
|
||||
unset($data['password_confirmation']);
|
||||
|
||||
return User::create($data);
|
||||
}
|
||||
|
||||
public function register(Request $request)
|
||||
@@ -115,8 +112,18 @@ class RegisterController extends Controller
|
||||
|
||||
$this->validator($request)->validate();
|
||||
|
||||
$userData = $request->all();
|
||||
|
||||
// Social media login info
|
||||
$registerData = $request->getSession()->get('ssoRegisterData');
|
||||
if (!is_null($registerData))
|
||||
{
|
||||
$userData = array_merge($registerData, $userData);
|
||||
$request->getSession()->remove('ssoRegisterData');
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->create($request->all());
|
||||
$user = $this->create($userData);
|
||||
|
||||
if ($user->is_activated)
|
||||
{
|
||||
@@ -137,7 +144,7 @@ class RegisterController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function showRegistrationForm()
|
||||
public function showRegistrationForm(Request $request)
|
||||
{
|
||||
if (!UserConfig::get('allow_self_registration'))
|
||||
{
|
||||
@@ -145,7 +152,35 @@ class RegisterController extends Controller
|
||||
}
|
||||
|
||||
return Theme::render('auth.v2_unified', [
|
||||
'active_tab' => 'register'
|
||||
'active_tab' => 'register',
|
||||
'is_sso' => false
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the application registration form (for a social media-linked account).
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function showRegistrationFormSso(Request $request)
|
||||
{
|
||||
if (!UserConfig::get('allow_self_registration'))
|
||||
{
|
||||
return redirect(route('home'));
|
||||
}
|
||||
|
||||
// Social media login info
|
||||
$registerData = $request->getSession()->get('ssoRegisterData');
|
||||
if (is_null($registerData))
|
||||
{
|
||||
// No SSO data in session, use the normal registration screen
|
||||
return redirect(route('register'));
|
||||
}
|
||||
|
||||
return Theme::render('auth.v2_unified', [
|
||||
'active_tab' => 'register',
|
||||
'is_sso' => true,
|
||||
'register_data' => $registerData
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ class User extends Authenticatable
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password', 'is_admin', 'is_activated', 'activation_token', 'profile_alias'
|
||||
'name', 'email', 'password', 'is_admin', 'is_activated', 'activation_token', 'enable_profile_page', 'profile_alias', 'facebook_id', 'twitter_id', 'google_id'
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user