Skip to content

Commit

Permalink
[FIX] password_security: fix Policy applied to reset password dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-wtioit committed May 8, 2024
1 parent 884f003 commit da4bc91
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 30 deletions.
3 changes: 3 additions & 0 deletions password_security/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ Contributors
* `Onestein <https://www.onestein.nl>`_:
* Andrea Stirpe <[email protected]>

* `WT-IO-IT GmbH <https://www.wt-io-it.at>`_:
* Andreas Perhab <[email protected]>

Maintainers
~~~~~~~~~~~

Expand Down
4 changes: 4 additions & 0 deletions password_security/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand All @@ -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/**/*",
],
Expand Down
13 changes: 13 additions & 0 deletions password_security/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions password_security/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

* `Onestein <https://www.onestein.nl>`_:
* Andrea Stirpe <[email protected]>

* `WT-IO-IT GmbH <https://www.wt-io-it.at>`_:
* Andreas Perhab <[email protected]>
9 changes: 8 additions & 1 deletion password_security/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -516,6 +515,14 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt><a class="reference external" href="https://www.wt-io-it.at">WT-IO-IT GmbH</a>:</dt>
<dd><ul class="first last simple">
<li>Andreas Perhab &lt;<a class="reference external" href="mailto:andreas.perhab&#64;wt-io-it.at">andreas.perhab&#64;wt-io-it.at</a>&gt;</li>
</ul>
</dd>
</dl>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
59 changes: 30 additions & 29 deletions password_security/static/src/js/signup_policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
});
16 changes: 16 additions & 0 deletions password_security/views/signup_templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<odoo>
<template
id="fields"
inherit_id="auth_signup.fields"
name="Password Security data for auth_signup"
>
<xpath expr="//input[@name='password']" position="attributes">
<attribute name="t-att-passwordlength">password_length</attribute>
<attribute name="t-att-passwordlower">password_lower</attribute>
<attribute name="t-att-passwordupper">password_upper</attribute>
<attribute name="t-att-passwordnumeric">password_numeric</attribute>
<attribute name="t-att-passwordspecial">password_special</attribute>
<attribute name="t-att-passwordestimate">password_estimate</attribute>
</xpath>
</template>
</odoo>

0 comments on commit da4bc91

Please sign in to comment.