This commit is contained in:
2019-11-13 20:17:51 +08:00
parent 92d82c08dd
commit f3f53e2519
3 changed files with 68 additions and 60 deletions

View File

@@ -1,22 +1,26 @@
var loginup = async (ctx,next) => {
let arr;
//查询数据库 没有用户默认admin 123456
console.time("asd")
await dbs.find('admin').then((res)=>{
arr = res.data
})
console.timeEnd("asd")
if(arr.length == 0){
await dbs.add('admin',{name:"admin",pwd:"123456"})
await dbs.find('admin').then((res)=>{
arr = res.data
})
}
//判断用户名密码
if(ctx.request.body.name == arr[0].name && ctx.request.body.pwd == arr[0].pwd){
//颁发token
const token = jwt.sign({
name: ctx.request.body.name,
_id: 1
id: arr[0]._id
}, 'my_token', { expiresIn: '2h' });
ctx.body={code:0,token}
}else{