From 4e2bf89784ed8c4f214cda52ebcae9b01e152094 Mon Sep 17 00:00:00 2001 From: AlexandreDoneux <94830560+AlexandreDoneux@users.noreply.github.com> Date: Wed, 10 Jan 2024 16:38:14 +0100 Subject: [PATCH] [frontend/profile] Fixing users without password couldn't define new password --- .../frontend/pages/preferences/profile.py | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/inginious/frontend/pages/preferences/profile.py b/inginious/frontend/pages/preferences/profile.py index cb34e573b..316c53ae0 100644 --- a/inginious/frontend/pages/preferences/profile.py +++ b/inginious/frontend/pages/preferences/profile.py @@ -59,15 +59,18 @@ def save_profile(self, userdata, data): if "password" in userdata: user = self.user_manager.auth_user(self.user_manager.session_username(), data["oldpasswd"], False) - if user is None: - error = True - msg = _("Incorrect old password.") - return result, msg, error - else: - passwd_hash = UserManager.hash_password(data["passwd"]) - result = self.database.users.find_one_and_update({"username": self.user_manager.session_username()}, - {"$set": {"password": passwd_hash}}, - return_document=ReturnDocument.AFTER) + else: + user = self.database.users.find_one({"username": userdata["username"]}) + + if user is None: + error = True + msg = _("Incorrect old password.") + return result, msg, error + else: + passwd_hash = UserManager.hash_password(data["passwd"]) + result = self.database.users.find_one_and_update({"username": self.user_manager.session_username()}, + {"$set": {"password": passwd_hash}}, + return_document=ReturnDocument.AFTER) # Check if updating language if data["language"] != userdata["language"]: