1
0
Fork 0
mirror of synced 2024-06-26 18:10:51 +12:00

all http endpoints completed (not tested)

This commit is contained in:
michael shanks 2019-06-16 22:17:22 +01:00
parent 89d774bbea
commit d207d442bb
4 changed files with 53 additions and 5 deletions

@ -1 +1 @@
Subproject commit 8d3f13b1b741fa4a8d83fae61460b9535fa7ee89
Subproject commit c255f52c811f02d77797c10f8ed1993a6bcc883c

File diff suppressed because one or more lines are too long

View file

@ -35,10 +35,27 @@ module.exports = (config, app) => {
ctx.response.status = StatusCodes.OK;
})
.post("/:appname/api/setPasswordFromTemporaryCode", async (ctx) => {
const instanceApi = await ctx.master.getFullAccessInstanceApiForUsername(
ctx.params.appname,
ctx.request.body.username
);
await instanceApi.authApi.setPasswordFromTemporaryCode(
ctx.request.body.tempCode,
ctx.request.body.newpassword);
ctx.response.status = StatusCodes.OK;
})
.post("/:appname/api/createTemporaryAccess", async (ctx) => {
const instanceApi = await ctx.master.getFullAccessInstanceApiForUsername(
ctx.params.appname,
ctx.request.body.username
);
await instanceApi.authApi.createTemporaryAccess(
ctx.request.body.username);
ctx.response.status = StatusCodes.OK;
})
.use(async (ctx, next) => {

View file

@ -123,14 +123,45 @@ module.exports = async (config) => {
const instanceDatastore = getInstanceDatastore(session.instanceDatastoreConfig)
return await getApisForSession(instanceDatastore, session);
}
}
};
const getFullAccessInstanceApiForUsername = async (appname, username) => {
if(isMaster(appname)) {
const user = bb.authApi.getUsers()
.find(u => u.name === username);
if(!user) return;
if(!user.enabled) return;
return user;
}
else {
const app = await getApplication(appname);
const matches = bb.indexApi.listItems(
`/applications/${app.id}/user_name_lookup`,
{
rangeStartParams:{name:username},
rangeEndParams:{name:username},
searchPhrase:`name:${username}`
}
);
if(matches.length !== 1) return;
const instanceDatastore = getInstanceDatastore(
matches[0].instanceDatastoreConfig);
return await getApisWithFullAccess(instanceDatastore);
}
};
return ({
getApplication,
getSession,
deleteSession,
authenticate,
getInstanceApiForSession
getInstanceApiForSession,
getFullAccessInstanceApiForUsername,
createTemporaryAccessCode
});
}