Add two distinct password reset routes
This commit is contained in:
@@ -13,6 +13,9 @@ exports = module.exports = {
|
||||
setGhost,
|
||||
makeOwner,
|
||||
|
||||
getPasswordResetLink,
|
||||
sendPasswordResetEmail,
|
||||
|
||||
disableTwoFactorAuthentication,
|
||||
|
||||
load
|
||||
@@ -216,3 +219,24 @@ async function makeOwner(req, res, next) {
|
||||
|
||||
next(new HttpSuccess(204));
|
||||
}
|
||||
|
||||
// This will always return a reset link, if none is set or expired a new one will be created
|
||||
async function getPasswordResetLink(req, res, next) {
|
||||
assert.strictEqual(typeof req.resource, 'object');
|
||||
|
||||
let [error, passwordResetLink] = await safe(users.getPasswordResetLink(req.resource, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, { passwordResetLink }));
|
||||
}
|
||||
|
||||
async function sendPasswordResetEmail(req, res, next) {
|
||||
assert.strictEqual(typeof req.resource, 'object');
|
||||
|
||||
if (!req.body.email || typeof req.body.email !== 'string') return next(new HttpError(400, 'email must be a non-empty string'));
|
||||
|
||||
let [error] = await safe(users.sendPasswordResetEmail(req.resource, req.body.email, AuditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202, {}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user