|
|
@@ -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
|