From c00ddea2fc1a1e0a8e78a2e7011c5f4825924274 Mon Sep 17 00:00:00 2001 From: Tyler Todd Date: Mon, 13 Feb 2023 03:57:21 +0000 Subject: [PATCH] More page formatting Added server-side logic for register.html validation Keep form firelds on register.html in the event of wrong input fields to save users from retyping info More button rounding --- powerdnsadmin/routes/index.py | 108 +++--- .../templates/admin_edit_account.html | 15 +- powerdnsadmin/templates/admin_edit_key.html | 109 +++--- .../templates/admin_global_search.html | 353 +++++++++--------- powerdnsadmin/templates/admin_history.html | 23 +- .../templates/admin_history_table.html | 2 +- .../templates/admin_manage_account.html | 21 +- .../templates/admin_manage_keys.html | 107 +++--- .../templates/admin_manage_user.html | 347 ++++++++--------- powerdnsadmin/templates/admin_pdns_stats.html | 203 +++++----- .../templates/admin_setting_basic.html | 80 ++-- .../templates/admin_setting_pdns.html | 181 +++++---- .../templates/admin_setting_records.html | 148 ++++---- powerdnsadmin/templates/base.html | 4 +- powerdnsadmin/templates/dashboard.html | 78 ++-- powerdnsadmin/templates/domain_add.html | 8 +- powerdnsadmin/templates/domain_changelog.html | 9 +- powerdnsadmin/templates/domain_remove.html | 12 +- powerdnsadmin/templates/domain_setting.html | 10 +- powerdnsadmin/templates/register.html | 171 +++++---- powerdnsadmin/templates/template.html | 198 +++++----- powerdnsadmin/templates/template_add.html | 160 ++++---- powerdnsadmin/templates/template_edit.html | 10 +- powerdnsadmin/templates/user_profile.html | 2 +- 24 files changed, 1234 insertions(+), 1125 deletions(-) diff --git a/powerdnsadmin/routes/index.py b/powerdnsadmin/routes/index.py index 98664d6..cd93181 100644 --- a/powerdnsadmin/routes/index.py +++ b/powerdnsadmin/routes/index.py @@ -400,7 +400,7 @@ def login(): desc_prop = Setting().get('oidc_oauth_account_description_property') account_to_add = [] - #If the name_property and desc_property exist in me (A variable that contains all the userinfo from the IdP). + #If the name_property and desc_property exist in me (A variable that contains all the userinfo from the IdP). if name_prop in me and desc_prop in me: accounts_name_prop = [me[name_prop]] if type(me[name_prop]) is not list else me[name_prop] accounts_desc_prop = [me[desc_prop]] if type(me[desc_prop]) is not list else me[desc_prop] @@ -415,7 +415,7 @@ def login(): account_to_add.append(account) user_accounts = user.get_accounts() - # Add accounts + # Add accounts for account in account_to_add: if account not in user_accounts: account.add_user(user) @@ -651,55 +651,73 @@ def logout(): @index_bp.route('/register', methods=['GET', 'POST']) def register(): - CAPTCHA_ENABLE = current_app.config.get('CAPTCHA_ENABLE') - if Setting().get('signup_enabled'): - if request.method == 'GET': - return render_template('register.html', captcha_enable=CAPTCHA_ENABLE) - elif request.method == 'POST': - username = request.form.get('username', '').strip() - password = request.form.get('password', '') - firstname = request.form.get('firstname', '').strip() - lastname = request.form.get('lastname', '').strip() - email = request.form.get('email', '').strip() - rpassword = request.form.get('rpassword', '') + CAPTCHA_ENABLE = current_app.config.get('CAPTCHA_ENABLE') + if Setting().get('signup_enabled'): + if current_user.is_authenticated: + return redirect(url_for('index.index')) + if request.method == 'GET': + return render_template('register.html', captcha_enable=CAPTCHA_ENABLE) + elif request.method == 'POST': + username = request.form.get('username', '').strip() + password = request.form.get('password', '') + firstname = request.form.get('firstname', '').strip() + lastname = request.form.get('lastname', '').strip() + email = request.form.get('email', '').strip() + rpassword = request.form.get('rpassword', '') - if not username or not password or not email: - return render_template( - 'register.html', error='Please input required information', captcha_enable=CAPTCHA_ENABLE) + is_valid_email = re.compile(r'[\w\.-]+@[\w\.-]+') - if password != rpassword: - return render_template( - 'register.html', - error="Password confirmation does not match", captcha_enable=CAPTCHA_ENABLE) + error_messages = {} + if not firstname: + error_messages['firstname'] = 'First Name is required' + if not lastname: + error_messages['lastname'] = 'Last Name is required' + if not username: + error_messages['username'] = 'Username is required' + if not password: + error_messages['password'] = 'Password is required' + if not rpassword: + error_messages['rpassword'] = 'Password confirmation is required' + if not email: + error_messages['email'] = 'Email is required' + if not is_valid_email.match(email): + error_messages['email'] = 'Invalid email address' + if password != rpassword: + error_messages['password'] = 'Password confirmation does not match' + error_messages['rpassword'] = 'Password confirmation does not match' - if not captcha.validate(): - return render_template( - 'register.html', error='Invalid CAPTCHA answer', captcha_enable=CAPTCHA_ENABLE) + if not captcha.validate(): + return render_template( + 'register.html', error='Invalid CAPTCHA answer', error_messages=error_messages, captcha_enable=CAPTCHA_ENABLE) - user = User(username=username, - plain_text_password=password, - firstname=firstname, - lastname=lastname, - email=email) + if error_messages: + return render_template('register.html', error_messages=error_messages, captcha_enable=CAPTCHA_ENABLE) - try: - result = user.create_local_user() - if result and result['status']: - if Setting().get('verify_user_email'): - send_account_verification(email) - if Setting().get('otp_force') and Setting().get('otp_field_enabled'): - user.update_profile(enable_otp=True) - prepare_welcome_user(user.id) - return redirect(url_for('index.welcome')) - else: - return redirect(url_for('index.login')) - else: - return render_template('register.html', - error=result['msg'], captcha_enable=CAPTCHA_ENABLE) - except Exception as e: - return render_template('register.html', error=e, captcha_enable=CAPTCHA_ENABLE) + user = User(username=username, + plain_text_password=password, + firstname=firstname, + lastname=lastname, + email=email + ) + + try: + result = user.create_local_user() + if result and result['status']: + if Setting().get('verify_user_email'): + send_account_verification(email) + if Setting().get('otp_force') and Setting().get('otp_field_enabled'): + user.update_profile(enable_otp=True) + prepare_welcome_user(user.id) + return redirect(url_for('index.welcome')) + else: + return redirect(url_for('index.login')) + else: + return render_template('register.html', + error=result['msg'], captcha_enable=CAPTCHA_ENABLE) + except Exception as e: + return render_template('register.html', error=e, captcha_enable=CAPTCHA_ENABLE) else: - return render_template('errors/404.html'), 404 + return render_template('errors/404.html'), 404 # Show welcome page on first login if otp_force is enabled diff --git a/powerdnsadmin/templates/admin_edit_account.html b/powerdnsadmin/templates/admin_edit_account.html index 0fc0b30..62ccf26 100644 --- a/powerdnsadmin/templates/admin_edit_account.html +++ b/powerdnsadmin/templates/admin_edit_account.html @@ -1,9 +1,14 @@ {% extends "base.html" %} + {% set active_page = "admin_accounts" %} -{% block title %}Edit Account - {{ SITE_NAME }}{% endblock %} + +{% block title %} + + Edit Account - {{ SITE_NAME }} + +{% endblock %} {% block dashboard_stat %} -
@@ -30,7 +35,7 @@
-
+

