<commit_before>module.directive('userPasswordForm', [
	'authService', 'pageService', '$http', '$window', function (auth, page, $http, $window) {
		var link = function ($scope) {
			var form = $scope.userPasswordForm;
			var token;

			form.data = {
				token: undefined,
				auth: undefined,
				email: undefined,
				password: {
					once: undefined,
					again: undefined
				}
			};

			if (auth.hasToken()) {
				token = auth.getToken();
				form.data.token = token.id;
				form.data.auth = token.auth;
			}

			//

			form.resetFn = undefined;
			form.resetSuccessFn = undefined;
			form.resetErrorFn = undefined;

			form.reset = function () {
				if (angular.isFunction(form.resetFn))
					form.resetFn(form);

				$http
					.post('/password', $scope.userPasswordForm.data)
					.success(function (data) {
						page.messages.add({
							type: 'green',
							countdown: 3000,
							body: page.constants.message('reset.request.success', form.data.email)
						});

						if (angular.isFunction(form.resetSuccessFn))
							form.resetSuccessFn(form, arguments);
					})
					.error(function (errors, status) {
						page.messages.addError({
							closeable: true,
							body: page.constants.message('reset.request.error'),
							errors: errors,
							status: status
						});

						if (angular.isFunction(form.resetErrorFn))
							form.resetErrorFn(form, arguments);
					});
			};

			//

			form.saveFn = undefined;
			form.saveSuccessFn = undefined;
			form.saveErrorFn = undefined;

			form.save = function () {
				if (angular.isFunction(form.saveFn))
					form.saveFn(form);

				$http
					.post('/api/party/' + token.party + '/password', $scope.userPasswordForm.data)
					.success(function (data) {
						page.messages.add({
							type: 'green',
							countdown: 3000,
							body: page.constants.message('reset.save.success', form.data.email)
						});

						if (angular.isFunction(form.saveSuccessFn))
							form.saveSuccessFn(form, arguments);

						$window.$play.object = null;
						auth.updateUser(data);
					})
					.error(function (errors, status) {
						page.messages.add({
							countdown: 3000,
							type: 'red',
							body: angular.isArray(errors) ? (errors['password.once'] || errors['password']).join('. ') + '.' : page.constants.message('error.generic')
						});

						if (angular.isFunction(form.saveErrorFn))
							form.saveErrorFn(form, arguments);

						$window.$play.object = null;
					});
			};

			//

			form.ready = function () {
				if (form.data.token)
					return form.$dirty && form.$valid && form.data.password.once &&
						form.data.password.once == form.data.password.again;
				else
					return form.$dirty && form.$valid && form.data.email;
			};

			//

			page.events.talk('userPasswordForm-init', form, $scope);
		};

		//

		return {
			restrict: 'E',
			templateUrl: 'userPasswordForm.html',
			scope: false,
			replace: true,
			link: link
		};
	}
]);
<commit_msg>Fix error reporting on passwords<commit_after>module.directive('userPasswordForm', [
	'authService', 'pageService', '$http', '$window', function (auth, page, $http, $window) {
		var link = function ($scope) {
			var form = $scope.userPasswordForm;
			var token;

			form.data = {
				token: undefined,
				auth: undefined,
				email: undefined,
				password: {
					once: undefined,
					again: undefined
				}
			};

			if (auth.hasToken()) {
				token = auth.getToken();
				form.data.token = token.id;
				form.data.auth = token.auth;
			}

			//

			form.resetFn = undefined;
			form.resetSuccessFn = undefined;
			form.resetErrorFn = undefined;

			form.reset = function () {
				if (angular.isFunction(form.resetFn))
					form.resetFn(form);

				$http
					.post('/password', $scope.userPasswordForm.data)
					.success(function (data) {
						page.messages.add({
							type: 'green',
							countdown: 3000,
							body: page.constants.message('reset.request.success', form.data.email)
						});

						if (angular.isFunction(form.resetSuccessFn))
							form.resetSuccessFn(form, arguments);
					})
					.error(function (errors, status) {
						page.messages.addError({
							closeable: true,
							body: page.constants.message('reset.request.error'),
							errors: errors,
							status: status
						});

						if (angular.isFunction(form.resetErrorFn))
							form.resetErrorFn(form, arguments);
					});
			};

			//

			form.saveFn = undefined;
			form.saveSuccessFn = undefined;
			form.saveErrorFn = undefined;

			form.save = function () {
				if (angular.isFunction(form.saveFn))
					form.saveFn(form);

				$http
					.post('/api/party/' + token.party + '/password', $scope.userPasswordForm.data)
					.success(function (data) {
						page.messages.add({
							type: 'green',
							countdown: 3000,
							body: page.constants.message('reset.save.success', form.data.email)
						});

						if (angular.isFunction(form.saveSuccessFn))
							form.saveSuccessFn(form, arguments);

						$window.$play.object = null;
						auth.updateUser(data);
					})
					.error(function (errors, status) {
						page.messages.add({
							countdown: 3000,
							type: 'red',
							body: angular.isObject(errors) ? (errors['password.once'] || errors['password']).join('. ') + '.' : page.constants.message('error.generic')
						});

						if (angular.isFunction(form.saveErrorFn))
							form.saveErrorFn(form, arguments);

						$window.$play.object = null;
					});
			};

			//

			form.ready = function () {
				if (form.data.token)
					return form.$dirty && form.$valid && form.data.password.once &&
						form.data.password.once == form.data.password.again;
				else
					return form.$dirty && form.$valid && form.data.email;
			};

			//

			page.events.talk('userPasswordForm-init', form, $scope);
		};

		//

		return {
			restrict: 'E',
			templateUrl: 'userPasswordForm.html',
			scope: false,
			replace: true,
			link: link
		};
	}
]);

{'fraction_non_alphanumeric': 0.15673662830060933, 'fraction_numerical': 0.004062288422477996, 'mean_word_length': 2.5660832830416416, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '410564', 'n_tokens_mistral': 2597, 'n_tokens_neox': 1850, 'n_words': 332}