From 8ce54274062ceb11bfa7702a57a9c9e0ce274bdd Mon Sep 17 00:00:00 2001 From: KF7EEL Date: Sat, 9 Oct 2021 10:26:21 -0700 Subject: [PATCH] fix login and mail templates, fix manual user creation, add APRS to web service --- web/app.py | 32 +++++++++++++++++++++++++---- web/templates/flask_user/login.html | 4 +++- web/templates/mail.html | 13 +++++++++--- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/web/app.py b/web/app.py index ae1cae4..4eca4f3 100644 --- a/web/app.py +++ b/web/app.py @@ -166,7 +166,7 @@ def hbnet_web_service(): dmr_ids = db.Column(db.String(1000), nullable=False, server_default='') city = db.Column(db.String(100), nullable=False, server_default='') notes = db.Column(db.String(2000), nullable=False, server_default='') - aprs = db.Column(db.String(2000), nullable=False, server_default='') + aprs = db.Column(db.String(2000), nullable=False, server_default='{}') #Used for initial approval initial_admin_approved = db.Column('initial_admin_approved', db.Boolean(), nullable=False, server_default='1') # Define the relationship to Role via UserRoles @@ -589,7 +589,8 @@ def hbnet_web_service(): password=user_manager.hash_password('admin'), initial_admin_approved = True, notes='Default admin account created during installation.', - dmr_ids='{}' + dmr_ids='{}', + aprs = '{}' ) user.roles.append(Role(name='Admin')) user.roles.append(Role(name='User')) @@ -644,6 +645,7 @@ def hbnet_web_service(): # Query radioid.net for list of DMR IDs, then add to DB @user_registered.connect_via(app) def _after_user_registered_hook(sender, user, **extra): + aprs_dict = {} edit_user = User.query.filter(User.username == user.username).first() radioid_data = ast.literal_eval(get_ids(user.username)) ## edit_user.notes = '' @@ -651,6 +653,9 @@ def hbnet_web_service(): edit_user.first_name = str(radioid_data[1]) edit_user.last_name = str(radioid_data[2]) edit_user.city = str(radioid_data[3]) + for i in radioid_data[0].items(): + aprs_dict[i[0]] = 'default' + edit_user.aprs = str(aprs_dict) user_role = UserRoles( user_id=edit_user.id, role_id=2, @@ -659,6 +664,9 @@ def hbnet_web_service(): if default_account_state == False: edit_user.active = default_account_state edit_user.initial_admin_approved = False + if USER_ENABLE_CONFIRM_EMAIL == False: + edit_user.email_confirmed_at = datetime.datetime.utcnow() + db.session.commit() def gen_passphrase(dmr_id): @@ -1193,6 +1201,12 @@ def hbnet_web_service(): if request.form.get('email') != edit_user.email: edit_user.email = request.form.get('email') content = content + '''

Changed email for user: ''' + str(user) + ''' to ''' + request.form.get('email') + '''

\n''' + if request.form.get('aprs') != edit_user.aprs: + edit_user.aprs = request.form.get('aprs') + content = content + '''

Changed APRS settings for user: ''' + str(user) + ''' to ''' + request.form.get('aprs') + '''

\n''' + + + if request.form.get('notes') != edit_user.notes: edit_user.notes = request.form.get('notes') content = content + '''

Changed notes for user: ''' + str(user) + '''.

\n''' @@ -1411,9 +1425,13 @@ def hbnet_web_service(): -


+


+ + +


+ @@ -2492,6 +2510,7 @@ TG #: ''' + str(tg_d.tg) + ''' @app.route('/mail/', methods=['GET', 'POST']) @login_required def get_mail(user): + show_mailbox = False if current_user.username == user: if request.args.get('delete_mail'): mailbox_del(int(request.args.get('delete_mail'))) @@ -2508,6 +2527,7 @@ TG #: ''' + str(tg_d.tg) + ''' ''' else: + show_mailbox = True mail_all = MailBox.query.filter_by(rcv_callsign=user.upper()).order_by(MailBox.time.desc()).all() content = '' for i in mail_all: @@ -2520,7 +2540,7 @@ TG #: ''' + str(tg_d.tg) + ''' ''' else: content = '

Not your mailbox.

' - return render_template('mail.html', markup_content = Markup(content), user_id = user) + return render_template('mail.html', markup_content = Markup(content), user_id = user, show_mail = show_mailbox) @app.route('/talkgroups/') #, methods=['POST', 'GET']) @@ -5817,10 +5837,14 @@ Name: ''' + p.name + '''  -  Port: ''' + str( elif request.method == 'POST' and request.form.get('username'): if not User.query.filter(User.username == request.form.get('username')).first(): radioid_data = ast.literal_eval(get_ids(request.form.get('username'))) + aprs_dict = {} + for i in radioid_data[0].items(): + aprs_dict[i[0]] = 'default' user = User( username=request.form.get('username'), email=request.form.get('email'), email_confirmed_at=datetime.datetime.utcnow(), + aprs = str(aprs_dict), password=user_manager.hash_password(request.form.get('password')), dmr_ids = str(radioid_data[0]), initial_admin_approved = True, diff --git a/web/templates/flask_user/login.html b/web/templates/flask_user/login.html index 2a8271f..fc33452 100644 --- a/web/templates/flask_user/login.html +++ b/web/templates/flask_user/login.html @@ -29,7 +29,9 @@ {{ field(class_='form-control', tabindex=110) }} {% if field.errors %} {% for e in field.errors %} -

{{ e }}

+   + +

{{ e }}

{% endfor %} {% endif %} diff --git a/web/templates/mail.html b/web/templates/mail.html index 1f5f09a..52d71a2 100644 --- a/web/templates/mail.html +++ b/web/templates/mail.html @@ -4,9 +4,8 @@

Mail

-

-
+
Send internal message to another user
@@ -32,9 +31,10 @@
- +{% if show_mail %}
+

@@ -54,6 +54,13 @@ +{% endif %} + +{% if not show_mail %} + {{markup_content}} + +{% endif %} +