{% if create %}Add{% else %}Edit{% endif %} account

@@ -107,8 +112,8 @@
-
-
+
+

Help with creating a new account

diff --git a/powerdnsadmin/templates/admin_edit_key.html b/powerdnsadmin/templates/admin_edit_key.html index a0e7a88..1d8e696 100644 --- a/powerdnsadmin/templates/admin_edit_key.html +++ b/powerdnsadmin/templates/admin_edit_key.html @@ -1,12 +1,17 @@ {% extends "base.html" %} + {% set active_page = "admin_keys" %} + {% if (key is not none and key.role.name != "User") %}{% set hide_opts = True %}{%else %}{% set hide_opts = False %}{% endif %} + {% block title %} -Edit Key - {{ SITE_NAME }} + + Edit Key - {{ SITE_NAME }} + {% endblock %} + {% block dashboard_stat %} - -
+
@@ -25,61 +30,59 @@
- {% endblock %} {% block content %}
+
-
-
-

{% if create %}Add{% else %}Edit{% endif %} Key

-
- - -
- - -
-
- - -
-
- - -
-
- - - +
+
+

{% if create %}Add{% else %}Edit{% endif %} Key

+
+ + + +
+
+ + +
+
+ + + +
+
+ + +
+
{% endblock %} + {% block extrascripts %} - - + {% endblock %} diff --git a/powerdnsadmin/templates/admin_history.html b/powerdnsadmin/templates/admin_history.html index 5b96c09..21c2758 100644 --- a/powerdnsadmin/templates/admin_history.html +++ b/powerdnsadmin/templates/admin_history.html @@ -1,11 +1,15 @@ {% extends "base.html" %} -{% set active_page = "admin_history" %} -{% block title %} -History - {{ SITE_NAME }} -{% endblock %} {% block dashboard_stat %} - -
+{% set active_page = "admin_history" %} + +{% block title %} + + History - {{ SITE_NAME }} + +{% endblock %} + +{% block dashboard_stat %} +
@@ -23,17 +27,14 @@
- {% endblock %} + {% block content %} {% import 'applied_change_macro.html' as applied_change_macro %} - - -
-
+

