From d6836915bbadfbab77d4c4f4584f433a2e747c01 Mon Sep 17 00:00:00 2001 From: Vivek Santayana Date: Mon, 20 Jun 2022 12:09:31 +0100 Subject: [PATCH] Prevent edit user from duplicating email address --- ref-test/app/models/user.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ref-test/app/models/user.py b/ref-test/app/models/user.py index a1cec1d..cd945c2 100644 --- a/ref-test/app/models/user.py +++ b/ref-test/app/models/user.py @@ -189,7 +189,10 @@ class User(UserMixin, db.Model): if not password and not email: return False, 'There were no changes requested.' if password: self.set_password(password) old_email = self.get_email() - if email: self.set_email(email) + if email: + for entry in User.query.all(): + 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()}.') if notify: