From 661254b76edd51c36090edd0f898bdca16f23277 Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Tue, 26 Apr 2022 17:16:52 +0200 Subject: Add 'Add user' to Users section Creates "Add user" form with the following inputs: username, password, password confirmation, role (administrator or regular), allowed scopes. --- ogcp/forms/auth.py | 31 ++++++++++++++++- ogcp/static/js/ogcp.js | 22 ++++++++++++ ogcp/templates/auth/add_user.html | 26 ++++++++++++++ ogcp/templates/users.html | 2 ++ ogcp/views.py | 71 ++++++++++++++++++++++++++++++++++++++- 5 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 ogcp/templates/auth/add_user.html (limited to 'ogcp') diff --git a/ogcp/forms/auth.py b/ogcp/forms/auth.py index c02ecc7..b10d8fe 100644 --- a/ogcp/forms/auth.py +++ b/ogcp/forms/auth.py @@ -7,7 +7,7 @@ from wtforms import ( Form, SubmitField, HiddenField, SelectField, BooleanField, IntegerField, - StringField, RadioField, PasswordField + StringField, RadioField, PasswordField, SelectMultipleField ) from wtforms.validators import InputRequired from flask_wtf import FlaskForm @@ -28,3 +28,32 @@ class LoginForm(FlaskForm): submit_btn = SubmitField( label=_l('Login') ) + + +class UserForm(FlaskForm): + username = StringField( + label=_l('Username'), + validators=[InputRequired()] + ) + pwd = PasswordField( + label=_l('Password'), + ) + pwd_hash = HiddenField( + validators=[InputRequired()] + ) + pwd_confirm = PasswordField( + label=_l('Repeat password'), + ) + pwd_hash_confirm = HiddenField( + validators=[InputRequired()] + ) + admin = BooleanField( + label=_l('Administrator'), + ) + scopes = SelectMultipleField( + label=_l('Allowed scopes'), + description=_l('Leave this empty to give full permissions'), + ) + submit_btn = SubmitField( + label=_l('Submit') + ) diff --git a/ogcp/static/js/ogcp.js b/ogcp/static/js/ogcp.js index 6a7e625..4605e5d 100644 --- a/ogcp/static/js/ogcp.js +++ b/ogcp/static/js/ogcp.js @@ -231,3 +231,25 @@ function digestLoginPassword() { $(this).submit() }); } + +function digestUserFormPassword() { + const loginForm = $('#user-form') + loginForm.one('submit', async function (event) { + event.preventDefault() + + const pwdInput = $('#pwd'); + const pwdHashInput = $('#pwd_hash'); + const pwdStr = pwdInput.val(); + const pwdStrHash = await digestMessage(pwdStr); + + const pwdConfirmInput = $('#pwd_confirm'); + const pwdHashConfirmInput = $('#pwd_hash_confirm'); + const pwdConfirmStr = pwdConfirmInput.val(); + const pwdConfirmStrHash = await digestMessage(pwdConfirmStr); + + pwdInput.prop( "disabled", true ); + pwdHashInput.val(pwdStrHash); + pwdHashConfirmInput.val(pwdConfirmStrHash); + $(this).submit() + }); +} diff --git a/ogcp/templates/auth/add_user.html b/ogcp/templates/auth/add_user.html new file mode 100644 index 0000000..af44caa --- /dev/null +++ b/ogcp/templates/auth/add_user.html @@ -0,0 +1,26 @@ +{% extends 'users.html' %} +{% import "bootstrap/wtf.html" as wtf %} + +{% set sidebar_state = 'disabled' %} +{% set btn_back = true %} + +{% block nav_user_add %}active{% endblock %} +{% block content %} + +

{{_('Add a user')}}

+ +{{ wtf.quick_form(form, + action=url_for('user_add_post'), + method='post', + button_map={'submit_btn':'primary'}, + id='user-form') }} + + + +{% endblock %} diff --git a/ogcp/templates/users.html b/ogcp/templates/users.html index c97f113..c14aae6 100644 --- a/ogcp/templates/users.html +++ b/ogcp/templates/users.html @@ -24,6 +24,8 @@ {% endblock %} {% block commands %} + {% if btn_back %}