History Management

diff --git a/powerdnsadmin/templates/admin_history_table.html b/powerdnsadmin/templates/admin_history_table.html index 537ba2a..146e7db 100644 --- a/powerdnsadmin/templates/admin_history_table.html +++ b/powerdnsadmin/templates/admin_history_table.html @@ -6,7 +6,7 @@

{% endif %} -
+
diff --git a/powerdnsadmin/templates/admin_manage_account.html b/powerdnsadmin/templates/admin_manage_account.html index e56705c..f0c79cc 100644 --- a/powerdnsadmin/templates/admin_manage_account.html +++ b/powerdnsadmin/templates/admin_manage_account.html @@ -1,9 +1,15 @@ {% extends "base.html" %} + {% set active_page = "admin_accounts" %} + {% block title %} -Account Management - {{ SITE_NAME }} -{% endblock %} {% block dashboard_stat %} -
+ + Account Management - {{ SITE_NAME }} + +{% endblock %} + +{% block dashboard_stat %} +
@@ -21,12 +27,13 @@
+{% endblock %} -{% endblock %} {% block content %} +{% block content %}
-
+

Account Management

@@ -133,8 +140,8 @@

diff --git a/powerdnsadmin/templates/admin_manage_keys.html b/powerdnsadmin/templates/admin_manage_keys.html index 9f2c682..e303cd6 100644 --- a/powerdnsadmin/templates/admin_manage_keys.html +++ b/powerdnsadmin/templates/admin_manage_keys.html @@ -1,9 +1,15 @@ {% extends "base.html" %} + {% set active_page = "admin_keys" %} + {% block title %} -Key Management - {{ SITE_NAME }} -{% endblock %} {% block dashboard_stat %} -
+ + Key Management - {{ SITE_NAME }} + +{% endblock %} + +{% block dashboard_stat %} +
@@ -21,7 +27,9 @@
-{% endblock %} {% block content %} +{% endblock %} + +{% block content %}
@@ -74,63 +82,62 @@
{% endblock %} + {% block extrascripts %} - + {% endblock %} + {% block modals %} -
- - - - - - - - - - - - - {% for user in users %} - - - - - - - - - - {% endfor %} - -
UsernameFirst NameLast NameEmailRolePrivilegesAction
{{ user.username }}{{ user.firstname }}{{ user.lastname }}{{ user.email }} - - - - - - -
-
- -
- -
- -
- -
-
{% endblock %} + +{% block content %} +
+
+
+
+
+
+

User Management

+
+ +
+ + + + + + + + + + + + + + {% for user in users %} + + + + + + + + + + {% endfor %} + +
UsernameFirst NameLast NameEmailRolePrivilegesAction
{{ user.username }}{{ user.firstname }}{{ user.lastname }}{{ user.email }} + + + + + + +
+
+
+
+
+
+
+{% endblock %} + {% block extrascripts %} - + {% endblock %} + {% block modals %} -