fallbackEmail is now independent from email

This commit is contained in:
Johannes Zellner
2021-10-26 22:50:02 +02:00
parent 2f510c2625
commit daf212468f
5 changed files with 40 additions and 7 deletions

View File

@@ -43,6 +43,7 @@ async function add(req, res, next) {
if (typeof req.body.email !== 'string') return next(new HttpError(400, 'email must be string'));
if ('username' in req.body && typeof req.body.username !== 'string') return next(new HttpError(400, 'username must be string'));
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'));
if ('password' in req.body && typeof req.body.password !== 'string') return next(new HttpError(400, 'password must be string'));
if ('role' in req.body) {
@@ -54,8 +55,9 @@ async function add(req, res, next) {
const email = req.body.email;
const username = 'username' in req.body ? req.body.username : null;
const displayName = req.body.displayName || '';
const fallbackEmail = req.body.fallbackEmail || '';
const [error, id] = await safe(users.add(email, { username, password, displayName, invitor: req.user, role: req.body.role || users.ROLE_USER }, AuditSource.fromRequest(req)));
const [error, id] = await safe(users.add(email, { username, password, displayName, fallbackEmail, invitor: req.user, role: req.body.role || users.ROLE_USER }, AuditSource.fromRequest(req)));
if (error) return next(BoxError.toHttpError(error));
next(new HttpSuccess(201, { id }));