<commit_before>/**
* auth.js
* Handles all of the authentication functions the client needs
* to perform in conjunction with the server.
* Author: <NAME> <<EMAIL>>
* Yes And Games (C) 2016
* <EMAIL>
*/

/*global $*/
/*global yag_api_endpoint*/
/*global dataCacheRetrieve*/
/*global dataCacheStore*/
/*global dataCacheAuthVar*/

// Private variables
var RESPONSE_OK = 0;
var RESPONSE_INVALID_LOGIN = 1;
var RESPONSE_UNKNOWN_ERROR = 2;
var RESPONSE_SERVER_UPDATING = 3;
var RESPONSE_USERNAME_TAKEN = 4;
var RESPONSE_ACCOUNT_CREATED = 5;
var RESPONSE_LOGGED_IN = 6;

/**
 * Attempt to authenticate a user.
 * @author <NAME> <<EMAIL>>
 * @param {string}   username        The username to send to the server.
 * @param {string}   password        The password to authenticate this user with.
 * @param {function} callback        Code to run with the login response.
 */
function authLogin(username, password, callback) {
  'use strict';
  var settings = {
    "async": true,
    "crossDomain": true,
    "url": yag_api_endpoint + "auth/login",
    "method": "POST",
    "headers": {
      "content-type": "application/json"
    },
    "processData": false,
    "data": "{\n    \"username\": \"" + username + "\",\n    \"password\": \"" + password + "\"\n}"
  };

  // Make sure the user isn't already logged in
  if (dataCacheRetrieve(dataCacheAuthVar) !== 'undefined') {
    $.ajax(settings).done(function (response) {
      if (response !== 'undefined') {
        switch (response[0].loginResponse) {
        case (RESPONSE_OK):
          dataCacheStore(dataCacheAuthVar, response[0]);
          break;
        }
        callback(response[0].loginResponse);
      }
    });
  } else {
    callback(RESPONSE_LOGGED_IN);
  }
}

/**
 * Attempt to create a user account.
 * @author <NAME> <<EMAIL>>
 * @param {string}   username        The username to send to the server.
 * @param {string}   password        The password to use for this user account.
* @param {string}   email            The email to use for this user.
 * @param {function} callback        Code to run after the with the create account response.
 */
function authCreateAccount(username, password, email, callback) {
  'use strict';
  var settings = {
    "async": true,
    "crossDomain": true,
    "url": yag_api_endpoint + "auth/create",
    "method": "POST",
    "headers": {
      "content-type": "application/json"
    },
    "processData": false,
    "data": "{\n    \"username\": \"" + username + "\",\n    \"password\": \"" + password + "\",\n  \"email\": \"" + email + "\n}"
  };

  $.ajax(settings).done(function (response) {
    if (response !== 'undefined') {
      switch (response.loginResponse) {
      case (RESPONSE_ACCOUNT_CREATED):
        dataCacheStore(dataCacheAuthVar, response);
        break;
      }
      callback(response.loginResponse);
    }
  });
}

/**
 * Confirm a user's account.
 * @author <NAME> <<EMAIL>>
 * @param {string}   confirmUUID     A unique ID to confirm the account.
 * @param {function} callback        Code to run after the with the create account response.
 */
function authConfirmAccount(confirmUUID, callback) {
    'use strict';
    var settings = {
      "async": true,
      "crossDomain": true,
      "url": yag_api_endpoint + "auth/create",
      "method": "POST",
      "headers": {
        "content-type": "application/json"
      },
      "processData": false,
      "data": "{\n    \"confirmUUID\": \"" + confirmUUID + "\n}"
    };<commit_msg>Updated auth confirm function to hit right endpoint<commit_after>/**
* auth.js
* Handles all of the authentication functions the client needs
* to perform in conjunction with the server.
* Author: <NAME> <<EMAIL>>
* Yes And Games (C) 2016
* <EMAIL>
*/

/*global $*/
/*global yag_api_endpoint*/
/*global dataCacheRetrieve*/
/*global dataCacheStore*/
/*global dataCacheAuthVar*/

// Private variables
var RESPONSE_OK = 0;
var RESPONSE_INVALID_LOGIN = 1;
var RESPONSE_UNKNOWN_ERROR = 2;
var RESPONSE_SERVER_UPDATING = 3;
var RESPONSE_USERNAME_TAKEN = 4;
var RESPONSE_ACCOUNT_CREATED = 5;
var RESPONSE_LOGGED_IN = 6;

/**
 * Attempt to authenticate a user.
 * @author <NAME> <<EMAIL>>
 * @param {string}   username        The username to send to the server.
 * @param {string}   password        The password to authenticate this user with.
 * @param {function} callback        Code to run with the login response.
 */
function authLogin(username, password, callback) {
  'use strict';
  var settings = {
    "async": true,
    "crossDomain": true,
    "url": yag_api_endpoint + "auth/login",
    "method": "POST",
    "headers": {
      "content-type": "application/json"
    },
    "processData": false,
    "data": "{\n    \"username\": \"" + username + "\",\n    \"password\": \"" + password + "\"\n}"
  };

  // Make sure the user isn't already logged in
  if (dataCacheRetrieve(dataCacheAuthVar) !== 'undefined') {
    $.ajax(settings).done(function (response) {
      if (response !== 'undefined') {
        switch (response[0].loginResponse) {
        case (RESPONSE_OK):
          dataCacheStore(dataCacheAuthVar, response[0]);
          break;
        }
        callback(response[0].loginResponse);
      }
    });
  } else {
    callback(RESPONSE_LOGGED_IN);
  }
}

/**
 * Attempt to create a user account.
 * @author <NAME> <<EMAIL>>
 * @param {string}   username        The username to send to the server.
 * @param {string}   password        The password to use for this user account.
* @param {string}   email            The email to use for this user.
 * @param {function} callback        Code to run after the with the create account response.
 */
function authCreateAccount(username, password, email, callback) {
  'use strict';
  var settings = {
    "async": true,
    "crossDomain": true,
    "url": yag_api_endpoint + "auth/create",
    "method": "POST",
    "headers": {
      "content-type": "application/json"
    },
    "processData": false,
    "data": "{\n    \"username\": \"" + username + "\",\n    \"password\": \"" + password + "\",\n  \"email\": \"" + email + "\n}"
  };

  $.ajax(settings).done(function (response) {
    if (response !== 'undefined') {
      switch (response.loginResponse) {
      case (RESPONSE_ACCOUNT_CREATED):
        dataCacheStore(dataCacheAuthVar, response);
        break;
      }
      callback(response.loginResponse);
    }
  });
}

/**
 * Confirm a user's account.
 * @author <NAME> <<EMAIL>>
 * @param {string}   confirmUUID     A unique ID to confirm the account.
 * @param {function} callback        Code to run after the with the create account response.
 */
function authConfirmAccount(confirmUUID, callback) {
    'use strict';
    var settings = {
      "async": true,
      "crossDomain": true,
      "url": yag_api_endpoint + "auth/confirm",
      "method": "POST",
      "headers": {
        "content-type": "application/json"
      },
      "processData": false,
      "data": "{\n    \"confirmUUID\": \"" + confirmUUID + "\n}"
    };
{'fraction_non_alphanumeric': 0.1486583440952791, 'fraction_numerical': 0.004017793083656192, 'mean_word_length': 2.8636363636363638, 'pattern_counts': {'":': 60, '<': 29, '<?xml version=': 0, '>': 29, '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': '184747', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2157, 'n_words': 625}