all http endpoints completed (not tested)
This commit is contained in:
parent
89d774bbea
commit
d207d442bb
|
@ -1 +1 @@
|
|||
Subproject commit 8d3f13b1b741fa4a8d83fae61460b9535fa7ee89
|
||||
Subproject commit c255f52c811f02d77797c10f8ed1993a6bcc883c
|
File diff suppressed because one or more lines are too long
|
@ -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) => {
|
||||
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
||||
}
|
Loading…
Reference in New Issue