<commit_before>var debug = require('debug')('VaccineForChild:auth');
var express = require('express');
var mailer = require('../utility/mailer');
var session = require('../utility/session');
var database = require('../utility/database');

var router = express.Router();

var SESSION_ID_COOKIE = 'SessionID';

/* POST change password */
router.post('/update-user', function (req, res, next) {
    var user = req.body;
    var key = req.cookies[SESSION_ID_COOKIE];
    var sdat = session.getSession(key);
    if (sdat) {
        user.id = sdat.data.id;
        if (user.email != sdat.data.email) user.confirmed = 0;
        else user.email = null;
        if (user.name == sdat.data.name) user.name = null;
        if (user.address == sdat.data.address) user.address = null;
        database.updateUser(user, function (err, result) {
            if (err) {
                res.send(err);
            }
            else {
                sdat.data = result;
                res.sendStatus(200);
                if (!user.confirmed) {
                    mailer.sendConfirmCode(sdat.data.email, session.getConfirmCode());
                }
            }
        });
    }
});

/* POST add new child */
router.post('/add-child', function (req, res, next) {
    var user = req.body;
    var key = req.cookies[SESSION_ID_COOKIE];
    var sdat = session.getSession(key);
    if (sdat) {
        user.dob = new Date(user.year, user.month, user.day);
        database.createChild(user.dob, sdat.user.id, user.name, user.height, user.weight, function (err, result) {
            if (err) {
                res.send(err);
            }
            else {
                sdat.data = result;
                res.sendStatus(200);
            }
        });
    }
});

/* GET list of all children */
router.get('/get-children', function (req, res, next) {
    var sdat = session.getSession(key);
    if (sdat) {
        database.getAllChilds(sdat.user.id, function (err, result) {
            if (err) {
                res.send(err);
            }
            else {
                sdat.data = result;
                res.sendStatus(200);
            }
        });
    }
});

module.exports = router;<commit_msg>2 tigers were fixed<commit_after>var debug = require('debug')('VaccineForChild:auth');
var express = require('express');
var mailer = require('../utility/mailer');
var session = require('../utility/session');
var database = require('../utility/database');

var router = express.Router();

var SESSION_ID_COOKIE = 'SessionID';

/* POST change password */
router.post('/update-user', function (req, res, next) {
    var user = req.body;
    var key = req.cookies[SESSION_ID_COOKIE];
    var sdat = session.getSession(key);
    if (sdat) {
        user.id = sdat.data.id;
        if (user.email != sdat.data.email) user.confirmed = 0;
        else user.email = null;
        if (user.name == sdat.data.name) user.name = null;
        if (user.address == sdat.data.address) user.address = null;
        database.updateUser(user, function (err, result) {
            if (err) {
                res.send(err);
            }
            else {
                sdat.data = result;
                res.sendStatus(200);
                if (!user.confirmed) {
                    mailer.sendConfirmCode(sdat.data.email, session.getConfirmCode());
                }
            }
        });
    }
});

/* POST add new child */
router.post('/add-child', function (req, res, next) {
    var user = req.body;
    var key = req.cookies[SESSION_ID_COOKIE];
    var sdat = session.getSession(key);
    if (sdat) {
        user.dob = new Date(user.year, user.month, user.day);
        database.createChild(user.dob, sdat.data.id, user.name, user.height, user.weight, function (err, result) {
            if (err) {
                res.send(err);
            }
            else {
                sdat.data = result;
                res.sendStatus(200);
            }
        });
    }
});

/* GET list of all children */
router.get('/get-children', function (req, res, next) {
    var sdat = session.getSession(key);
    if (sdat) {
        database.getAllChilds(sdat.data.id, function (err, result) {
            if (err) {
                res.send(err);
            }
            else {
                sdat.data = result;
                res.sendStatus(200);
            }
        });
    }
});

module.exports = router;
{'fraction_non_alphanumeric': 0.1449341208541572, 'fraction_numerical': 0.004770558836892321, 'mean_word_length': 1.8080357142857142, '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': '1014629', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1342, 'n_words': 288}