Skip to content

Commit

Permalink
[IMP] password_security: Set password update date for already existin…
Browse files Browse the repository at this point in the history
…g 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.
  • Loading branch information
keylor2906 authored and moylop260 committed Sep 20, 2024
1 parent 99d7b5c commit dfeb26a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions password_security/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from . import controllers, models
from .hooks import post_init_hook
3 changes: 2 additions & 1 deletion password_security/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Password Security",
"summary": "Allow admin to set password security requirements.",
"version": "16.0.1.0.1",
"version": "16.0.1.0.2",
"author": "LasLabs, "
"Onestein, "
"Kaushal Prajapati, "
Expand All @@ -29,4 +29,5 @@
"demo/res_users.xml",
],
"installable": True,
"post_init_hook": "post_init_hook",
}
16 changes: 16 additions & 0 deletions password_security/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Vauxoo
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


def post_init_hook(cr, registry):
# Set password date for already existing users
cr.execute(
"""
UPDATE
res_users
SET
password_write_date = NOW() at time zone 'UTC'
WHERE
password_write_date IS NULL;
"""
)
12 changes: 12 additions & 0 deletions password_security/migrations/16.0.1.0.2/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def migrate(cr, version):
# Set password date for already existing users
cr.execute(
"""
UPDATE
res_users
SET
password_write_date = NOW() at time zone 'UTC'
WHERE
password_write_date IS NULL;
"""
)
5 changes: 1 addition & 4 deletions password_security/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ def _validate_pass_reset(self):
if pass_min <= 0:
continue
write_date = user.password_write_date
if not write_date:
continue
delta = timedelta(hours=pass_min)
if write_date + delta > datetime.now():
if write_date and write_date + timedelta(hours=pass_min) > datetime.now():
raise UserError(
_(
"Passwords can only be reset every %d hour(s). "
Expand Down

0 comments on commit dfeb26a

Please sign in to comment.