function logincontroller() {
    return {
        index(req, res) {
            if (req.session.userlogin) {
                if (req.session.userlogin.userlogintype === 'userlogin') {
                    res.redirect('/admin/games');
                } else {
                    res.render('login')
                }
            } else {
                res.render('login')
            }
        },
        loginpost(req, res) {
            const { username, userpass } = req.body;
            if (username && userpass) {
                if (username === process.env.APPUSERNAME && userpass === process.env.APPUSERPASS) {
                    req.session.userlogin = { userlogintype: "userlogin" }
                    res.redirect('/admin/games');
                } else {
                    res.redirect('/login')
                }
            } else {
                res.redirect('/login')
            }
        },
        userlogout(req, res) {
            req.session.userlogin = { userlogintype: "logout" }
            res.redirect('/login')
        }
    }
}

module.exports = logincontroller;