{"size": 803, "ext": "js", "max_stars_repo_path": "middleware/auth.js", "max_stars_repo_name": "Skylae/wenbo-system2", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "middleware/auth.js", "max_issues_repo_name": "Skylae/wenbo-system2", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "middleware/auth.js", "max_forks_repo_name": "Skylae/wenbo-system2", "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": 25.09375, "max_line_length": 81, "alphanum_fraction": 0.5068493151}
const User = require('../model/user')

module.exports = {
    // 从session中获取用户数据模块
    getUser: (req, res, next) => {
        req.user = req.session.user
        next();
    },

    // 用于验证管理员用户是否存在
    allowToAdmin: (req, res , next) => {

        
        console.log(`权限验证时的sessionStore------`)
        console.log(req.sessionStore.sessions)
        console.log('权限验证前的session------')
        console.log(req.session)
        
        let user = req.session.user;
        if(user) {
            User.updateSessionStore(req, res, next);
            // req.session.cookie.expires = new Date(Date.now() + 60 * 60 * 1000)
            req.session.save(); // sessionStore刷新过期时间

            req.user = user;
            next();
        }
        else {
            res.redirect('/login');
        }
    }
}