(function () { "use strict"; var UpdatePassword = function ($scope, userService) { $scope.model = { password: '', confirmPassword: '', submitted: false }; $scope.update = function () { const error = "A password must be at least 6 characters, an upper case, a lower case, a numeric digit, and a special character."; const errorOld = "Old password is required."; const notMatching = "Passwords do not match."; $scope.model.submitted = true; $scope.errorMessage = null; if (!testPassword($scope.model.password)) { $scope.errorMessage = error; } else if (!$scope.model.oldPassword || !$scope.model.oldPassword.length){ $scope.errorMessage = errorOld; } else if ($scope.model.password !== $scope.model.confirmPassword) { $scope.errorMessage = null; } else { $('.upload').show(); userService.updatePassword($scope.model.oldPassword, $scope.model.password, $scope.model.confirmPassword).then(function (message) { $('.upload').hide(); $scope.message = message; $scope.success = true; }).catch(response => { $scope.errorMessage = response.data.message; $('.upload').hide(); }); } }; function testPassword(password) { if (!password || password.length < 6) return false; var regex = RegExp('(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\\W)'); return regex.test(password); } }; UpdatePassword.$inject = ['$scope', 'userService']; angular.module('streamApp').controller('updatePasswordController', UpdatePassword); })();