<commit_before>var app = angular.module("Colonnade", ['ngRoute', 'ngCookies'])
var API_URL = './api';

var email_regex = /^[a-z0-9._%+-]+@(?:[a-z0-9-]+\.)+[a-z]{2,4}$/;
var password_regex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,20}$/;
var username_regex = /^[a-zA-Z0-9]{2,12}$/;
var name_regex = /^.{3,}$/;

app
.config(function ($routeProvider, $locationProvider, $httpProvider){
	$httpProvider.useApplyAsync(true);
	$routeProvider
	.when('/',{
		templateUrl:'public/template/main.html',
		controller:'mainCtrl'})
	.when('/dashboard/',{
		templateUrl:'public/template/dashboard.html',
		controller:'dashboardCtrl'})
	.when('/login/',{
		templateUrl:'public/template/login.html',
		controller:'loginCtrl'})
	.otherwise({
		templateUrl:'public/template/404.html',
		controller:'404Ctrl'});
})
.controller("GlobCtrl", function($scope, $rootScope, $http){

})
.controller("mainCtrl", function($scope, $rootScope, $http){

})
.controller("dashboardCtrl", function($scope, $rootScope, $http){

})
.controller("loginCtrl", function($scope, $rootScope, $location, login, register){
	$scope.login = function() {
		login($scope.loginInfo.email, $scope.loginInfo.password, function(data){
			if(data.error == 0){
				$location.url("/dashboard/");
				$scope.loginErrMsg = "";
			}else{
				$scope.loginErrMsg = data.message;
			}
		});
	};
	$scope.register = function() {
		var ri = $scope.registerInfo;
		var invalid = {}
		if(ri){
			invalid.email = !Boolean(ri.email ? ri.email.match(email_regex) : false);
			invalid.username = !Boolean(ri.username ? ri.username.match(username_regex) : false);
			invalid.name = !Boolean(ri.name ? ri.name.match(name_regex) : false);
			invalid.password = !Boolean(ri.password ? ri.password.match(password_regex) : false);
		}else{
			invalid.email = invalid.username = invalid.name = invalid.password = true;
		}

		if (!invalid.email && !invalid.username && !invalid.name && !invalid.password) {
			register(
				ri.email,
				ri.username,
				ri.name,
				ri.password,
				function(data){
					if(data.error == 0){
						$scope.registerInfo.email = "";
						$scope.registerInfo.username = "";
						$scope.registerInfo.name = "";
						$scope.registerInfo.password = "";
						$scope.regSucc = true;
						$scope.regErrMsg = "";
					}else{
						$scope.regErrMsg = data.message;
					}
				}
			);
		}
		$scope.regInvalid = invalid;
	};
})
.controller("404Ctrl", function($scope, $rootScope, $http){

})
.factory('login', function($http){
	return function(email, password, callback){
		$http.post(API_URL + '/user/login', {
			email: email,
			password: password
		}, {
			withCredentials: true,
		}).then(function successCallback(response) {
			callback(response.data);
		}, function errorCallback(response) {
			console.log("error");
			callback(response.data);
		});
	}
})
.factory('register', function($http){
	return function(email, username, name, password, callback){
		$http.post(API_URL + '/user/register', {<commit_msg>frontend handling name from login response, adding more variable and function to login factory, so it can act as interface for storing user detail<commit_after>var app = angular.module("Colonnade", ['ngRoute', 'ngCookies'])
var API_URL = './api';

var email_regex = /^[a-z0-9._%+-]+@(?:[a-z0-9-]+\.)+[a-z]{2,4}$/;
var password_regex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,20}$/;
var username_regex = /^[a-zA-Z0-9]{2,12}$/;
var name_regex = /^.{3,}$/;

app
.config(function ($routeProvider, $locationProvider, $httpProvider){
	$httpProvider.useApplyAsync(true);
	$routeProvider
	.when('/',{
		templateUrl:'public/template/main.html',
		controller:'mainCtrl'})
	.when('/dashboard/',{
		templateUrl:'public/template/dashboard.html',
		controller:'dashboardCtrl'})
	.when('/login/',{
		templateUrl:'public/template/login.html',
		controller:'loginCtrl'})
	.otherwise({
		templateUrl:'public/template/404.html',
		controller:'404Ctrl'});
})
.controller("GlobCtrl", function($scope, $rootScope, $http){

})
.controller("mainCtrl", function($scope, $rootScope, $http){

})
.controller("dashboardCtrl", function($scope, $rootScope, $http){

})
.controller("loginCtrl", function($scope, $rootScope, $location, login, register){
	$scope.login = function() {
		login.launch($scope.loginInfo.email, $scope.loginInfo.password, function(data){
			if(data.error == 0){
				$location.url("/dashboard/");
				$scope.loginErrMsg = "";
			}else{
				$scope.loginErrMsg = data.message;
			}
		});
	};
	$scope.register = function() {
		var ri = $scope.registerInfo;
		var invalid = {}
		if(ri){
			invalid.email = !Boolean(ri.email ? ri.email.match(email_regex) : false);
			invalid.username = !Boolean(ri.username ? ri.username.match(username_regex) : false);
			invalid.name = !Boolean(ri.name ? ri.name.match(name_regex) : false);
			invalid.password = !Boolean(ri.password ? ri.password.match(password_regex) : false);
		}else{
			invalid.email = invalid.username = invalid.name = invalid.password = true;
		}

		if (!invalid.email && !invalid.username && !invalid.name && !invalid.password) {
			register(
				ri.email,
				ri.username,
				ri.name,
				ri.password,
				function(data){
					if(data.error == 0){
						$scope.registerInfo.email = "";
						$scope.registerInfo.username = "";
						$scope.registerInfo.name = "";
						$scope.registerInfo.password = "";
						$scope.regSucc = true;
						$scope.regErrMsg = "";
					}else{
						$scope.regErrMsg = data.message;
					}
				}
			);
		}
		$scope.regInvalid = invalid;
	};
})
.controller("404Ctrl", function($scope, $rootScope, $http){

})
.factory('login', function($http){
	var user = {};
	user.loggedIn = false;
	user.name = "";
	user.email = "";
	return {
		launch: function(email, password, callback){
			$http.post(API_URL + '/user/login', {
				email: email,
				password: password
			}, {
				withCredentials: true,
			}).then(function successCallback(response) {
				if(response.data.error == 0){
					user.loggedIn = true;
					user.name = response.data.data.name;
					user.email = email;
				}
				callback(response.data);
			}, function errorCallback(response) {
				console.log("error");
				callback(response.data);
			});
		},
		getUser: function(){
			return user;
		},
		checkLogin: function(){
			return null;
		}
	}
})
.factory('register', function($http){
	return function(email, username, name, password, callback){
		$http.post(API_URL + '/user/register', {
{'fraction_non_alphanumeric': 0.19680601221230626, 'fraction_numerical': 0.008298105526851417, 'mean_word_length': 4.002349256068912, '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': '6496696', 'n_tokens_mistral': 2495, 'n_tokens_neox': 2167, 'n_words': 364}