admin.js 1.39 KB
/**
 * 文章controller
 * @author: leo <qi.li@yoho.cn>
 * @date: 23/06/2017
 */
const _ = require('lodash');

const adminController = {
    /**
     * 登录页
     * @param req
     * @param res
     */
    loginPage(req, res) {
        res.render('login', {
            layout: false,
            page: 'login',
            module: 'admin',
            bodyClass: 'login'
        });
    },

    /**
     * 管理员登录
     * @param req
     * @param res
     */
    login(req, res) {
        const userName = req.body.userName || '';
        const password = req.body.password || '';

        if (userName !== 'admin' || password !== 'yap@admin') {
            return res.json({
                code: 400,
                message: '请检查账号和密码'
            });
        }

        if (!userName || !password) {
            return res.json({
                code: 400,
                message: '请检查账号和密码'
            });
        }

        _.set(req.session, 'user.isAdmin', true);
        res.json({
            code: 200,
            message: '登录成功'
        });
    },

    /**
     * 登出
     * @param req
     * @param res
     */
    logout(req, res) {
        res.clearCookie('yoho_activity');
        res.clearCookie('yoho_activity.sig');
        res.json({
            code: 200,
            message: '登出成功'
        });
    }
};


module.exports = adminController;