<commit_before>angular.module('myApp.main.register', [
	'ui.bootstrap'
]).

config(['$routeProvider', function ( $routeProvider ){
	$routeProvider.when('/register', {
		title: 'Registration',
		subTitle: 'Form',
		templateUrl: 'app/main/register/register.tpl.html',
		controller: 'RegisterFormCtrl',
		resolve: {
			firms: ['interface', function (interface) {
				return interface.user('listFirms');
			}]
		}
	});
}]).

controller('RegisterFormCtrl', ['$scope', '$modal', 'interface', 'security', 'firms', 'appStrings', function ($scope, $modal, interface, security, firms, appStrings){

	// find firm vs. register
	$scope.firms = firms;
	$scope.clearFirm = function () { 
		$scope.user.firm = '';
		$scope.firmModified = false;
	};

	// initialize empty user
	$scope.user = {
		preName: '',
		firm: ''
	};
	$scope.modifyFirm = function() { $scope.firmModified = true; };

	// validate email address
	$scope.formState = 0;
	$scope.checkEmail = function() {
		interface.user('checkEmail', {email: $scope.user.email}).then(function (res) {
			$scope.formState = 1;
		}, function (res) {
			$scope.formState = -1;
		});
	};

	// pw-reset
	$scope.resetMsg = null;
	$scope.pwReset = function() {
		security.reset( $scope.user.email ).then(function() {
			$scope.resetMsg = appStrings.register.resetGood;
		}, function() {
			$scope.resetMsg = appStrings.register.resetBad;
		});
	};

	// handle registration clicks
	$scope.register = function() {
		if ($scope.passVerify !== $scope.user.password) {
			$scope.message = appStrings.register.passMatch;
			return;
		}
		if (($scope.user.firm.addr || {}).addressID === undefined) {
			$scope.message = appStrings.register.firmAddr;
			return;
		}
		if ($scope.user.addr.addressID === undefined) {
			$scope.message = appStrings.register.userAddr;
			return;
		}
		interface.user('addUser', $scope.user).then(function() {
			$scope.message = appStrings.register.success; // some sort of callback on close
			security.requestCurrentUser();
			// security.redirect('/cart');
			window.history.back(); // go to last page!
		}, function (err) {
			$scope.message = (err=='dup') ? appStrings.register.duplicate : appStrings.register.failure ;
		});
	};

	// For same address handling
	$scope.same = false;
	var firstLoad = true, oldUserAddr = null;
	$scope.$watch('same', function(value) {
		if (firstLoad) {<commit_msg>Notify-bugfix: fix register notify<commit_after>angular.module('myApp.main.register', [
	'ui.bootstrap'
]).

config(['$routeProvider', function ( $routeProvider ){
	$routeProvider.when('/register', {
		title: 'Registration',
		subTitle: 'Form',
		templateUrl: 'app/main/register/register.tpl.html',
		controller: 'RegisterFormCtrl',
		resolve: {
			firms: ['interface', function (interface) {
				return interface.user('listFirms');
			}]
		}
	});
}]).

controller('RegisterFormCtrl', ['$scope', '$modal', 'interface', 'security', 'firms', 'appStrings', function ($scope, $modal, interface, security, firms, appStrings){

	// find firm vs. register
	$scope.firms = firms;
	$scope.clearFirm = function () { 
		$scope.user.firm = '';
		$scope.firmModified = false;
	};

	// initialize empty user
	$scope.user = {
		preName: '',
		firm: ''
	};
	$scope.modifyFirm = function() { $scope.firmModified = true; };

	// validate email address
	$scope.formState = 0;
	$scope.checkEmail = function() {
		interface.user('checkEmail', {email: $scope.user.email}).then(function (res) {
			$scope.formState = 1;
		}, function (res) {
			$scope.formState = -1;
		});
	};

	// pw-reset
	$scope.resetMsg = null;
	$scope.pwReset = function() {
		security.reset( $scope.user.email ).then(function() {
			$scope.resetMsg = appStrings.register.resetGood();
		}, function() {
			$scope.resetMsg = appStrings.register.resetBad();
		});
	};

	// handle registration clicks
	$scope.register = function() {
		if ($scope.passVerify !== $scope.user.password) {
			$scope.message = appStrings.register.passMatch();
			return;
		}
		if (($scope.user.firm.addr || {}).addressID === undefined) {
			$scope.message = appStrings.register.firmAddr();
			return;
		}
		if ($scope.user.addr.addressID === undefined) {
			$scope.message = appStrings.register.userAddr();
			return;
		}
		interface.user('addUser', $scope.user).then(function() {
			$scope.message = appStrings.register.success(); // some sort of callback on close
			security.requestCurrentUser();
			// security.redirect('/cart');
			window.history.back(); // go to last page!
		}, function (err) {
			$scope.message = (err=='dup') ? appStrings.register.duplicate() : appStrings.register.failure() ;
		});
	};

	// For same address handling
	$scope.same = false;
	var firstLoad = true, oldUserAddr = null;
	$scope.$watch('same', function(value) {
		if (firstLoad) {
{'fraction_non_alphanumeric': 0.18277532112023584, 'fraction_numerical': 0.0012634238787113076, 'mean_word_length': 3.9530761209593326, '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': '4102824', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1541, 'n_words': 299}