Add set ghost route

This commit is contained in:
Johannes Zellner
2021-09-17 12:52:41 +02:00
parent 8fde4e959c
commit f75b0ebff9
3 changed files with 34 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ exports = module.exports = {
verifyPassword,
sendInvite,
setGroups,
setGhost,
makeOwner,
disableTwoFactorAuthentication,
@@ -174,6 +175,19 @@ async function setGroups(req, res, next) {
next(new HttpSuccess(204));
}
async function setGhost(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
assert.strictEqual(typeof req.resource, 'object');
if (typeof req.body.password !== 'string' || !req.body.password) return next(new HttpError(400, 'password must be non-empty string'));
if ('expiresAt' in req.body && typeof req.body.password !== 'number') return next(new HttpError(400, 'expiresAt must be a number'));
const [error] = await safe(users.setGhost(req.resource, req.body.password, req.body.expiresAt || null));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(204));
}
async function setPassword(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
assert.strictEqual(typeof req.resource, 'object');