diff options
author | gumi <git@gumi.ca> | 2020-03-15 21:56:57 -0400 |
---|---|---|
committer | gumi <git@gumi.ca> | 2020-03-15 21:56:57 -0400 |
commit | 8a1302edf0506c92bd9a8e83ed7c1e145b246513 (patch) | |
tree | fae4703cb17a829b102c60550acb7cdea0878685 /src/routers/vault/middlewares/account.js | |
parent | a0a35766911f5354487663b0f148b824ca32ba44 (diff) | |
download | api-8a1302edf0506c92bd9a8e83ed7c1e145b246513.tar.gz api-8a1302edf0506c92bd9a8e83ed7c1e145b246513.tar.bz2 api-8a1302edf0506c92bd9a8e83ed7c1e145b246513.tar.xz api-8a1302edf0506c92bd9a8e83ed7c1e145b246513.zip |
add an Identity type
Diffstat (limited to 'src/routers/vault/middlewares/account.js')
-rw-r--r-- | src/routers/vault/middlewares/account.js | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/src/routers/vault/middlewares/account.js b/src/routers/vault/middlewares/account.js index 3c1cf52..5a5fa85 100644 --- a/src/routers/vault/middlewares/account.js +++ b/src/routers/vault/middlewares/account.js @@ -1,11 +1,9 @@ "use strict"; const validate = require("../utils/validate.js"); - -const regexes = { - token: /^[a-zA-Z0-9-_]{6,128}$/, // UUID -}; +const Session = require("../types/Session.js"); const get_data = async (req, res, next) => { + /** @type {Session} */ let session; try { @@ -14,14 +12,7 @@ const get_data = async (req, res, next) => { res.status(200).json({ status: "success", - data: { - // TODO: make this a method of Session - primaryIdentity: session.primaryIdentity, - allowNonPrimary: session.allowNonPrimary, - strictIPCheck: session.strictIPCheck, - requireSecret: true, - vaultId: session.vault, - }, + data: session.getAccountData(), }); req.app.locals.cooldown(req, 1e3); }; @@ -35,19 +26,20 @@ const update_account = async (req, res, next) => { const data = { primary: +validate.get_prop(req, "primary"), - allow: !!validate.get_prop(req, "allow"), - strict: !!validate.get_prop(req, "strict"), + allow: validate.get_prop(req, "allow") === "true", + strict: validate.get_prop(req, "strict") === "true", }; const update_fields = {}; - if (session.primaryIdentity !== data.primary) { + if (session.primaryIdentity.id !== data.primary) { // update primary identity let new_primary = null; for (const ident of session.identities) { if (ident.id === data.primary) { new_primary = ident.id; + session.primaryIdentity = ident; break; } } @@ -81,13 +73,13 @@ const update_account = async (req, res, next) => { // now update our cache session.allowNonPrimary = data.allow; session.strictIPCheck = data.strict; - session.primaryIdentity = data.primary; for (const ident of session.identities) { - if (ident.id === session.primaryIdentity) { - ident.primary = true; - } else if (ident.primary === true) { - ident.primary = false; + if (ident.id === session.primaryIdentity.id) { + ident.isPrimary = true; + session.primaryIdentity = ident; + } else if (ident.isPrimary === true) { + ident.isPrimary = false; } } |