mail notification
This commit is contained in:
@@ -9,3 +9,5 @@ class UserFormData:
|
||||
garmin_email: str
|
||||
garmin_password: str
|
||||
enabled: bool
|
||||
notify_email_enabled: bool = False
|
||||
notification_email: str = ""
|
||||
|
||||
@@ -96,6 +96,8 @@ def create_user(
|
||||
garmin_email: str = Form(""),
|
||||
garmin_password: str = Form(""),
|
||||
enabled: str | None = Form(None),
|
||||
notify_email_enabled: str | None = Form(None),
|
||||
notification_email: str = Form(""),
|
||||
):
|
||||
require_admin(request)
|
||||
validate_csrf(request, csrf_token)
|
||||
@@ -110,7 +112,11 @@ def create_user(
|
||||
garmin_email=garmin_email,
|
||||
garmin_password=garmin_password,
|
||||
enabled=enabled is not None,
|
||||
notify_email_enabled=notify_email_enabled is not None,
|
||||
notification_email=notification_email,
|
||||
)
|
||||
if form.notify_email_enabled:
|
||||
_require_non_empty(form.notification_email, "notification_email")
|
||||
cipher = _cipher(request)
|
||||
with request.app.state.session_factory() as session:
|
||||
repository = UserRepository(session)
|
||||
@@ -121,6 +127,8 @@ def create_user(
|
||||
mywhoosh_password_enc=cipher.encrypt(form.mywhoosh_password),
|
||||
garmin_email_enc=cipher.encrypt(form.garmin_email.strip()),
|
||||
garmin_password_enc=cipher.encrypt(form.garmin_password),
|
||||
notify_email_enabled=form.notify_email_enabled,
|
||||
notification_email=form.notification_email.strip() or None,
|
||||
)
|
||||
user_id = user.id
|
||||
return RedirectResponse(f"/users/{user_id}", status_code=303)
|
||||
@@ -175,6 +183,8 @@ def update_user(
|
||||
garmin_email: str = Form(""),
|
||||
garmin_password: str = Form(""),
|
||||
enabled: str | None = Form(None),
|
||||
notify_email_enabled: str | None = Form(None),
|
||||
notification_email: str = Form(""),
|
||||
):
|
||||
require_admin(request)
|
||||
validate_csrf(request, csrf_token)
|
||||
@@ -187,7 +197,11 @@ def update_user(
|
||||
garmin_email=garmin_email,
|
||||
garmin_password=garmin_password,
|
||||
enabled=enabled is not None,
|
||||
notify_email_enabled=notify_email_enabled is not None,
|
||||
notification_email=notification_email,
|
||||
)
|
||||
if form.notify_email_enabled:
|
||||
_require_non_empty(form.notification_email, "notification_email")
|
||||
cipher = _cipher(request)
|
||||
with request.app.state.session_factory() as session:
|
||||
repository = UserRepository(session)
|
||||
@@ -197,6 +211,8 @@ def update_user(
|
||||
"enabled": form.enabled,
|
||||
"mywhoosh_email_enc": cipher.encrypt(form.mywhoosh_email.strip()),
|
||||
"garmin_email_enc": cipher.encrypt(form.garmin_email.strip()),
|
||||
"notify_email_enabled": form.notify_email_enabled,
|
||||
"notification_email": form.notification_email.strip() or None,
|
||||
}
|
||||
if form.mywhoosh_password:
|
||||
values["mywhoosh_password_enc"] = cipher.encrypt(form.mywhoosh_password)
|
||||
|
||||
@@ -36,6 +36,16 @@
|
||||
Enabled
|
||||
</label>
|
||||
|
||||
<label for="notify_email_enabled">
|
||||
<input type="checkbox" id="notify_email_enabled" name="notify_email_enabled"
|
||||
{% if user and user.notify_email_enabled %}checked{% endif %}>
|
||||
Email me when this account needs attention
|
||||
</label>
|
||||
|
||||
<label for="notification_email">Notification email</label>
|
||||
<input type="email" id="notification_email" name="notification_email"
|
||||
value="{{ user.notification_email if user and user.notification_email else '' }}">
|
||||
|
||||
<button type="submit">{% if user %}Save{% else %}Create{% endif %}</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user