From da4bc917fa63e1712e8beb16af79f14bf3b693ab Mon Sep 17 00:00:00 2001 From: Andreas Perhab Date: Mon, 6 May 2024 15:47:13 +0200 Subject: [PATCH] [FIX] password_security: fix Policy applied to reset password dialog --- password_security/README.rst | 3 + password_security/__manifest__.py | 4 ++ password_security/controllers/main.py | 13 ++++ password_security/readme/CONTRIBUTORS.rst | 3 + .../static/description/index.html | 9 ++- .../static/src/js/signup_policy.js | 59 ++++++++++--------- password_security/views/signup_templates.xml | 16 +++++ 7 files changed, 77 insertions(+), 30 deletions(-) create mode 100644 password_security/views/signup_templates.xml diff --git a/password_security/README.rst b/password_security/README.rst index e292f74818..9201210143 100644 --- a/password_security/README.rst +++ b/password_security/README.rst @@ -122,6 +122,9 @@ Contributors * `Onestein `_: * Andrea Stirpe +* `WT-IO-IT GmbH `_: + * Andreas Perhab + Maintainers ~~~~~~~~~~~ diff --git a/password_security/__manifest__.py b/password_security/__manifest__.py index deafe20132..e34a22011a 100644 --- a/password_security/__manifest__.py +++ b/password_security/__manifest__.py @@ -25,6 +25,7 @@ "license": "LGPL-3", "data": [ "views/res_config_settings_views.xml", + "views/signup_templates.xml", "security/ir.model.access.csv", "security/res_users_pass_history.xml", ], @@ -33,6 +34,9 @@ "/password_security/static/src/js/password_gauge.js", "/password_security/static/lib/zxcvbn/zxcvbn.min.js", ], + "web.assets_frontend": [ + "/password_security/static/src/js/signup_policy.js", + ], "web.qunit_suite_tests": [ "password_security/static/tests/**/*", ], diff --git a/password_security/controllers/main.py b/password_security/controllers/main.py index 1f7f7916d6..f50bb0bd55 100644 --- a/password_security/controllers/main.py +++ b/password_security/controllers/main.py @@ -50,6 +50,19 @@ def web_login(self, *args, **kw): redirect = request.env.user.partner_id.signup_url return request.redirect(redirect) + def get_auth_signup_config(self): + signup_config = super().get_auth_signup_config() + for property_name in ( + "password_length", + "password_lower", + "password_upper", + "password_numeric", + "password_special", + "password_estimate", + ): + signup_config[property_name] = request.env.company[property_name] + return signup_config + @http.route() def web_auth_signup(self, *args, **kw): try: diff --git a/password_security/readme/CONTRIBUTORS.rst b/password_security/readme/CONTRIBUTORS.rst index 76ad7c31e1..ca39341a94 100644 --- a/password_security/readme/CONTRIBUTORS.rst +++ b/password_security/readme/CONTRIBUTORS.rst @@ -13,3 +13,6 @@ * `Onestein `_: * Andrea Stirpe + +* `WT-IO-IT GmbH `_: + * Andreas Perhab diff --git a/password_security/static/description/index.html b/password_security/static/description/index.html index 0edc49c95c..43653d5fcb 100644 --- a/password_security/static/description/index.html +++ b/password_security/static/description/index.html @@ -1,4 +1,3 @@ - @@ -516,6 +515,14 @@

Contributors

+
  • +
    WT-IO-IT GmbH:
    +
    +
    +
    +
  • diff --git a/password_security/static/src/js/signup_policy.js b/password_security/static/src/js/signup_policy.js index b5c6372ae2..80f6502eda 100644 --- a/password_security/static/src/js/signup_policy.js +++ b/password_security/static/src/js/signup_policy.js @@ -3,39 +3,40 @@ odoo.define("password_security.signup.policy", function (require) { "use strict"; - var base = require("web_editor.base"); var policy = require("auth_password_policy"); var PasswordMeter = require("auth_password_policy.Meter"); + // Wait until auth_password_policy_signup.policy is done + require("auth_password_policy_signup.policy"); - base.ready().then(function () { - var $signupForm = $(".oe_signup_form, .oe_reset_password_form"); - if (!$signupForm.length) { - return; - } + var $signupForm = $(".oe_signup_form, .oe_reset_password_form"); + if (!$signupForm.length) { + return; + } - var $password = $signupForm.find("#password"); - var password_length = Number($password.attr("password_length")); - var password_lower = Number($password.attr("password_lower")); - var password_upper = Number($password.attr("password_upper")); - var password_numeric = Number($password.attr("password_numeric")); - var password_special = Number($password.attr("password_special")); - var password_estimate = Number($password.attr("password_estimate")); + var $password = $signupForm.find("#password"); + var password_length = Number($password.attr("passwordlength")); + var password_lower = Number($password.attr("passwordlower")); + var password_upper = Number($password.attr("passwordupper")); + var password_numeric = Number($password.attr("passwordnumeric")); + var password_special = Number($password.attr("passwordspecial")); + var password_estimate = Number($password.attr("passwordestimate")); - var meter = new PasswordMeter( - null, - new policy.Policy({ - password_length: password_length, - password_lower: password_lower, - password_upper: password_upper, - password_numeric: password_numeric, - password_special: password_special, - password_estimate: password_estimate, - }), - policy.recommendations - ); - meter.insertAfter($password); - $password.on("input", function () { - meter.update($password.val()); - }); + var meter = new PasswordMeter( + null, + new policy.Policy({ + password_length: password_length, + password_lower: password_lower, + password_upper: password_upper, + password_numeric: password_numeric, + password_special: password_special, + password_estimate: password_estimate, + }), + policy.recommendations + ); + // Remove the old meter + $password.parent().find("meter").remove(); + meter.insertAfter($password); + $password.on("input", function () { + meter.update($password.val()); }); }); diff --git a/password_security/views/signup_templates.xml b/password_security/views/signup_templates.xml new file mode 100644 index 0000000000..22255080d3 --- /dev/null +++ b/password_security/views/signup_templates.xml @@ -0,0 +1,16 @@ + + +