Skip to content

Commit

Permalink
1939/template notification (privacyidea#1940)
Browse files Browse the repository at this point in the history
* Read the email notification from a file

This would also work for the savefile handler

Closes privacyidea#1939

* Add missing traceback
  • Loading branch information
cornelinux authored and local committed Mar 5, 2021
1 parent 9cb7b02 commit 52d7347
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions privacyidea/lib/eventhandler/usernotification.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
from privacyidea.lib import _
import logging
import os
import traceback

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -293,6 +294,16 @@ def do(self, action, options=None):
# In case of "savefile" we do not need a recipient
# Collect all data
body = handler_options.get("body") or DEFAULT_BODY
if body.startswith("file:"): # pragma no cover
# We read the template from the file.
filename = body[5:]
try:
with open(filename, "r") as f:
body = f.read()
except Exception as e:
log.warning(u"Failed to read email template from file {0!r}: {1!r}".format(filename, e))
log.debug(u"{0!s}".format(traceback.format_exc()))

subject = handler_options.get("subject") or \
"An action was performed on your token."
serial = request.all_data.get("serial") or \
Expand Down

0 comments on commit 52d7347

Please sign in to comment.