-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fbe2af0
commit 7d995e2
Showing
28 changed files
with
683 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = app => class extends app.Controller { | ||
async all(ctx){ | ||
ctx.body = this.service.ret.success(await ctx.model.Role.find()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = app => { | ||
const mongoose = app.mongoose | ||
const Schema = mongoose.Schema | ||
|
||
var RoleSchema = new Schema({ | ||
name: { | ||
type: String, | ||
unique: true, | ||
}, | ||
// 业务后管系统使用的字段,可以不填 | ||
key: String, | ||
description: String, | ||
isAdmin: Boolean, | ||
menus: [{ | ||
type: Schema.Types.ObjectId, | ||
ref: 'Menu', | ||
}] | ||
}, { | ||
timestamps: true, | ||
}) | ||
|
||
return mongoose.model('Role', RoleSchema) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,44 @@ | ||
const compose = require('koa-compose') | ||
|
||
module.exports = app=>{ | ||
const { router, middleware, controller } = app | ||
let jwtQuiet = middleware.jwt('user', true) | ||
let jwt = middleware.jwt('user') | ||
let jwt = compose([middleware.jwt('user'), async (ctx, next)=>{ | ||
// 验证用户信息 | ||
await next() | ||
}]) | ||
|
||
let jwtAdminRoleCheck = compose([jwt, async (ctx, next)=>{ | ||
let user = ctx.state.user | ||
if(user.role?.isAdmin){ | ||
await next() | ||
}else{ | ||
throw new app.ServiceError(100, '无权限') | ||
} | ||
}]) | ||
|
||
router.post('/api/user/registerAdmin', controller.user.registerAdmin) | ||
router.post('/api/user/isAdminRegistered', controller.user.isAdminRegistered) | ||
router.post('/api/user/login', controller.user.login) | ||
router.post('/api/user/decode', controller.user.decode) | ||
router.post('/api/user/myInfo', jwt, controller.user.myInfo) | ||
router.post('/api/user/decode', jwt, controller.user.decode) | ||
router.post('/api/user/pageData', jwt, controller.user.pageData) | ||
router.post('/api/user/getChangingPasswordToken', jwt, controller.user.getChangingPasswordToken) | ||
router.post('/api/user/changePasswordByToken', jwt, controller.user.changePasswordByToken) | ||
router.post('/api/user/pageData', jwtAdminRoleCheck, controller.user.pageData) | ||
router.post('/api/user/save', jwtAdminRoleCheck, controller.user.save) | ||
router.post('/api/user/delete', jwtAdminRoleCheck, controller.user.delete) | ||
router.post('/api/user/changePassword', jwtAdminRoleCheck, controller.user.changePassword) | ||
|
||
router.post('/api/menu/pageData', jwt, controller.menu.pageData) | ||
router.post('/api/menu/save', jwt, controller.menu.save) | ||
router.post('/api/menu/delete', jwt, controller.menu.delete) | ||
router.post('/api/menu/resetOrders', jwt, controller.menu.resetOrders) | ||
router.post('/api/menu/save', jwtAdminRoleCheck, controller.menu.save) | ||
router.post('/api/menu/delete', jwtAdminRoleCheck, controller.menu.delete) | ||
router.post('/api/menu/resetOrders', jwtAdminRoleCheck, controller.menu.resetOrders) | ||
|
||
router.post('/api/role/all', jwt, controller.role.all) | ||
|
||
router.post('/api/admin/save', jwt, controller.admin.save) | ||
router.post('/api/admin/get', jwt, controller.admin.get) | ||
router.post('/api/admin/pageData', jwt, controller.admin.pageData) | ||
router.post('/api/admin/delete', jwt, controller.admin.delete) | ||
router.post('/api/admin/login', controller.user.login) | ||
router.post('/api/admin/save', jwtAdminRoleCheck, controller.admin.save) | ||
router.post('/api/admin/get', jwtAdminRoleCheck, controller.admin.get) | ||
router.post('/api/admin/pageData', jwtAdminRoleCheck, controller.admin.pageData) | ||
router.post('/api/admin/delete', jwtAdminRoleCheck, controller.admin.delete) | ||
// router.post('/api/admin/login', controller.user.login) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.