diff --git a/CHANGELOG.md b/CHANGELOG.md index 378d27758..46975545a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,10 @@ - Ability to cancel a payement schedule from the interface - Ability to create slots in the past +- Ability to disable public account creation - Updated caniuse db - Optimized the load time of the payment schedules list +- [TODO DEPLOY] `rails db:seed` # v5.3.0 2021 December 29 diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 7ceee313d..c958d347d 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -4,6 +4,11 @@ class RegistrationsController < Devise::RegistrationsController # POST /users.json def create + # Is public registration allowed? + unless Setting.get('public_registrations') + render json: { errors: { signup: [t('errors.messages.registration_disabled')] } }, status: :forbidden and return + end + # first check the recaptcha check = RecaptchaService.verify(params[:user][:recaptcha]) render json: check['error-codes'], status: :unprocessable_entity and return unless check['success'] diff --git a/app/frontend/src/javascript/controllers/header.js b/app/frontend/src/javascript/controllers/header.js index 1d9759b68..a59536cdb 100644 --- a/app/frontend/src/javascript/controllers/header.js +++ b/app/frontend/src/javascript/controllers/header.js @@ -1,11 +1,18 @@ 'use strict'; -Application.Controllers.controller('HeaderController', ['$scope', '$rootScope', '$state', - function ($scope, $rootScope, $state) { +Application.Controllers.controller('HeaderController', ['$scope', '$rootScope', '$state', 'settingsPromise', + function ($scope, $rootScope, $state, settingsPromise) { $scope.aboutPage = ($state.current.name === 'app.public.about'); $rootScope.$on('$stateChangeStart', function (event, toState) { $scope.aboutPage = (toState.name === 'app.public.about'); }); + + /** + * Returns the current state of the public registration setting (allowed/blocked). + */ + $scope.registrationEnabled = function () { + return settingsPromise.public_registrations === 'true'; + }; } ]); diff --git a/app/frontend/src/javascript/controllers/main_nav.js b/app/frontend/src/javascript/controllers/main_nav.js index 04d3f4d97..443a01c0c 100644 --- a/app/frontend/src/javascript/controllers/main_nav.js +++ b/app/frontend/src/javascript/controllers/main_nav.js @@ -13,7 +13,7 @@ /** * Navigation controller. List the links availables in the left navigation pane and their icon. */ -Application.Controllers.controller('MainNavController', ['$scope', function ($scope) { +Application.Controllers.controller('MainNavController', ['$scope', 'settingsPromise', function ($scope, settingsPromise) { // Common links (public application) $scope.navLinks = [ { @@ -172,5 +172,12 @@ Application.Controllers.controller('MainNavController', ['$scope', function ($sc authorizedRoles: ['admin'] }); } + + /** + * Returns the current state of the public registration setting (allowed/blocked). + */ + $scope.registrationEnabled = function () { + return settingsPromise.public_registrations === 'true'; + }; } ]); diff --git a/app/frontend/src/javascript/models/setting.ts b/app/frontend/src/javascript/models/setting.ts index 420d1f374..89eb1c577 100644 --- a/app/frontend/src/javascript/models/setting.ts +++ b/app/frontend/src/javascript/models/setting.ts @@ -117,7 +117,8 @@ export enum SettingName { RenewPackThreshold = 'renew_pack_threshold', PackOnlyForSubscription = 'pack_only_for_subscription', OverlappingCategories = 'overlapping_categories', - ExtendedPricesInSameDay = 'extended_prices_in_same_day' + ExtendedPricesInSameDay = 'extended_prices_in_same_day', + PublicRegistrations = 'public_registrations' } export type SettingValue = string|boolean|number; diff --git a/app/frontend/src/javascript/router.js b/app/frontend/src/javascript/router.js index bb5a7d6c6..26b98543a 100644 --- a/app/frontend/src/javascript/router.js +++ b/app/frontend/src/javascript/router.js @@ -38,7 +38,8 @@ angular.module('application.router', ['ui.router']) logoFile: ['CustomAsset', function (CustomAsset) { return CustomAsset.get({ name: 'logo-file' }).$promise; }], logoBlackFile: ['CustomAsset', function (CustomAsset) { return CustomAsset.get({ name: 'logo-black-file' }).$promise; }], sharedTranslations: ['Translations', function (Translations) { return Translations.query(['app.shared', 'app.public.common']).$promise; }], - modulesPromise: ['Setting', function (Setting) { return Setting.query({ names: "['spaces_module', 'plans_module', 'invoicing_module', 'wallet_module', 'statistics_module', 'trainings_module', 'public_agenda_module']" }).$promise; }] + modulesPromise: ['Setting', function (Setting) { return Setting.query({ names: "['spaces_module', 'plans_module', 'invoicing_module', 'wallet_module', 'statistics_module', 'trainings_module', 'public_agenda_module']" }).$promise; }], + settingsPromise: ['Setting', function (Setting) { return Setting.query({ names: "['public_registrations']" }).$promise; }] }, onEnter: ['$rootScope', 'logoFile', 'logoBlackFile', 'modulesPromise', 'CSRF', function ($rootScope, logoFile, logoBlackFile, modulesPromise, CSRF) { // Retrieve Anti-CSRF tokens from cookies @@ -1081,7 +1082,8 @@ angular.module('application.router', ['ui.router']) "'reminder_delay', 'visibility_yearly', 'visibility_others', 'wallet_module', 'trainings_module', " + "'display_name_enable', 'machines_sort_by', 'fab_analytics', 'statistics_module', 'address_required', " + "'link_name', 'home_content', 'home_css', 'phone_required', 'upcoming_events_shown', 'public_agenda_module'," + - "'renew_pack_threshold', 'pack_only_for_subscription', 'overlapping_categories', 'extended_prices_in_same_day']" + "'renew_pack_threshold', 'pack_only_for_subscription', 'overlapping_categories', 'public_registrations'," + + "'extended_prices_in_same_day']" }).$promise; }], privacyDraftsPromise: ['Setting', function (Setting) { return Setting.get({ name: 'privacy_draft', history: true }).$promise; }], diff --git a/app/frontend/templates/admin/settings/general.html b/app/frontend/templates/admin/settings/general.html index 0de4db60f..d5282bdd1 100644 --- a/app/frontend/templates/admin/settings/general.html +++ b/app/frontend/templates/admin/settings/general.html @@ -412,6 +412,18 @@ {{ 'app.admin.settings.account_creation' }}
+
+

{{ 'app.admin.settings.general.public_registrations' }}

+

+ {{ 'app.admin.settings.general.public_registrations_info' }} +

+
+ + +
+

{{ 'app.admin.settings.phone' }}

diff --git a/app/frontend/templates/shared/header.html.erb b/app/frontend/templates/shared/header.html.erb index 41f1d16dc..4f61c2e8f 100644 --- a/app/frontend/templates/shared/header.html.erb +++ b/app/frontend/templates/shared/header.html.erb @@ -53,7 +53,7 @@

  • {{ 'app.public.common.sign_out' | translate }}
  • -
  • {{ 'app.public.common.sign_up' | translate }}
  • +
  • {{ 'app.public.common.sign_up' | translate }}
  • {{ 'app.public.common.sign_in' | translate }}
  • diff --git a/app/frontend/templates/shared/leftnav.html b/app/frontend/templates/shared/leftnav.html index 141504814..27b4f80d8 100644 --- a/app/frontend/templates/shared/leftnav.html +++ b/app/frontend/templates/shared/leftnav.html @@ -7,12 +7,12 @@