<commit_before>'use strict';

// ==================================================
// This file is intended to reflect the Stormpath
// Node.js Quickstart documented here:
//
//     http://docs.stormpath.com/nodejs/api/
//
// Enjoy!
// ==================================================

var stormpath = require('stormpath');

var homeDir = process.env[(process.platform === 'win32' ? 'USERPROFILE' : 'HOME')];
var apiKeyFilePath = homeDir + '/.stormpath/apiKey.properties';

//helper function to prevent any data collisions in the tenant while running the quickstart:
function unique(aString) {
  return aString + '-' + require('node-uuid').v4().toString();
}

//populated during the quickstart steps
var client, application, account, group = null;

var accountEmail = unique('jlpicard') + '@mailinator.com';

// ==================================================
// Step 1 - Load the API Key file and create a Client
// ==================================================
stormpath.loadApiKey(apiKeyFilePath, function (err, apiKey) {
  if (err) throw err;

  client = new stormpath.Client({apiKey: apiKey});

  //client is available, kick off the quickstart steps:
  createApplication();
});

// ==================================================
// Step 2 - Register an application with Stormpath
// ==================================================
function createApplication() {

  var app = {
    name: unique('My Awesome Application'),
    description: ('No, Srsly. It\'s Awesome')
  };

  return client.createApplication(app, {createDirectory: true}, function(err, app) {
    if (err) throw err;
    application = app;
    console.log('Created application:');
    console.log(application);
    return createAccount(); //next quickstart step
  });
}

// ==================================================
// Step 3 - Create a new application account
// ==================================================
function createAccount() {

  var acct = {
    givenName: 'Jean-Luc',
    surname: 'Picard',
    username: unique('jlpicard'),

    //Change the email value below to be your REAL email address if you want to see the
    //password reset email workflow later

    email: accountEmail,
    password: '<PASSWORD>!'
  };

  return application.createAccount(acct, function(err, createdAccount) {
    if (err) throw err;
    account = createdAccount;
    console.log('Created account:');
    console.log(account);
    return updateAccount(); //next quickstart step
  });
}

// ==================================================
// Step 3 - Update an account
// ==================================================
function updateAccount() {

  account.middleName = 'Make it so.';
  return account.save(function(err, savedAccount) {
    if (err) throw err;
    account = savedAccount;
    console.log('Updated account:');
    console.log(account);
    return authenticateAccount(); //next quickstart step
  });

}

// ==================================================
// Step 4 - Authenticate an account
// ==================================================
function authenticateAccount() {

  var authcRequest = {
    username: accountEmail, //we could've entered the username instead
    password: '<PASSWORD>!'
  };
<commit_msg>minor syntactic changes for readability<commit_after>'use strict';

// ==================================================
// This file is intended to reflect the Stormpath
// Node.js Quickstart documented here:
//
//     http://docs.stormpath.com/nodejs/api/
//
// Enjoy!
// ==================================================

var stormpath = require('stormpath');

var homeDir = process.env[(process.platform === 'win32' ? 'USERPROFILE' : 'HOME')];
var apiKeyFilePath = homeDir + '/.stormpath/apiKey.properties';

//helper function to prevent any data collisions in the tenant while running the quickstart:
function unique(aString) {
  return aString + '-' + require('node-uuid').v4().toString();
}

//populated during the quickstart steps
var client, application, account, group = null;

var accountEmail = unique('jlpicard') + '@mailinator.com';

// ==================================================
// Step 1 - Load the API Key file and create a Client
// ==================================================
stormpath.loadApiKey(apiKeyFilePath, function (err, apiKey) {
  if (err) throw err;

  client = new stormpath.Client({apiKey: apiKey});

  //client is available, kick off the quickstart steps:
  createApplication();
});

// ==================================================
// Step 2 - Register an application with Stormpath
// ==================================================
function createApplication() {

  var app = {
    name: unique('My Awesome Application'),
    description: ('No, Srsly. It\'s Awesome')
  };

  return client.createApplication(app, {createDirectory: true}, function(err, app) {
    if (err) throw err;
    application = app;
    console.log('Created application:');
    console.log(application);
    return createAccount(); //next quickstart step
  });
}

// ==================================================
// Step 3 - Create a new application account
// ==================================================
function createAccount() {

  var acct = {
    givenName: 'Jean-Luc',
    surname: 'Picard',
    username: unique('jlpicard'),
    email: accountEmail,
    password: '<PASSWORD>!'
  };

  return application.createAccount(acct, function(err, createdAccount) {
    if (err) throw err;
    account = createdAccount;
    console.log('Created account:');
    console.log(account);
    return updateAccount(); //next quickstart step
  });
}

// ==================================================
// Step 3 - Update an account
// ==================================================
function updateAccount() {

  account.middleName = 'Make it so.';

  return account.save(function(err, savedAccount) {
    if (err) throw err;
    account = savedAccount;
    console.log('Updated account:');
    console.log(account);
    return authenticateAccount(); //next quickstart step
  });

}

// ==================================================
// Step 4 - Authenticate an account
// ==================================================
function authenticateAccount() {

  var authcRequest = {
    username: accountEmail, //we could've entered the username instead
    password: '<PASSWORD>!'
  };

{'fraction_non_alphanumeric': 0.2991358994501178, 'fraction_numerical': 0.0025137470542026708, 'mean_word_length': 4.469072164948454, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6666398', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1560, 'n_words': 468}