From 68314a4ed232f256ff1540819d68cf9e1d9d414e Mon Sep 17 00:00:00 2001 From: Vivek Santayana Date: Thu, 11 Aug 2022 16:28:47 +0100 Subject: [PATCH] Add handling of anonymous user when updating account --- ref-test/app/models/user.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ref-test/app/models/user.py b/ref-test/app/models/user.py index cd945c2..c2a5d81 100644 --- a/ref-test/app/models/user.py +++ b/ref-test/app/models/user.py @@ -194,7 +194,8 @@ class User(UserMixin, db.Model): if entry.get_email() == email and not entry == self: return False, f'The email address {email} is already in use.' self.set_email(email) db.session.commit() - write('system.log', f'Information for user {self.get_username()} has been updated by {current_user.get_username()}.') + _current_user = current_user.get_username() if current_user.is_authenticated else 'anonymous' + write('system.log', f'Information for user {self.get_username()} has been updated by {_current_user}.') if notify: message = Message( subject='RefTest | Account Update', @@ -202,7 +203,7 @@ class User(UserMixin, db.Model): bcc=[old_email,current_user.get_email()], body=f""" Hello {self.get_username()},\n\n - Your administrator account for the SKA RefTest App has been updated by {current_user.get_username()}.\n\n + Your administrator account for the SKA RefTest App has been updated by {_current_user}.\n\n Your new account details are as follows:\n\n Email: {email}\n Password: {password if password else ''}\n\n @@ -213,7 +214,7 @@ class User(UserMixin, db.Model): """, html=f"""

Hello {self.get_username()},

-

Your administrator account for the SKA RefTest App has been updated by {current_user.get_username()}.

+

Your administrator account for the SKA RefTest App has been updated by {_current_user}.

Your new account details are as follows:

Email: {email}
Password: {password if password else '<same as old>'}

You can update your email address and password by logging in to the admin console using the following URL: