diff --git a/backend/src/appenlight/__init__.py b/backend/src/appenlight/__init__.py index bddd896..7d6f224 100644 --- a/backend/src/appenlight/__init__.py +++ b/backend/src/appenlight/__init__.py @@ -84,6 +84,11 @@ def main(global_config, **settings): encryption.ENCRYPTION_SECRET = settings.get('encryption_secret') # import this later so encyption key can be monkeypatched from appenlight.models import DBSession, register_datastores + + # registration + settings['appenlight.disable_registration'] = asbool( + settings.get('appenlight.disable_registration')) + # update config with cometd info settings['cometd_servers'] = {'server': settings['cometd.server'], 'secret': settings['cometd.secret']} diff --git a/backend/src/appenlight/views/index.py b/backend/src/appenlight/views/index.py index be47156..999f0b2 100644 --- a/backend/src/appenlight/views/index.py +++ b/backend/src/appenlight/views/index.py @@ -176,6 +176,10 @@ def register(request): if request.method == 'POST' and form.validate(): log.info('registering user') # insert new user here + if request.registry.settings['appenlight.disable_registration']: + request.session.flash(_('Registration is currently disabled.')) + return HTTPFound(location=request.route_url('/')) + new_user = User() DBSession.add(new_user) form.populate_obj(new_user) diff --git a/backend/src/appenlight/views/user.py b/backend/src/appenlight/views/user.py index eed2820..daa03a5 100644 --- a/backend/src/appenlight/views/user.py +++ b/backend/src/appenlight/views/user.py @@ -79,6 +79,10 @@ def users_create(request): csrf_context=request) if form.validate(): log.info('registering user') + # probably not needed in the future since this requires root anyways + # lets keep this here in case we lower view permission in the future + # if request.registry.settings['appenlight.disable_registration']: + # return HTTPUnprocessableEntity(body={'error': 'Registration is currently disabled.'}) user = User() # insert new user here DBSession.add(user)