Browse Source

Nov 06: [FIX] Bug Fixed 'user_password_strength'

pull/345/merge
Cybrosys Technologies 6 months ago
parent
commit
3b5350e7a5
  1. 2
      user_password_strength/README.rst
  2. 4
      user_password_strength/__manifest__.py
  3. 2
      user_password_strength/models/restrict_password.py
  4. BIN
      user_password_strength/static/description/assets/screenshots/PSCO5.png
  5. BIN
      user_password_strength/static/description/assets/screenshots/hero.gif
  6. BIN
      user_password_strength/static/description/assets/screenshots/hero.png
  7. 19
      user_password_strength/static/description/index.html
  8. 196
      user_password_strength/static/src/js/signup_user.js
  9. 2
      user_password_strength/views/restrict_password.xml
  10. 8
      user_password_strength/views/signup_page_view.xml

2
user_password_strength/README.rst

@ -1,4 +1,4 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

4
user_password_strength/__manifest__.py

@ -39,7 +39,9 @@
],
'images': ['static/description/banner.png'],
'assets': {
'web.assets_frontend': ['user_password_strength/static/src/js/signup_user.js', ],
'web.assets_frontend': [
'user_password_strength/static/src/js/signup_user.js',
],
},
'license': "AGPL-3",
'installable': True,

2
user_password_strength/models/restrict_password.py

