<commit_before>// Includes
var http = require('./http.js').func;
var promise = require('./promise.js');
var options = require('../options.js');

// Args
exports.required = ['username', 'password'];
exports.optional = ['jar'];

// Define
function login (jar, username, password) {
  return function (resolve, reject) {
    var url = '//www.roblox.com/MobileAPI/Login'; // Using this API because it returns user info.
    var post = {
      'username': username,
      'password': password
    };
    var httpOpt = {
      url: url,
      options: {
        method: 'POST',
        json: post,
        resolveWithFullResponse: true,
        jar: jar
      }
    };
    http(httpOpt)
    .then(function (res) {
      var body = res.body;
      if (body.Status === 'OK') {
        if (options.sessionOnly) {
          var session = res.headers['set-cookie'].toString().match('\.ROBLOSECURITY=(.*);')[1];
          if (jar) {
            jar.session = session;
          } else {
            options.jar.session = session;
          }
        }
        resolve(body.UserInfo);
      } else {
        reject(new Error(body.Status));
      }
    });
  };
}

exports.func = function (args) {
  return promise(login(args.jar, args.username, args.password));
};<commit_msg>Fix<commit_after>// Includes
var http = require('./http.js').func;
var promise = require('./promise.js');
var options = require('../options.js');

// Args
exports.required = ['username', 'password'];
exports.optional = ['jar'];

// Define
function login (jar, username, password) {
  return function (resolve, reject) {
    var url = '//www.roblox.com/MobileAPI/Login'; // Using this API because it returns user info.
    var post = {
      'username': username,
      'password': password
    };
    var httpOpt = {
      url: url,
      options: {
        method: 'POST',
        json: post,
        resolveWithFullResponse: true,
        jar: jar
      }
    };
    http(httpOpt)
    .then(function (res) {
      var body = res.body;
      if (body.Status === 'OK') {
        if (options.sessionOnly) {
          var cookies = res.headers['set-cookie']; // If the user is already logged in a new cookie will not be returned.
          if (cookies) {
            var session = cookies.toString().match('\.ROBLOSECURITY=(.*);')[1];
            if (jar) {
              jar.session = session;
            } else {
              options.jar.session = session;
            }
          }
        }
        resolve(body.UserInfo);
      } else {
        reject(new Error(body.Status));
      }
    });
  };
}

exports.func = function (args) {
  return promise(login(args.jar, args.username, args.password));
};
{'fraction_non_alphanumeric': 0.15698763581865868, 'fraction_numerical': 0.0007493443237167478, 'mean_word_length': 2.0724971231300344, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '760605', 'n_tokens_mistral': 793, 'n_tokens_neox': 792, 'n_words': 197}