{"size": 1812, "ext": "js", "max_stars_repo_path": "router/admin.js", "max_stars_repo_name": "zhaobo-arch/talk", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "router/admin.js", "max_issues_repo_name": "zhaobo-arch/talk", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "router/admin.js", "max_forks_repo_name": "zhaobo-arch/talk", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.2258064516, "max_line_length": 113, "alphanum_fraction": 0.5507726269}
const express = require('express');
const router = express.Router();
const oracledb = require('oracledb');
const dialog = require('dialog')
const { password } = require('../db/db_config');
const config = require('../db/db_config');
router.get('/adminlogin', (req, res) => {
    console.log(req.session.user);

    res.render('adminlogin', {
        isLogin: false
    })
})

router.post('/adminlogin', (req, res) => {
    const _adminnum = req.body.adminnum;
    const _password = req.body.apassword;

    oracledb.getConnection(config, function(err, connection) {
        if (err) { console.log(err.message); return; }

        var query = `SELECT * FROM administrators WHERE Adminnum = '${_adminnum}' AND APASSWORD = '${_password}'`
        connection.execute(query, function(err, result) {
            if (err) {
                console.error(err.message);

                doRelease(connection);
                return;
            }
            isLogin = true
            doRelease(connection, result.rows);
        });
    });

    function doRelease(connection, user) {
        connection.close(function(err) {
            if (err) {
                console.error(err.message);
                res.redirect('/adminlogin');
            }

            console.log(user);
            if (user.length == 1) {
                res.redirect('/adminindex');
                req.session.user = { isLogin: true, adminname: user[0][2] };
                console.log(req.session.user);
            } else { res.redirect('/admin/adminlogin'); }
        })
    }
})
router.get('/logout', (req, res) => {
    req.session.user = null
    if (req.session.user == null || req.session.user == undefined) {
        res.redirect('/')
        isLogin = false
    } else {
        return false
    }
})


module.exports = router