Commit f1bf3e35 authored by Lorex's avatar Lorex
Browse files

release: 新增權限機制

parents 6ae657d4 d514ff00
...@@ -28,8 +28,30 @@ module.exports = { ...@@ -28,8 +28,30 @@ module.exports = {
fn: async function (inputs, exits) { 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({ 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, { }, sails.config.custom.jwtSecret, {
issuer: 'Exam API SSO System', issuer: 'Exam API SSO System',
subject: inputs.email, subject: inputs.email,
......
...@@ -24,10 +24,10 @@ module.exports = { ...@@ -24,10 +24,10 @@ module.exports = {
required: true, required: true,
encrypt: true encrypt: true
}, // 密碼, }, // 密碼,
// role: { role: {
// type: 'number', type: 'number',
// defaultsTo: 999 defaultsTo: 999
// }, // 權限,0: 系統管理員、999:一般使用者 }, // 權限,0: 系統管理員、999:一般使用者
status: { status: {
type: 'number', type: 'number',
defaultsTo: 1 defaultsTo: 1
......
...@@ -11,5 +11,5 @@ ...@@ -11,5 +11,5 @@
module.exports.routes = { module.exports.routes = {
'POST /user/login': 'user/login', 'POST /user/login': 'user/login',
'POST /app/auth': 'app/auth', '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