merge userdb.js into users.js
This commit is contained in:
+22
-27
@@ -6,7 +6,7 @@ exports = module.exports = {
|
||||
update,
|
||||
getAvatar,
|
||||
setAvatar,
|
||||
changePassword,
|
||||
setPassword,
|
||||
setTwoFactorAuthenticationSecret,
|
||||
enableTwoFactorAuthentication,
|
||||
disableTwoFactorAuthentication,
|
||||
@@ -55,7 +55,7 @@ async function get(req, res, next) {
|
||||
}));
|
||||
}
|
||||
|
||||
function update(req, res, next) {
|
||||
async function update(req, res, next) {
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
|
||||
@@ -63,13 +63,12 @@ function update(req, res, next) {
|
||||
if ('fallbackEmail' in req.body && typeof req.body.fallbackEmail !== 'string') return next(new HttpError(400, 'fallbackEmail must be string'));
|
||||
if ('displayName' in req.body && typeof req.body.displayName !== 'string') return next(new HttpError(400, 'displayName must be string'));
|
||||
|
||||
var data = _.pick(req.body, 'email', 'fallbackEmail', 'displayName');
|
||||
const data = _.pick(req.body, 'email', 'fallbackEmail', 'displayName');
|
||||
|
||||
users.update(req.user, data, auditSource.fromRequest(req), function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error] = await safe(users.update(req.user, data, auditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(204));
|
||||
});
|
||||
next(new HttpSuccess(204));
|
||||
}
|
||||
|
||||
async function setAvatar(req, res, next) {
|
||||
@@ -99,48 +98,44 @@ async function getAvatar(req, res, next) {
|
||||
res.send(avatar);
|
||||
}
|
||||
|
||||
function changePassword(req, res, next) {
|
||||
async function setPassword(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
if (typeof req.body.newPassword !== 'string') return next(new HttpError(400, 'newPassword must be a string'));
|
||||
|
||||
users.setPassword(req.user, req.body.newPassword, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error] = await safe(users.setPassword(req.user, req.body.newPassword, auditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(204));
|
||||
});
|
||||
next(new HttpSuccess(204));
|
||||
}
|
||||
|
||||
function setTwoFactorAuthenticationSecret(req, res, next) {
|
||||
async function setTwoFactorAuthenticationSecret(req, res, next) {
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
users.setTwoFactorAuthenticationSecret(req.user.id, function (error, result) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error, result] = await safe(users.setTwoFactorAuthenticationSecret(req.user.id, auditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(201, { secret: result.secret, qrcode: result.qrcode }));
|
||||
});
|
||||
next(new HttpSuccess(201, { secret: result.secret, qrcode: result.qrcode }));
|
||||
}
|
||||
|
||||
function enableTwoFactorAuthentication(req, res, next) {
|
||||
async function enableTwoFactorAuthentication(req, res, next) {
|
||||
assert.strictEqual(typeof req.body, 'object');
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
if (!req.body.totpToken || typeof req.body.totpToken !== 'string') return next(new HttpError(400, 'totpToken must be a nonempty string'));
|
||||
|
||||
users.enableTwoFactorAuthentication(req.user.id, req.body.totpToken, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error] = await safe(users.enableTwoFactorAuthentication(req.user.id, req.body.totpToken, auditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202, {}));
|
||||
});
|
||||
next(new HttpSuccess(202, {}));
|
||||
}
|
||||
|
||||
function disableTwoFactorAuthentication(req, res, next) {
|
||||
async function disableTwoFactorAuthentication(req, res, next) {
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
users.disableTwoFactorAuthentication(req.user.id, function (error) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
const [error] = await safe(users.disableTwoFactorAuthentication(req.user.id, auditSource.fromRequest(req)));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202, {}));
|
||||
});
|
||||
next(new HttpSuccess(202, {}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user