<commit_before>var express = require('express');
var router = express.Router();

var parseXmlString = require('xml2js').parseString;
var https = require('https');
var querystring = require('querystring');

var utils = require('../utils');

router.get('/', function(req, res, next) {
	res.json({
		status: "ok",
		version: "1"
	});
});

router.post('/schedules/connect', global.apiCall, global.requireUser, global.getUserRecord, function(req, res, next) {
	var username = req.body.username;
	var password = req.body.password;

	var rouxRequest = "";
	rouxRequest += "<request><key></key><action>authenticate</action><credentials><username>";
	rouxRequest += username.encodeHTML();
	rouxRequest += "</username><password type=\"plaintext\">";
	rouxRequest += password.encodeHTML();
	rouxRequest += "</password></credentials></request>";

	var post_data = querystring.stringify({
		'rouxRequest': rouxRequest
	});

	var post_options = {
		host: 'schedules.dalton.org',
		port: '443',
		path: '/roux/index.php',
		method: 'POST',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded',
			'Content-Length': post_data.length
		}
	};

	var post_req = https.request(post_options, function(hRes) {
		hRes.setEncoding('utf8');
		hRes.on('data', function (chunk) {
			parseXmlString(chunk, function(err, data) {
				if (err) {
					res.json({err:err});
					return;
				}
				if (data["response"]["result"][0]["$"]["status"] != 200) {
					res.json({
						status: "ok",
						message: "The username or password was incorrect!"
					});
					return;
				}
				var key = data["response"]["result"][0]["key"][0]["_"];
				var owner = data["response"]["result"][0]["key"][0]["$"]["owner"];

				var start = utils.findThisMonday();
				var end = new Date(start);
				end.setDate(end.getDate() + 4);

				rouxRequest = "";
				rouxRequest += "<request><key>";
				rouxRequest += key.encodeHTML();
				rouxRequest += "</key><action>selectStudentCalendar</action><ID>";
				rouxRequest += owner.encodeHTML();
				rouxRequest += "</ID><start>";
				rouxRequest += utils.formatDate_roux(start);
				rouxRequest += "</start><end>";
				rouxRequest += utils.formatDate_roux(end);
				rouxRequest += "</end></request>";

				post_data = querystring.stringify({
					'rouxRequest': rouxRequest
				});
				post_options.headers["Content-Length"] = post_data.length;
				post_req = https.request(post_options, function(hUserRes) {
					hUserRes.setEncoding('utf8');
					hUserRes.on('data', function (chunk) {
						parseXmlString(chunk, function(err, data) {
							res.json({
								status: "ok",
								data: data
							});
						});
					});
				});

				post_req.write(post_data);
				post_req.end();
			});
		});
	});

	post_req.write(post_data);
	post_req.end();
});

module.exports = router;
<commit_msg>wheye you no work<commit_after>var express = require('express');
var router = express.Router();

var parseXmlString = require('xml2js').parseString;
var https = require('https');
var querystring = require('querystring');

var utils = require('../utils');

router.get('/', function(req, res, next) {
	res.json({
		status: "ok",
		version: "1"
	});
});

router.post('/schedules/connect', global.apiCall, global.requireUser, global.getUserRecord, function(req, res, next) {
	var username = req.body.username;
	var password = req.body.password;

	var rouxRequest = "";
	rouxRequest += "<request><key></key><action>authenticate</action><credentials><username>";
	rouxRequest += username.encodeHTML();
	rouxRequest += "</username><password type=\"plaintext\">";
	rouxRequest += password.encodeHTML();
	rouxRequest += "</password></credentials></request>";

	var post_data = querystring.stringify({
		'rouxRequest': rouxRequest
	});

	var post_options = {
		host: 'schedules.dalton.org',
		port: '443',
		path: '/roux/index.php',
		method: 'POST',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded',
			'Content-Length': post_data.length
		}
	};

	var post_req = https.request(post_options, function(hRes) {
		hRes.setEncoding('utf8');
		hRes.on('data', function (chunk) {
			parseXmlString(chunk, function(err, data) {
				if (err) {
					res.json({err:err});
					return;
				}
				if (data["response"]["result"][0]["$"]["status"] != 200) {
					res.json({
						status: "ok",
						message: "The username or password was incorrect!"
					});
					return;
				}
				var key = data["response"]["result"][0]["key"][0]["_"];
				var owner = data["response"]["result"][0]["key"][0]["$"]["owner"];

				var start = utils.findThisMonday();
				var end = new Date(start);
				end.setDate(end.getDate() + 4);

				rouxRequest = "";
				rouxRequest += "<request><key>";
				rouxRequest += key.encodeHTML();
				rouxRequest += "</key><action>selectStudentCalendar</action><ID>";
				rouxRequest += owner.encodeHTML();
				rouxRequest += "</ID><start>";
				rouxRequest += utils.formatDate_roux(start);
				rouxRequest += "</start><end>";
				rouxRequest += utils.formatDate_roux(end);
				rouxRequest += "</end></request>";

				post_data = querystring.stringify({
					'rouxRequest': rouxRequest
				});
				post_options.headers["Content-Length"] = post_data.length;
				post_req = https.request(post_options, function(hUserRes) {
					hUserRes.setEncoding('utf8');
					hUserRes.on('data', function (chunk) {
						parseXmlString(chunk, function(err, data) {
							res.json({
								status: "ok",
								chunk: chunk,
								data: data
							});
						});
					});
				});

				post_req.write(post_data);
				post_req.end();
			});
		});
	});

	post_req.write(post_data);
	post_req.end();
});

module.exports = router;

{'fraction_non_alphanumeric': 0.1921847246891652, 'fraction_numerical': 0.005683836589698046, 'mean_word_length': 3.8459552495697076, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '1645803', 'n_tokens_mistral': 2244, 'n_tokens_neox': 1862, 'n_words': 331}