diff --git a/password_security/controllers/main.py b/password_security/controllers/main.py index 1736ca354e..58c9a7b450 100644 --- a/password_security/controllers/main.py +++ b/password_security/controllers/main.py @@ -17,7 +17,10 @@ class PasswordSecurityHome(AuthSignupHome): def do_signup(self, qcontext): password = qcontext.get("password") - user = request.env.user + user = ( + request.env.user.search([("login", "=", qcontext.get("login"))]) + or request.env.user + ) user._check_password(password) return super(PasswordSecurityHome, self).do_signup(qcontext) diff --git a/password_security/models/res_users.py b/password_security/models/res_users.py index 79c74418f2..7424520585 100644 --- a/password_security/models/res_users.py +++ b/password_security/models/res_users.py @@ -32,6 +32,11 @@ def write(self, vals): vals["password_write_date"] = fields.Datetime.now() return super(ResUsers, self).write(vals) + def copy(self, vals): + if vals.get("password"): + vals["password_write_date"] = fields.Datetime.now() + return super(ResUsers, self).copy(vals) + @api.model def get_password_policy(self): data = super(ResUsers, self).get_password_policy() diff --git a/password_security/tests/test_signup.py b/password_security/tests/test_signup.py index b600f4cd12..9d6467c89a 100644 --- a/password_security/tests/test_signup.py +++ b/password_security/tests/test_signup.py @@ -4,6 +4,7 @@ from unittest import mock +from freezegun import freeze_time from requests.exceptions import HTTPError from odoo import http @@ -82,7 +83,8 @@ def test_03_create_user_signup(self): # Stronger password: no error raised vals["password"] = "asdQWE12345_3" - login, pwd = self.env["res.users"].signup(vals) + with freeze_time("2020-01-01"): + login, pwd = self.env["res.users"].signup(vals) # check created user created_user = self.env["res.users"].search([("login", "=", "test_user")])