diff --git a/app/ExternalService.php b/app/ExternalService.php index d4a1a93..9a908ed 100644 --- a/app/ExternalService.php +++ b/app/ExternalService.php @@ -16,7 +16,7 @@ class ExternalService extends Model * * @var array */ - protected $fillable = ['name', 'service_type']; + protected $fillable = ['name', 'service_type', 'app_id', 'app_secret']; /** * Gets all possible service configurations for the given service type. diff --git a/app/Helpers/ConfigHelper.php b/app/Helpers/ConfigHelper.php index eb53d1b..80bc340 100644 --- a/app/Helpers/ConfigHelper.php +++ b/app/Helpers/ConfigHelper.php @@ -113,8 +113,8 @@ class ConfigHelper 'date_format' => $this->allowedDateFormats()[0], 'default_album_view' => $this->allowedAlbumViews()[0], 'enable_visitor_hits' => false, - 'facebook_external_service_id' => null, - 'google_external_service_id' => null, + 'facebook_external_service_id' => 0, + 'google_external_service_id' => 0, 'hotlink_protection' => false, 'items_per_page' => 12, 'items_per_page_admin' => 10, @@ -149,7 +149,7 @@ class ConfigHelper 'social_user_feeds' => false, 'social_user_profiles' => false, 'theme' => 'default', - 'twitter_external_service_id' => null + 'twitter_external_service_id' => 0 ); } @@ -216,11 +216,29 @@ class ConfigHelper !empty($this->get('rabbitmq_vhost')); } + public function isLoginWithFacebookEnabled() + { + return boolval($this->get('social_facebook_login')) && + intval($this->get('facebook_external_service_id')) > 0; + } + + public function isLoginWithGoogleEnabled() + { + return boolval($this->get('social_google_login')) && + intval($this->get('google_external_service_id')) > 0; + } + + public function isLoginWithTwitterEnabled() + { + return boolval($this->get('social_twitter_login')) && + intval($this->get('twitter_external_service_id')) > 0; + } + public function isSocialMediaLoginEnabled() { - return $this->get('social_facebook_login') || - $this->get('social_twitter_login') || - $this->get('social_google_login'); + return $this->isLoginWithFacebookEnabled() || + $this->isLoginWithGoogleEnabled() || + $this->isLoginWithTwitterEnabled(); } private function loadCache() diff --git a/app/Http/Middleware/AppInstallation.php b/app/Http/Middleware/AppInstallation.php index b711d99..d90361f 100644 --- a/app/Http/Middleware/AppInstallation.php +++ b/app/Http/Middleware/AppInstallation.php @@ -69,7 +69,10 @@ class AppInstallation if ($isAppInstalled) { // See if an update is necessary - $this->updateDatabaseIfRequired(); + if ($this->updateDatabaseIfRequired()) + { + return redirect($request->fullUrl()); + } // App is configured, continue on return $next($request); @@ -152,6 +155,10 @@ class AppInstallation // Rebuild the permissions cache $helper = new PermissionsHelper(); $helper->rebuildCache(); + + return true; } + + return false; } } \ No newline at end of file diff --git a/database/data_migrations/DataMigrationV2_2_0_beta_2.php b/database/data_migrations/DataMigrationV2_2_0_beta_2.php new file mode 100644 index 0000000..1f01120 --- /dev/null +++ b/database/data_migrations/DataMigrationV2_2_0_beta_2.php @@ -0,0 +1,112 @@ +moveFacebookSettingsToService(); + $this->moveGoogleSettingsToService(); + $this->moveTwitterSettingsToService(); + }); + } + + private function moveFacebookSettingsToService() + { + /** @var Configuration $facebookAppID */ + $facebookAppID = Configuration::where(['key' => 'facebook_app_id'])->first(); + + /** @var Configuration $facebookAppID */ + $facebookAppSecret = Configuration::where(['key' => 'facebook_app_secret'])->first(); + + if (is_null($facebookAppID) || is_null($facebookAppSecret)) + { + return; + } + + $externalService = ExternalService::create([ + 'service_type' => ExternalService::FACEBOOK, + 'name' => 'Facebook (migrated from settings)', + 'app_id' => encrypt($facebookAppID->value), // app ID needs to be encrypted now + 'app_secret' => $facebookAppSecret->value // secret is already encrypted + ]); + + /** @var ExternalService $facebookExternalServiceConfig */ + $facebookExternalServiceConfig = UserConfig::getOrCreateModel('facebook_external_service_id'); + $facebookExternalServiceConfig->value = $externalService->id; + $facebookExternalServiceConfig->save(); + + $facebookAppID->delete(); + $facebookAppSecret->delete(); + } + + private function moveGoogleSettingsToService() + { + /** @var Configuration $googleAppID */ + $googleAppID = Configuration::where(['key' => 'google_app_id'])->first(); + + /** @var Configuration $facebookAppID */ + $googleAppSecret = Configuration::where(['key' => 'google_app_secret'])->first(); + + if (is_null($googleAppID) || is_null($googleAppSecret)) + { + return; + } + + $externalService = ExternalService::create([ + 'service_type' => ExternalService::GOOGLE, + 'name' => 'Google (migrated from settings)', + 'app_id' => encrypt($googleAppID->value), // app ID needs to be encrypted now + 'app_secret' => $googleAppSecret->value // secret is already encrypted + ]); + + /** @var ExternalService $googleExternalServiceConfig */ + $googleExternalServiceConfig = UserConfig::getOrCreateModel('google_external_service_id'); + $googleExternalServiceConfig->value = $externalService->id; + $googleExternalServiceConfig->save(); + + $googleAppID->delete(); + $googleAppSecret->delete(); + } + + private function moveTwitterSettingsToService() + { + /** @var Configuration $twitterAppID */ + $twitterAppID = Configuration::where(['key' => 'twitter_app_id'])->first(); + + /** @var Configuration $facebookAppID */ + $twitterAppSecret = Configuration::where(['key' => 'twitter_app_secret'])->first(); + + if (is_null($twitterAppID) || is_null($twitterAppSecret)) + { + return; + } + + $externalService = ExternalService::create([ + 'service_type' => ExternalService::TWITTER, + 'name' => 'Twitter (migrated from settings)', + 'app_id' => encrypt($twitterAppID->value), // app ID needs to be encrypted now + 'app_secret' => $twitterAppSecret->value // secret is already encrypted + ]); + + /** @var ExternalService $twitterExternalServiceConfig */ + $twitterExternalServiceConfig = UserConfig::getOrCreateModel('twitter_external_service_id'); + $twitterExternalServiceConfig->value = $externalService->id; + $twitterExternalServiceConfig->save(); + + $twitterAppID->delete(); + $twitterAppSecret->delete(); + } +} \ No newline at end of file diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php index 994b770..64f1e62 100644 --- a/resources/lang/en/forms.php +++ b/resources/lang/en/forms.php @@ -82,6 +82,7 @@ return [ 'settings_moderate_known_users_help' => 'If this option is enabled, comments posted by logged-in users must be moderated before being displayed.', 'settings_restrict_originals_download' => 'Restrict access to original images', 'settings_restrict_originals_download_help' => 'With this option enabled, only the photo\'s owner can download the original high-resolution images.', + 'settings_social_external_services_edit_link' => 'Add or change these details in Services', 'settings_social_facebook_external_service' => 'Facebook service:', '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.', diff --git a/resources/views/themes/base/admin/settings.blade.php b/resources/views/themes/base/admin/settings.blade.php index 5aa83f2..85ed4dd 100644 --- a/resources/views/themes/base/admin/settings.blade.php +++ b/resources/views/themes/base/admin/settings.blade.php @@ -516,11 +516,12 @@
- @if (UserConfig::get('social_facebook_login')) + @if (UserConfig::isLoginWithFacebookEnabled()) @endif - @if (UserConfig::get('social_twitter_login')) + @if (UserConfig::isLoginWithTwitterEnabled()) @endif - @if (UserConfig::get('social_google_login')) + @if (UserConfig::isLoginWithGoogleEnabled()) @endif
\ No newline at end of file