diff --git a/nodejs/models/token.js b/nodejs/models/token.js index e679686..07e17ec 100644 --- a/nodejs/models/token.js +++ b/nodejs/models/token.js @@ -95,7 +95,7 @@ class OtpToken extends Token { } static async issue(uid, method) { - const existing = await this.find({uid}); + const existing = await this.list({where: {uid}}); for (const t of existing) { if (t.is_valid) await t.update({is_valid: false}); } @@ -104,7 +104,7 @@ class OtpToken extends Token { } static async verify(uid, code) { - const tokens = await this.listDetail({uid}); + const tokens = await this.list({where: {uid}}); const match = tokens.find(t => t.is_valid && !t.isExpired && t.code === code); if (!match) return null; await match.update({is_valid: false}); diff --git a/nodejs/routes/auth.js b/nodejs/routes/auth.js index 9e3cbfd..ab39db9 100755 --- a/nodejs/routes/auth.js +++ b/nodejs/routes/auth.js @@ -203,7 +203,7 @@ router.post('/impersonate/:uid', middleware.auth, async function(req, res, next) const target = await User.get(req.params.uid); // Clean up any existing impersonation for this target - const existing = await ImpersonationToken.listDetail({ target_uid: target.uid }); + const existing = await ImpersonationToken.list({where: { target_uid: target.uid }}); for (const old of existing) { if (old.is_valid && !old.isExpired) { try { await target.removeTempPassword(old.temp_hash); } catch(_) {} @@ -237,7 +237,7 @@ router.delete('/impersonate/:uid', middleware.auth, async function(req, res, nex await permission.byGroup(req.user, ['app_sso_admin']); const target = await User.get(req.params.uid); - const existing = await ImpersonationToken.listDetail({ target_uid: target.uid }); + const existing = await ImpersonationToken.list({where: { target_uid: target.uid }}); let revoked = 0; for (const token of existing) { diff --git a/nodejs/routes/token.js b/nodejs/routes/token.js index 39e02d9..d46971a 100644 --- a/nodejs/routes/token.js +++ b/nodejs/routes/token.js @@ -24,7 +24,7 @@ router.get('/', async function(req, res, next){ router.get('/:name', async function(req, res, next){ try{ return res.json({ - results: await tokens[req.params.name][req.query.detail ? "listDetail" : "list"]() + results: await tokens[req.params.name].list({detail: !!req.query.detail}) }); }catch(error){ next(error);