Development

This commit is contained in:
Matthew Grotke 2026-06-12 11:16:31 -04:00
parent c561f2f548
commit 1beb660be1
8 changed files with 280 additions and 48 deletions

View file

@ -37,6 +37,39 @@ def accountdetails_save():
return redirect(f'/{_PAGE}')
@bp.route('/action/preferences/email_change_request', methods=['POST'])
@auth.require_level('viewer')
def email_change_request():
new_email = sanitize.email(request.form.get('new_email', '').strip())
if not new_email:
flash('A valid email address is required.', 'error')
return redirect(f'/{_PAGE}')
current_email = session.get('email_address', '').lower()
if new_email == current_email:
flash('That is already your current email address.', 'error')
return redirect(f'/{_PAGE}')
if config_utils.get_account_by_email(new_email):
flash('That email address is already in use.', 'error')
return redirect(f'/{_PAGE}')
try:
con = config_utils.open_accounts_db()
con.execute(
'UPDATE accounts SET requested_email=? WHERE account_id=?',
(new_email, session.get('account_id', ''))
)
con.commit()
con.close()
except Exception as exc:
flash(f'Could not submit request: {exc}', 'error')
return redirect(f'/{_PAGE}')
flash('Email change request submitted. A manager will review it.', 'success')
return redirect(f'/{_PAGE}')
@bp.route('/action/preferences/changepassword_save', methods=['POST'])
@auth.require_level('viewer')
def changepassword_save():

View file

@ -23,31 +23,19 @@
"action": "/action/preferences/accountdetails_save",
"method": "post",
"items": [
{
"type": "field",
"label": "Email Address",
"name": "email",
"input_type": "text",
"value": "%PREF_EMAIL%",
"readonly": true,
"hint": "Contact your manager to change your email address."
},
{
"type": "field",
"label": "Timezone",
"name": "timezone",
"input_type": "select",
"value": "%PREF_TIMEZONE%",
"options": "%TIMEZONE_OPTIONS%",
"hint": "All timestamps will be displayed in this timezone."
"options": "%TIMEZONE_OPTIONS%"
},
{
"type": "button_row",
"items": [
{
"type": "button_primary",
"action": "/action/preferences/accountdetails_save",
"method": "post",
"text": "Save Preferences"
}
]
@ -56,6 +44,40 @@
}
]
},
{
"type": "card",
"label": "Change Email",
"items": [
{
"type": "raw_html",
"html": "%PENDING_EMAIL_BAR%"
},
{
"type": "form",
"action": "/action/preferences/email_change_request",
"method": "post",
"items": [
{
"type": "field",
"label": "Email Address",
"name": "new_email",
"input_type": "text",
"value": "%PREF_EMAIL%",
"placeholder": "New email address"
},
{
"type": "button_row",
"items": [
{
"type": "button_primary",
"text": "Submit Request"
}
]
}
]
}
]
},
{
"type": "card",
"label": "Change Password",
@ -91,8 +113,6 @@
"items": [
{
"type": "button_primary",
"action": "/action/preferences/changepassword_save",
"method": "post",
"text": "Change Password"
}
]
@ -102,4 +122,4 @@
]
}
]
}
}

View file

@ -2,12 +2,25 @@ import json
from flask import session
import sanitize
import config_utils
import factory
def collect_tokens(cfg):
tokens = config_utils.collect_layout_tokens(cfg)
blank = [{'value': '', 'label': '-- Select Timezone --'}]
tokens['PREF_EMAIL'] = session.get('email_address', '')
tokens['PREF_TIMEZONE'] = session.get('timezone', '')
tokens['TIMEZONE_OPTIONS'] = json.dumps(blank + [{'value': tz, 'label': tz} for tz in sanitize.VALID_TIMEZONES])
tokens['PREF_EMAIL'] = session.get('email_address', '')
tokens['PREF_TIMEZONE'] = session.get('timezone', '')
tokens['TIMEZONE_OPTIONS'] = json.dumps(blank + [{'value': tz, 'label': tz} for tz in sanitize.VALID_TIMEZONES])
account = config_utils.get_account_by_id(session.get('account_id', ''))
requested = (account or {}).get('requested_email', '')
if requested:
tokens['PENDING_EMAIL_BAR'] = (
f'<div class="info-bar info-bar-inline info-bar-warning">'
f'A request to change email to {factory.e(requested)} is pending approval.'
f'</div>'
)
else:
tokens['PENDING_EMAIL_BAR'] = ''
return tokens