<commit_before><commit_msg>Create cookies.js<commit_after>// JavaScript Document
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/*
	This function formats the data field to send in the command
*/
function formSignInBuffer (username, password) {
	this.username = username;
	this.password = password;
	return this;
}

function signIn (username, password) {
	this.signIn = new formSignInBuffer (username, password);
	return this;
}

function signInBtnClick () {
	var signInUrl = '/wluxui/data/signin.php';
	var buffer = new signIn ($('#formUsername').val(), 
							 $('#formPassword').val());
	
	var postResponse = $.post(signInUrl, buffer);
	
	// if the response comes back let the user know.
	postResponse.done( function(response) {
		if (response.data != null) {
			// user is authorized so...
			// * save token in cookie
			createCookie ('weblabuxToken', response.data.token, 0);
			// * save the user name cookie
			createCookie ('weblabuxUsername', response.data.username, 0);
			// * reload the home page
			window.location.href = '/wluxui/index.php';
			// for now, we'll just show a message
			// alert ('worked!');
		}
		if (response.error) {
			// user is not athorized so...
			// * display error message
			// for now, we'll just show a message
			alert ('didn\'t work!');
		}
	});
}

function signoutClick(){
	document.cookie = "weblabuxToken=;expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/";
    document.cookie = "weblabuxUsername=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path = /";
    window.location.href = '/wluxui/index.php';
}

{'fraction_non_alphanumeric': 0.15493757094211125, 'fraction_numerical': 0.02043132803632236, 'mean_word_length': 3.6888297872340425, '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': '4360434', 'n_tokens_mistral': 653, 'n_tokens_neox': 568, 'n_words': 158}