Added the ability to disable registration in the config file
This commit is contained in:
parent
a1fbeb91a0
commit
a5211d9483
2 changed files with 21 additions and 16 deletions
|
@ -51,6 +51,8 @@ enable_safety: yes
|
||||||
tag_name_regex: ^\S+$
|
tag_name_regex: ^\S+$
|
||||||
tag_category_name_regex: ^[^\s%+#/]+$
|
tag_category_name_regex: ^[^\s%+#/]+$
|
||||||
|
|
||||||
|
# Disable registration by setting false
|
||||||
|
registration_enabled: true
|
||||||
|
|
||||||
# don't make these more restrictive unless you want to annoy people; if you do
|
# don't make these more restrictive unless you want to annoy people; if you do
|
||||||
# customize them, make sure to update the instructions in the registration form
|
# customize them, make sure to update the instructions in the registration form
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
from szurubooru import model, search, rest
|
from szurubooru import model, search, rest, config, errors
|
||||||
from szurubooru.func import auth, users, serialization, versions
|
from szurubooru.func import auth, users, serialization, versions
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,21 +26,24 @@ def get_users(
|
||||||
@rest.routes.post('/users/?')
|
@rest.routes.post('/users/?')
|
||||||
def create_user(
|
def create_user(
|
||||||
ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response:
|
ctx: rest.Context, _params: Dict[str, str] = {}) -> rest.Response:
|
||||||
auth.verify_privilege(ctx.user, 'users:create')
|
if config.config['registration_enabled']:
|
||||||
name = ctx.get_param_as_string('name')
|
auth.verify_privilege(ctx.user, 'users:create')
|
||||||
password = ctx.get_param_as_string('password')
|
name = ctx.get_param_as_string('name')
|
||||||
email = ctx.get_param_as_string('email', default='')
|
password = ctx.get_param_as_string('password')
|
||||||
user = users.create_user(name, password, email)
|
email = ctx.get_param_as_string('email', default='')
|
||||||
if ctx.has_param('rank'):
|
user = users.create_user(name, password, email)
|
||||||
users.update_user_rank(user, ctx.get_param_as_string('rank'), ctx.user)
|
if ctx.has_param('rank'):
|
||||||
if ctx.has_param('avatarStyle'):
|
users.update_user_rank(user, ctx.get_param_as_string('rank'), ctx.user)
|
||||||
users.update_user_avatar(
|
if ctx.has_param('avatarStyle'):
|
||||||
user,
|
users.update_user_avatar(
|
||||||
ctx.get_param_as_string('avatarStyle'),
|
user,
|
||||||
ctx.get_file('avatar', default=b''))
|
ctx.get_param_as_string('avatarStyle'),
|
||||||
ctx.session.add(user)
|
ctx.get_file('avatar', default=b''))
|
||||||
ctx.session.commit()
|
ctx.session.add(user)
|
||||||
return _serialize(ctx, user, force_show_email=True)
|
ctx.session.commit()
|
||||||
|
return _serialize(ctx, user, force_show_email=True)
|
||||||
|
else:
|
||||||
|
raise errors.ValidationError('User Registration Disabled')
|
||||||
|
|
||||||
|
|
||||||
@rest.routes.get('/user/(?P<user_name>[^/]+)/?')
|
@rest.routes.get('/user/(?P<user_name>[^/]+)/?')
|
||||||
|
|
Loading…
Reference in a new issue