From b354c556d4349171bcc31051c45c92433c92221d Mon Sep 17 00:00:00 2001 From: miloshIra Date: Mon, 21 Aug 2023 15:57:58 +0200 Subject: [PATCH] dynamic message and readme fix --- README.md | 6 ++++-- ckanext/password_policy/plugin.py | 6 ++++-- ckanext/password_policy/views.py | 4 +++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e495fe6..d161127 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,14 @@ To install ckanext-password-policy: 2. Clone the source and install it on the virtualenv + ``` git clone https://github.com/Keitaro/ckanext-password-policy.git cd ckanext-password-policy pip install -e . - pip install -r requirements.txt + pip install -r requirements.txt + ``` -3. Add `password-policy` to the `ckan.plugins` setting in your CKAN +3. Add `password_policy` to the `ckan.plugins` setting in your CKAN config file (by default the config file is located at `/etc/ckan/default/ckan.ini`). diff --git a/ckanext/password_policy/plugin.py b/ckanext/password_policy/plugin.py index acc5808..5a4c6ab 100644 --- a/ckanext/password_policy/plugin.py +++ b/ckanext/password_policy/plugin.py @@ -4,12 +4,14 @@ import ckan.lib.navl.dictization_functions as df import ckanext.password_policy.helpers as h from six import string_types -from ckan.common import _ +from ckan.common import _, config Missing = df.Missing missing = df.missing +password_length = int(config.get('ckan.password_policy.password_length')) + def user_custom_password_validator(key, data, errors, context): value = data[key] @@ -22,7 +24,7 @@ def user_custom_password_validator(key, data, errors, context): elif value == '': pass elif not valid_pass['password_ok']: - errors[('password',)].append(_('Your password must be 12 characters or ' + errors[('password',)].append(_(f'Your password must be {password_length} characters or ' 'longer and contain uppercase, lowercase, ' 'digit and special character')) diff --git a/ckanext/password_policy/views.py b/ckanext/password_policy/views.py index e0822aa..7dec44a 100644 --- a/ckanext/password_policy/views.py +++ b/ckanext/password_policy/views.py @@ -101,11 +101,13 @@ class PerformResetView_(PerformResetView): def _get_form_password(self): password1 = request.form.get(u'password1') password2 = request.form.get(u'password2') + + password_length = int(config.get('ckan.password_policy.password_length')) valid_pass = helper.custom_password_check(password1) if valid_pass['password_ok']==False: raise ValueError( - _(u'Your password must be 12 characters or ' + _(f"u'Your password must be {password_length} characters or '" u'longer and contain uppercase, lowercase, ' u'digit and special character')) elif password1 != password2: