Merge branch 'passwordStrength'

This commit is contained in:
Henry Oswald 2015-04-28 17:39:46 +01:00
commit a1e24eb064
4 changed files with 66 additions and 0 deletions

View file

@ -165,6 +165,17 @@ module.exports =
{name: "French", code: "fr"}
]
# Password Settings
# -----------
# These restrict the passwords users can use when registering
# opts are from http://antelle.github.io/passfield
passwordStrengthOptions:
pattern: "aA$3"
length:
min: 8
max: 50
# Email support
# -------------
#

View file

@ -1,8 +1,14 @@
define [
"base"
"libs/passfield"
], (App) ->
App.directive "asyncForm", ($http) ->
return {
controller: ['$scope', ($scope) ->
@getEmail = () ->
return $scope.email
return this
]
link: (scope, element, attrs) ->
formName = attrs.asyncForm
@ -71,3 +77,49 @@ define [
}
}
App.directive 'complexPassword', ->
require: ['^asyncForm', 'ngModel']
link: (scope, element, attrs, ctrl) ->
PassField.Config.blackList = []
defaultPasswordOpts =
pattern: ""
length:
min: 1
max: 50
allowEmpty: false
allowAnyChars: false
isMasked: true
showToggle: false
showGenerate: false
showTip:false
showWarn:false
checkMode : PassField.CheckModes.STRICT
chars:
digits: "1234567890"
letters: "abcdefghijklmnopqrstuvwxyz"
letters_up: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
symbols: "@#$%^&*()-_=+[]{};:<>/?!£€.,"
opts = _.defaults(window.passwordStrengthOptions || {}, defaultPasswordOpts)
if opts.length.min == 1
opts.acceptRate = 0 #this allows basically anything to be a valid password
passField = new PassField.Field("passwordFeild", opts);
[asyncFormCtrl, ngModelCtrl] = ctrl
ngModelCtrl.$parsers.unshift (modelValue) ->
isValid = passField.validatePass()
if !isValid
scope.complexPasswordErrorMessage = passField.getPassValidationMessage()
else
email = asyncFormCtrl.getEmail()
startOfEmail = email?.split("@")?[0]
if modelValue.indexOf(email) != -1 or modelValue.indexOf(startOfEmail) != -1
isValid = false
scope.complexPasswordErrorMessage = "Password can not contain email address"
ngModelCtrl.$setValidity('complexPassword', isValid)
return modelValue

View file

@ -9,4 +9,5 @@ define [
"libs/fineuploader"
"libs/angular-sanitize-1.2.17"
"libs/angular-cookie"
"libs/passfield"
], () ->

File diff suppressed because one or more lines are too long