接入cookie操作;jwt改为手动触发验证

v1
宇天 2020-09-21 19:24:02 +08:00
parent 2faa23a12a
commit 76d205a1c4
2 changed files with 27 additions and 5 deletions

View File

@ -17,16 +17,12 @@ export default class Controller {
jwt.expires = ctx.get('session').ttl jwt.expires = ctx.get('session').ttl
jwt.secret = ctx.get('jwt') jwt.secret = ctx.get('jwt')
this.jwt = { this.jwt = { sign: jwt.sign }
sign: jwt.sign,
result: jwt.verify(req.header('authorized'))
}
// smarty.config('path', this.ctx.get('VIEWS')) // smarty.config('path', this.ctx.get('VIEWS'))
// smarty.config('ext', this.ctx.get('temp_ext')) // smarty.config('ext', this.ctx.get('temp_ext'))
// smarty.config('cache', !!this.ctx.get('temp_cache')) // smarty.config('cache', !!this.ctx.get('temp_cache'))
this.cookie = ctx.ins('cookie')
// this.session = this.ctx.ins('session') // this.session = this.ctx.ins('session')
} }
@ -56,6 +52,29 @@ export default class Controller {
// }) // })
// } // }
checkAuth() {
this.jwt.result = jwt.verify(this.request.header('authorized'))
}
// cookie读写
cookie(key, val, opt) {
if (arguments.length < 2) {
return this.request.cookie(key)
}
if (!opt) {
opt = {}
}
opt.domain = opt.domain || this.context.get('domain')
if (val === null || val === undefined) {
delete opt.expires
opt.maxAge = -1
}
this.response.cookie(key, val, opt)
}
// RESFULL-API规范的纯API返回 // RESFULL-API规范的纯API返回
send(status = 200, msg = 'success', data = {}) { send(status = 200, msg = 'success', data = {}) {
if (typeof msg === 'object') { if (typeof msg === 'object') {

View File

@ -4,6 +4,9 @@
"type": "module", "type": "module",
"description": "控制器基类。", "description": "控制器基类。",
"main": "index.js", "main": "index.js",
"dependencies": {
"@gm5/jwt": "^1.0.0"
},
"author": "yutent", "author": "yutent",
"keywords": ["fivejs", "controller", "http"], "keywords": ["fivejs", "controller", "http"],
"repository": "https://github.com/bytedo/gmf.controller.git", "repository": "https://github.com/bytedo/gmf.controller.git",