admin.js
1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* 文章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 !== '!q@w#e$r') {
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;