Commit f1bf3e35 authored by Lorex's avatar Lorex

release: 新增權限機制

parents 6ae657d4 d514ff00
......@@ -28,8 +28,30 @@ module.exports = {
fn: async function (inputs, exits) {
// 權限表(之後視情況開 db collection)
const roleName = {
0: {
name: 'SysAdmin'
},
1: {
name: 'Admin'
},
10: {
name: 'Teacher'
},
999: {
name: 'Student'
},
1000: {
name: 'StudentWithoutExam'
}
};
// 查詢 mail
const _user = await User.findOne({email: inputs.email});
let token = await jwt.sign({
iat: Math.floor(Date.now()/1000)
iat: Math.floor(Date.now()/1000),
role: roleName[_user.role].name
}, sails.config.custom.jwtSecret, {
issuer: 'Exam API SSO System',
subject: inputs.email,
......
......@@ -24,10 +24,10 @@ module.exports = {
required: true,
encrypt: true
}, // 密碼,
// role: {
// type: 'number',
// defaultsTo: 999
// }, // 權限,0: 系統管理員、999:一般使用者
role: {
type: 'number',
defaultsTo: 999
}, // 權限,0: 系統管理員、999:一般使用者
status: {
type: 'number',
defaultsTo: 1
......
......@@ -11,5 +11,5 @@
module.exports.routes = {
'POST /user/login': 'user/login',
'POST /app/auth': 'app/auth',
'*': 'main/index'
// '*': 'main/index'
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment