update api errormanager
This commit is contained in:
@@ -28,18 +28,25 @@ router.use(async(c, n) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
await n();
|
||||
try {
|
||||
await n();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
if ('db' in c && typeof c.db == 'object' && 'release' in c.db && typeof c.db.release == 'function') c.db.release();
|
||||
switch (typeof c.body) {
|
||||
case 'undefined':
|
||||
c.body = { errorCode: 'ERR9999', status: 0 };
|
||||
break;
|
||||
case 'string':
|
||||
c.body = { errorCode: c.body, status: 0 };
|
||||
break;
|
||||
default:
|
||||
c.body = {
|
||||
data: c.body,
|
||||
status: 1
|
||||
}
|
||||
break;
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -9,15 +9,15 @@ const mongo = require('../../libs/mongo_model.js');
|
||||
router
|
||||
.post('/login', async(c, n) => {
|
||||
let arr = c.request.body;
|
||||
if (!arr.data) return c.body = 'ERR0000';
|
||||
if (!arr.data.account) return c.body = 'ERR0001';
|
||||
if (!arr.data.password) return c.body = 'ERR0002';
|
||||
if (!arr.data) throw 'C_EDATA';
|
||||
if (!arr.data.account) throw 'C_EACCOUNT';
|
||||
if (!arr.data.password) throw 'C_EPASSWORD';
|
||||
try {
|
||||
let user = await c.syncQuery('select `uid`,`account`,`password`,`name`,`email` from ??.?? where `account` = ?', ['lora', 'user', arr.data.account])
|
||||
|
||||
if (user.length == 0) return c.body = 'user not exists';
|
||||
if (user.length == 0) throw 'user not exists';
|
||||
|
||||
if (!crypto.comparePass(arr.data.password, user[0].password)) return c.body = 'password not match';
|
||||
if (!crypto.comparePass(arr.data.password, user[0].password)) throw 'password not match';
|
||||
|
||||
delete user[0].password;
|
||||
|
||||
@@ -25,11 +25,11 @@ router
|
||||
record: user
|
||||
}
|
||||
} catch (err) {
|
||||
return c.body = 'DB Query Error';
|
||||
throw 'DB Query Error';
|
||||
}
|
||||
|
||||
let u = c.body.record[0];
|
||||
let token = new mongo.token({ object: u, expire: Date.now() });
|
||||
let token = new mongo.token({ object: u, expire: Date.now() + 86400000 });
|
||||
token.save();
|
||||
c.body.rt = {
|
||||
token: {
|
||||
|
||||
Reference in New Issue
Block a user