You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2018/10/22 16:30:56 UTC
[3/5] allura git commit: [#7459] Added JS password validation
[#7459] Added JS password validation
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/37f38258
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/37f38258
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/37f38258
Branch: refs/heads/master
Commit: 37f38258ee38979080a3a7b788a8802f914aea3a
Parents: 45d1007
Author: Shalitha Suranga <sh...@gmail.com>
Authored: Fri Oct 19 11:43:22 2018 +0530
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Mon Oct 22 16:24:44 2018 +0000
----------------------------------------------------------------------
Allura/allura/lib/widgets/forms.py | 7 +++
.../widgets/resources/js/password-validator.js | 49 ++++++++++++++++++++
2 files changed, 56 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/37f38258/Allura/allura/lib/widgets/forms.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index d436fff..71d3fca 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -170,6 +170,7 @@ class PasswordChangeForm(PasswordChangeBase):
ew.PasswordField(
name='pw',
label='New Password',
+ attrs=dict(minlength=6, maxlength=30),
validator=fev.UnicodeString(
not_empty=True,
min=asint(tg.config.get('auth.min_password_len', 6)),
@@ -190,6 +191,8 @@ class PasswordChangeForm(PasswordChangeBase):
value, state)
return d
+ def resources(self):
+ yield ew.JSLink('js/password-validator.js')
class PersonalDataForm(ForgeForm):
_fields = None
@@ -771,6 +774,7 @@ class RegistrationForm(ForgeForm):
ew.PasswordField(
name='pw',
label='New Password',
+ attrs=dict(minlength=6, maxlength=30),
validator=fev.UnicodeString(
not_empty=True,
min=asint(tg.config.get('auth.min_password_len', 6)),
@@ -794,6 +798,9 @@ class RegistrationForm(ForgeForm):
raise formencode.Invalid('Passwords must match', value, state)
return d
+ def resources(self):
+ yield ew.JSLink('js/password-validator.js')
+
class AdminForm(ForgeForm):
template = 'jinja:allura:templates/widgets/admin_form.html'
http://git-wip-us.apache.org/repos/asf/allura/blob/37f38258/Allura/allura/lib/widgets/resources/js/password-validator.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/password-validator.js b/Allura/allura/lib/widgets/resources/js/password-validator.js
new file mode 100644
index 0000000..951337a
--- /dev/null
+++ b/Allura/allura/lib/widgets/resources/js/password-validator.js
@@ -0,0 +1,49 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+$(document).ready(function () {
+ $("input[name=pw], input[name=pw2]").tooltipster({
+ animation: 'fade',
+ delay: 200,
+ theme: 'tooltipster-light',
+ trigger: 'custom',
+ position: 'right',
+ iconCloning: false,
+ maxWidth: 400
+ });
+
+ $('input[name=pw]').tooltipster('content', 'Password must be at having charactors between ' + $("input[name=pw]").attr('minlength') + ' and ' + $("input[name=pw]").attr('maxlength'));
+ $('input[name=pw2]').tooltipster('content', 'Passwords don\'t match');
+
+ $("input[name=pw]").keyup(function() {
+ checkPassword($(this));
+ });
+
+ $("input[name=pw2]").keyup(function() {
+ checkPasswordConfirm($(this), $('input[name=pw]'));
+ });
+
+ function checkPassword(elm) {
+ elm.tooltipster(!elm[0].checkValidity() ? 'show' : 'hide');
+ }
+
+ function checkPasswordConfirm(elm, pelm) {
+ elm.tooltipster(elm.val() != pelm.val() ? 'show' : 'hide');
+ }
+ });
\ No newline at end of file