Skip to content

Commit f178694

Browse files
committed
[IMP] password_security: Set password update date for already existing users that don't have it. This fixes the password expiration date and other validations that require an existing value for password update date.
[IMP] password_security: Simplify validation on password reset.
1 parent 99d7b5c commit f178694

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

password_security/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
33

44
from . import controllers, models
5+
from .hooks import post_init_hook

password_security/__manifest__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"name": "Password Security",
77
"summary": "Allow admin to set password security requirements.",
8-
"version": "16.0.1.0.1",
8+
"version": "16.0.1.0.2",
99
"author": "LasLabs, "
1010
"Onestein, "
1111
"Kaushal Prajapati, "
@@ -29,4 +29,5 @@
2929
"demo/res_users.xml",
3030
],
3131
"installable": True,
32+
"post_init_hook": "post_init_hook",
3233
}

password_security/hooks.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2024 Vauxoo
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
5+
def post_init_hook(cr, registry):
6+
# Set password date for already existing users
7+
cr.execute(
8+
"""
9+
UPDATE
10+
res_users
11+
SET
12+
password_write_date = NOW() at time zone 'UTC'
13+
WHERE
14+
password_write_date IS NULL;
15+
"""
16+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def migrate(cr, version):
2+
# Set password date for already existing users
3+
cr.execute(
4+
"""
5+
UPDATE
6+
res_users
7+
SET
8+
password_write_date = NOW() at time zone 'UTC'
9+
WHERE
10+
password_write_date IS NULL;
11+
"""
12+
)

password_security/models/res_users.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,7 @@ def _validate_pass_reset(self):
144144
if pass_min <= 0:
145145
continue
146146
write_date = user.password_write_date
147-
if not write_date:
148-
continue
149-
delta = timedelta(hours=pass_min)
150-
if write_date + delta > datetime.now():
147+
if write_date and write_date + timedelta(hours=pass_min) > datetime.now():
151148
raise UserError(
152149
_(
153150
"Passwords can only be reset every %d hour(s). "

0 commit comments

Comments
 (0)