@ -40,7 +40,7 @@ class ConfSettings(models.TransientModel):
'is_upper')
is_lower = fields.Boolean(string="Should have at least one "
"lowercase character",
config_parameter='user_password_strength.'
config_parameter='user_password_strength.'
'is_lower')
is_special_symbol = fields.Boolean(string="Should have at least one "
"special symbol",

BIN
user_password_strength/static/description/assets/screenshots/PSCO5.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
user_password_strength/static/description/assets/screenshots/hero.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

BIN
user_password_strength/static/description/assets/screenshots/hero.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

19
user_password_strength/static/description/index.html

@ -38,7 +38,7 @@
</p>
<!-- END OF APP HERO -->
<img src="./assets/screenshots/hero.png" class="img-responsive" width="100%" height="auto" />
<img src="./assets/screenshots/hero.gif" class="img-responsive" width="100%" height="auto" />
</div>
</div>
<!-- NAVIGATION SECTION -->
@ -290,6 +290,19 @@
<img src="assets/screenshots/PSC03.png" class="img-responsive img-thumbnail border" width="100%"
height="auto" />
</div>
<div class="col-lg-12 my-2">
<h4 class="my-2"
style="font-family: 'Roboto', sans-serif !important; font-weight: 600 !important; color: #282F33 !important; font-size: 1.3rem !important;">
Create a New Password</h4>
<p
style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;">
Users can create a new password by ensuring it is strong, using a mix of uppercase
and lowercase letters, numbers, and special characters.
</p>
<img src="assets/screenshots/PSCO5.png"
class="img-responsive img-thumbnail border" width="100%"
height="auto" />
</div>
<div class="col-lg-12 my-3">
@ -489,7 +502,7 @@
</div>
</div>
</section>
<!-- END OF END OF OUR SERVICES -->
<!-- END OF OUR SERVICES -->
<!-- OUR INDUSTRIES -->
<section class="container" style="margin-top: 6rem !important;">
@ -622,7 +635,7 @@
</div>
</section>
<!-- END OF END OF OUR INDUSTRIES -->
<!-- END OF OUR INDUSTRIES -->
<!-- FOOTER -->
<!-- Footer Section -->

196
user_password_strength/static/src/js/signup_user.js

@ -1,140 +1,150 @@
odoo.define('user_password_strength.signup_user', function (require) {
"use strict";
// Extending the public widget of the signup form for checking the user
// password strength conditions on key up function of the password field in
// the sign up form,Based on the conditions from configuration settings.
odoo.define('user_password_strength.reset_user', function (require) {
"use strict";
var PublicWidget = require('web.public.widget');
var ajax = require("web.ajax");
var password = document.getElementById("password");
var MySignUpForm = PublicWidget.registry.SignUpForm.extend({
selector: '.oe_signup_form',
var ResetForm = PublicWidget.Widget.extend({
selector: '.oe_website_login_container',
events: {
'keyup': '_onKeyup',
'input input[type="password"]': '_onPasswordInput',
},
_onPasswordInput: function () {
var passwordField = document.getElementById("password");
var confirmPasswordField = document.getElementById("confirm_password");
// Call function to update password strength progress for both password and confirm password fields
this._updateProgress(passwordField);
this._updateProgress(confirmPasswordField);
},
_onKeyup: function () {
// Rendering ajax Rpc call from controller through route
ajax.jsonRpc('/web/config_params', 'call', {
}).then(function (data) {
var list=[]
_updateProgress: function (passwordField) {
var current_pwd = passwordField ? passwordField.value : "";
// Reset if password length is zero
if (current_pwd.length === 0) {
var progressBar = document.getElementById("progress");
if (progressBar) {
progressBar.value = "0";
progressBar.style.backgroundColor = "#FF0000"; // Red for no input
}
return;
}
// AJAX call to get configuration settings
ajax.jsonRpc('/web/config_params', 'call', {}).then(function (data) {
var list = [];
for (let x in data) {
list.push(data[x]);
list.push(data[x]);
}
var flag = 0
for(var i=0;i<=list.length;i++){
if(list[i] == 'True'){
flag +=1
// Count the number of enabled password conditions
var flag = 0;
for (var i = 0; i < list.length; i++) {
if (list[i] === 'True') {
flag++;
}
}
// Check how many conditions the current password satisfies
var prog = [/[$@$!%*#?&]/, /[A-Z]/, /[0-9]/, /[a-z]/]
.reduce((memo, test) => memo + test.test(current_pwd),
0);
if(prog > 2 && current_pwd.length > 7){
.reduce((memo, test) => memo + test.test(current_pwd), 0);
// Increase progress if password length is greater than 7 characters
if (prog > 2 && current_pwd.length > 7) {
prog++;
}
var progress = "";
var colors = ['#FF0000', '#00FF00','#0000FF'];
var currentColor = 0;
//When 5 conditions are enabled in config settings
if (flag == 5){
var colors = ['#FF0000', '#00FF00', '#0000FF'];
var currentColor = colors[0]; // Default to red
// Update progress and color based on the number of conditions (flag)
if (flag === 5) {
switch (prog) {
case 0:
case 1:
progress = "20";
currentColor = colors[0];
break;
progress = "20";
currentColor = colors[0];
break;
case 2:
progress = "25";
currentColor = colors[0];
break;
progress = "25";
currentColor = colors[0];
break;
case 3:
progress = "50";
currentColor = colors[1];
break;
progress = "50";
currentColor = colors[1]; // Green
break;
case 4:
progress = "75";
currentColor = colors[1];
break;
progress = "75";
currentColor = colors[1];
break;
case 5:
progress = "100";
currentColor = colors[1];
break;
progress = "100";
currentColor = colors[1];
break;
}
}
//When 4 conditions are enabled in config settings
if (flag == 4){
} else if (flag === 4) {
switch (prog) {
case 0:
case 1:
case 2:
progress = "25";
currentColor = colors[0];
break;
progress = "25";
currentColor = colors[0];
break;
case 3:
progress = "50";
currentColor = colors[0];
break;
progress = "50";
currentColor = colors[0];
break;
case 4:
progress = "75";
currentColor = colors[1];
break;
progress = "75";
currentColor = colors[1];
break;
case 5:
progress = "100";
currentColor = colors[1];
break;
progress = "100";
currentColor = colors[1];
break;
}
}
//When 3 conditions are enabled in config settings
if (flag == 3){
} else if (flag === 3) {
switch (prog) {
case 0:
case 1:
case 2:
case 3:
progress = "33.33";
currentColor = colors[0];
break;
progress = "33.33";
currentColor = colors[0];
break;
case 4:
progress = "66.66";
currentColor = colors[1];
break;
progress = "66.66";
currentColor = colors[1];
break;
case 5:
progress = "100";
currentColor = colors[1];
break;
progress = "100";
currentColor = colors[1];
break;
}
}
//When 2 conditions are enabled in config settings
if (flag == 2) {
if (prog != 5) {
} else if (flag === 2) {
if (prog !== 5) {
progress = "50";
currentColor = colors[0];
} else{
} else {
progress = "100";
currentColor = colors[1];
currentColor = colors[1];
}
}
//When only 1 condition is enabled in config settings
if (flag == 1){
} else if (flag === 1) {
progress = "100";
currentColor = colors[1];
currentColor = colors[1]; // Green for fully satisfied
}
var val = document.getElementById("progress")
if(val!== null){
document.getElementById("progress").value = progress;
document.getElementById("progress").style
.backgroundColor = currentColor;
}
});
// Reset if password length is zero
var current_pwd = password.value
if (current_pwd.length === 0) {
document.getElementById("progress").value = "0";
return;
// Update the progress bar
var progressBar = document.getElementById("progress");
if (progressBar) {
progressBar.value = progress;
progressBar.style.backgroundColor = currentColor;
}
},
});
},
});
PublicWidget.registry.MySignUpForm = MySignUpForm;
return MySignUpForm;
PublicWidget.registry.ResetForm = ResetForm;
return ResetForm;
});

2
user_password_strength/views/restrict_password.xml

@ -1,10 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!-- Inherit and Extend Base Settings Form View -->
<record id="res_config_settings_inherit_view_form" model="ir.ui.view">
<field name="name">res.config.settings.inherit.view</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base.res_config_settings_view_form"/>
<field name="arch" type="xml">
<!-- Insert our new settings after the existing password reset section -->
<xpath expr="//div[@id='enable_password_reset']" position="after">
<div class="col-12 col-lg-6 o_setting_box"
id="enable_password_restrict">

8
user_password_strength/views/signup_page_view.xml

@ -1,11 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="document_fields" inherit_id="auth_signup.fields">
<!-- Inherit and Extend the Standard Auth Signup Fields Template -->
<xpath expr="//input[@name='password']" position="after">
<br>
</br>
<div>
<progress id="progress" value="0" max="100"
style="color: red;">70</progress>
<progress id="progress" value="0" max="100" style="color: red;">70</progress>
</div>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save