From e787f9dd9fd2ebf8ec87568afdd80baf94d06127 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Tue, 12 May 2020 17:23:58 +0200 Subject: [PATCH] Automatic username (#1172) --- cps/admin.py | 1 + cps/config_sql.py | 1 + cps/static/css/style.css | 3 ++- cps/templates/config_edit.html | 2 +- cps/templates/register.html | 2 ++ cps/web.py | 15 +++++++++------ 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cps/admin.py b/cps/admin.py index 8f627bd2..d20a0100 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -635,6 +635,7 @@ def _configuration_update_helper(): _config_checkbox_int(to_save, "config_uploading") _config_checkbox_int(to_save, "config_anonbrowse") _config_checkbox_int(to_save, "config_public_reg") + _config_checkbox_int(to_save, "config_register_email") reboot_required |= _config_checkbox_int(to_save, "config_kobo_sync") _config_checkbox_int(to_save, "config_kobo_proxy") diff --git a/cps/config_sql.py b/cps/config_sql.py index 08636f6d..ab464d0d 100644 --- a/cps/config_sql.py +++ b/cps/config_sql.py @@ -77,6 +77,7 @@ class _Settings(_Base): config_uploading = Column(SmallInteger, default=0) config_anonbrowse = Column(SmallInteger, default=0) config_public_reg = Column(SmallInteger, default=0) + config_register_email = Column(SmallInteger, default=0) config_remote_login = Column(Boolean, default=False) config_kobo_sync = Column(Boolean, default=False) diff --git a/cps/static/css/style.css b/cps/static/css/style.css index 42d71eda..9ec0d7fe 100644 --- a/cps/static/css/style.css +++ b/cps/static/css/style.css @@ -213,7 +213,7 @@ span.glyphicon.glyphicon-tags { .panel-body {background-color: #f5f5f5; } .spinner {margin: 0 41%; } .spinner2 {margin: 0 41%; } - +.intend-form { margin-left:20px; } table .bg-dark-danger {background-color: #d9534f; color: #fff; } table .bg-dark-danger a {color: #fff; } table .bg-dark-danger:hover {background-color: #c9302c; } @@ -302,3 +302,4 @@ div.log { white-space: nowrap; padding: 0.5em; } + diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index a9fb23b0..77a60c1b 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -179,7 +179,7 @@
-
+
diff --git a/cps/templates/register.html b/cps/templates/register.html index 0e218ec2..043378c3 100644 --- a/cps/templates/register.html +++ b/cps/templates/register.html @@ -3,10 +3,12 @@

{{_('Register New Account')}}

+ {% if not config.config_register_email %}
+ {% endif %}
diff --git a/cps/web.py b/cps/web.py index 7d3a80bb..0e6a1b9a 100644 --- a/cps/web.py +++ b/cps/web.py @@ -1285,30 +1285,33 @@ def register(): if request.method == "POST": to_save = request.form.to_dict() - if not to_save["nickname"] or not to_save["email"]: + if config.config_register_email: + nickname = to_save["email"] + else: + nickname = to_save["nickname"] + if not nickname or not to_save["email"]: flash(_(u"Please fill out all fields!"), category="error") return render_title_template('register.html', title=_(u"register"), page="register") - existing_user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == to_save["nickname"] + + existing_user = ub.session.query(ub.User).filter(func.lower(ub.User.nickname) == nickname .lower()).first() existing_email = ub.session.query(ub.User).filter(ub.User.email == to_save["email"].lower()).first() if not existing_user and not existing_email: content = ub.User() - # content.password = generate_password_hash(to_save["password"]) if check_valid_domain(to_save["email"]): - content.nickname = to_save["nickname"] + content.nickname = nickname content.email = to_save["email"] password = generate_random_password() content.password = generate_password_hash(password) content.role = config.config_default_role content.sidebar_view = config.config_default_show - # content.mature_content = bool(config.config_default_show & constants.MATURE_CONTENT) try: ub.session.add(content) ub.session.commit() if feature_support['oauth']: register_user_with_oauth(content) - send_registration_mail(to_save["email"], to_save["nickname"], password) + send_registration_mail(to_save["email"], nickname, password) except Exception: ub.session.rollback() flash(_(u"An unknown error occurred. Please try again later."), category="error")