<commit_before>/**
 * Copyright (c) 2016-present, <NAME> <@AlejoJamC>.
 * All rights reserved.
 *
 * This source code is licensed under the MIT license found in the LICENSE
 * file in the root directory of this source tree or translated in the assets folder.
 */

var express     = require('express');
var indexRouter = express.Router();
var logger      = require('../config/logger').logger;
var oracledb    = require('oracledb');

/* GET Index page. */
indexRouter.get('/', function (req, res) {
    res.redirect('/login');
});


/* GET Login page. */
indexRouter.get('/login', function (req, res) {
    var error = '';

    // Basic error validator
    if(typeof req.query.error !== 'undefined'){
        error = req.query.error;
    }

    res.render('auth/index', {
        title   : 'Analytics Website | Login',
        level   : '',
        layout  : 'auth',
        error   : error
    });
});

/* POST Login page. */
indexRouter.post('/login', function (req, res) {
    if( typeof req.body.username === 'undefined'&& req.body.username === ''
        && typeof req.body.password === '<PASSWORD>' && req.body.password === ''){
        logger.info('Login credentials: Empty values.');
        // error=11 Login credentials: Empty values.
        res.redirect('/login?error=11');
    }

    oracledb.getConnection({
        user            : process.env.ORACLE_USERNAME,
        password        : <PASSWORD>,
        connectString   : process.env.ORACLE_HOST + ':' + process.env.ORACLE_PORT
        + '/' + process.env.ORACLE_SID
    }, function (err, connection) {
        if (err){
            logger.error(err.message);
            // error=0 trying to connect with database
            res.redirect('/login?error=0');
        }

        // Login credentidas
        var user        = req.body.username;
        var password    = req.body.password;

        connection.execute(
            // The statement to execute
            "SELECT ANALYTICS.\"Usuarios\".\"idUsuario\", ANALYTICS.\"Usuarios\".\"nombre\", " +
            " ANALYTICS.\"Usuarios\".\"usuario\", ANALYTICS.\"Usuarios\".\"password\" " +
            " FROM ANALYTICS.\"Usuarios\" " +
            " WHERE \"Usuarios\".\"usuario\" =':user' AND \"Usuarios\".\"password\" =':password'",
            { user : user , password : password },

            // The Callback function handles the SQL execution results
            function (err, result) {
                logger.info("SELECT ANALYTICS.\"Usuarios\".\"idUsuario\", ANALYTICS.\"Usuarios\".\"nombre\", " +
                    " ANALYTICS.\"Usuarios\".\"usuario\", ANALYTICS.\"Usuarios\".\"password\" " +
                    " FROM ANALYTICS.\"Usuarios\" " +
                    " WHERE \"Usuarios\".\"usuario\" ='" + user +
                    "' AND \"Usuarios\".\"password\" ='" + password + "'");
                if (err) {
                    logger.error(err.message);
                    connection.close(
                        function(err) {
                            if (err) {
                                // error=1 trying to disconnect of database
                                logger.error(err.message);
                                res.redirect('/login?error=1');
                            }
                    });
                    // Error doing select statement
                    res.redirect('/login?error=12');
                }

                // Login success
                // Create the session
                logger.info(result.metaData);
                logger.info(result.rows);
                connection.close(
                    function(err) {
                        if (err) {
                            // error=1 trying to disconnect of database
                            logger.error(err.message);
                            res.redirect('/login?error=1');
                        }
                });
                res.redirect('/dashboard');
            }

        );

    });


});

module.exports = indexRouter;<commit_msg>login query<commit_after>/**
 * Copyright (c) 2016-present, <NAME> <@AlejoJamC>.
 * All rights reserved.
 *
 * This source code is licensed under the MIT license found in the LICENSE
 * file in the root directory of this source tree or translated in the assets folder.
 */

var express     = require('express');
var indexRouter = express.Router();
var logger      = require('../config/logger').logger;
var oracledb    = require('oracledb');

/* GET Index page. */
indexRouter.get('/', function (req, res) {
    res.redirect('/login');
});


/* GET Login page. */
indexRouter.get('/login', function (req, res) {
    var error = '';

    // Basic error validator
    if(typeof req.query.error !== 'undefined'){
        error = req.query.error;
    }

    res.render('auth/index', {
        title   : 'Analytics Website | Login',
        level   : '',
        layout  : 'auth',
        error   : error
    });
});

/* POST Login page. */
indexRouter.post('/login', function (req, res) {
    if( typeof req.body.username === 'undefined'&& req.body.username === ''
        && typeof req.body.password === '<PASSWORD>' && req.body.password === ''){
        logger.info('Login credentials: Empty values.');
        // error=11 Login credentials: Empty values.
        res.redirect('/login?error=11');
    }

    oracledb.getConnection({
        user            : process.env.ORACLE_USERNAME,
        password        : <PASSWORD>.ORACLE_PASSWORD,
        connectString   : process.env.ORACLE_HOST + ':' + process.env.ORACLE_PORT
        + '/' + process.env.ORACLE_SID
    }, function (err, connection) {
        if (err){
            logger.error(err.message);
            // error=0 trying to connect with database
            res.redirect('/login?error=0');
        }

        // Login credentidas
        var user        = req.body.username;
        var password    = <PASSWORD>;

        var sql = "SELECT ANALYTICS.\"Usuarios\".\"idUsuario\", ANALYTICS.\"Usuarios\".\"nombre\", " +
            " ANALYTICS.\"Usuarios\".\"usuario\", ANALYTICS.\"Usuarios\".\"password\" " +
            " FROM ANALYTICS.\"Usuarios\" " +
            " WHERE \"Usuarios\".\"usuario\" ='"+ user +"' AND \"Usuarios\".\"password\" ='" +  password + "'";

        connection.execute(
            // The statement to execute
            sql,
            [ ],

            // The Callback function handles the SQL execution results
            function (err, result) {
                logger.info(sql);
                if (err) {
                    logger.error(err.message);
                    connection.close(
                        function(err) {
                            if (err) {
                                // error=1 trying to disconnect of database
                                logger.error(err.message);
                                res.redirect('/login?error=1');
                            }
                            logger.info('Connection to Oracle closed successfully!');
                    });
                    // Error doing select statement
                    res.redirect('/login?error=12');
                }

                // Login success
                // Create the session
                logger.info(result.metaData);
                logger.info(result.rows);
                connection.close(
                    function(err) {
                        if (err) {
                            // error=1 trying to disconnect of database
                            logger.error(err.message);
                            res.redirect('/login?error=1');
                        }
                        logger.info('Connection to Oracle closed successfully!');
                });
                res.redirect('/dashboard');
            }

        );

    });


});

module.exports = indexRouter;
{'fraction_non_alphanumeric': 0.14176342988388413, 'fraction_numerical': 0.0040831951001658795, 'mean_word_length': 1.4725552050473185, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '297871', 'n_tokens_mistral': 2142, 'n_tokens_neox': 2033, 'n_words': 453}