Compare commits

...

2 Commits

2 changed files with 6 additions and 5 deletions

View File

@ -117,7 +117,7 @@ def _reset():
user.clear_reset_tokens() user.clear_reset_tokens()
if request.args.get('verification') == verification_token: if request.args.get('verification') == verification_token:
form = UpdatePassword() form = UpdatePassword()
session['user_id'] = user.id session['user'] = user.id
return render_template('/admin/auth/update-password.html', form=form) return render_template('/admin/auth/update-password.html', form=form)
flash('The verification of your password reset request failed and the token has been invalidated. Please make a new reset password request.', 'error') flash('The verification of your password reset request failed and the token has been invalidated. Please make a new reset password request.', 'error')
@ -127,7 +127,7 @@ def _reset():
def _update_password(): def _update_password():
form = UpdatePassword() form = UpdatePassword()
if form.validate_on_submit(): if form.validate_on_submit():
user = session.pop('user_id') user = session.pop('user')
user = User.query.filter_by(id=user).first() user = User.query.filter_by(id=user).first()
user.update(password=request.form.get('password')) user.update(password=request.form.get('password'))
session['remembered_username'] = user.get_username() session['remembered_username'] = user.get_username()

View File

@ -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.' if entry.get_email() == email and not entry == self: return False, f'The email address {email} is already in use.'
self.set_email(email) self.set_email(email)
db.session.commit() 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: if notify:
message = Message( message = Message(
subject='RefTest | Account Update', subject='RefTest | Account Update',
@ -202,7 +203,7 @@ class User(UserMixin, db.Model):
bcc=[old_email,current_user.get_email()], bcc=[old_email,current_user.get_email()],
body=f""" body=f"""
Hello {self.get_username()},\n\n 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 Your new account details are as follows:\n\n
Email: {email}\n Email: {email}\n
Password: {password if password else '<same as old>'}\n\n Password: {password if password else '<same as old>'}\n\n
@ -213,7 +214,7 @@ class User(UserMixin, db.Model):
""", """,
html=f""" html=f"""
<p>Hello {self.get_username()},</p> <p>Hello {self.get_username()},</p>
<p>Your administrator account for the SKA RefTest App has been updated by {current_user.get_username()}.</p> <p>Your administrator account for the SKA RefTest App has been updated by {_current_user}.</p>
<p>Your new account details are as follows:</p> <p>Your new account details are as follows:</p>
<p>Email: {email} <br/> Password: <strong>{password if password else '&lt;same as old&gt;'}</strong></p> <p>Email: {email} <br/> Password: <strong>{password if password else '&lt;same as old&gt;'}</strong></p>
<p>You can update your email address and password by logging in to the admin console using the following URL:</p> <p>You can update your email address and password by logging in to the admin console using the following URL:</p>