|
@ -35,6 +35,9 @@ class UserAdminController extends SiteController { |
|
|
const { user: userService } = this.dtp.services; |
|
|
const { user: userService } = this.dtp.services; |
|
|
try { |
|
|
try { |
|
|
res.locals.userAccount = await userService.getLocalUserAccount(localUserId); |
|
|
res.locals.userAccount = await userService.getLocalUserAccount(localUserId); |
|
|
|
|
|
if (!res.locals.userAccount) { |
|
|
|
|
|
throw new SiteError(404, 'User not found'); |
|
|
|
|
|
} |
|
|
return next(); |
|
|
return next(); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
return next(error); |
|
|
return next(error); |
|
@ -42,9 +45,43 @@ class UserAdminController extends SiteController { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async postUpdateLocalUser (req, res, next) { |
|
|
async postUpdateLocalUser (req, res, next) { |
|
|
const { user: userService } = this.dtp.services; |
|
|
const { |
|
|
|
|
|
logan: loganService, |
|
|
|
|
|
user: userService, |
|
|
|
|
|
} = this.dtp.services; |
|
|
try { |
|
|
try { |
|
|
await userService.updateLocalForAdmin(res.locals.userAccount, req.body); |
|
|
this.log.debug('local user update', { action: req.body.action }); |
|
|
|
|
|
switch (req.body.action) { |
|
|
|
|
|
case 'update': |
|
|
|
|
|
await userService.updateLocalForAdmin(res.locals.userAccount, req.body); |
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, { |
|
|
|
|
|
level: 'info', |
|
|
|
|
|
event: 'postUpdateLocalUser', |
|
|
|
|
|
message: 'local user account updated', |
|
|
|
|
|
data: { |
|
|
|
|
|
userAccount: { |
|
|
|
|
|
_id: res.locals.userAccount._id, |
|
|
|
|
|
username: res.locals.userAccount.username, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'ban': |
|
|
|
|
|
await userService.ban(res.locals.userAccount); |
|
|
|
|
|
loganService.sendRequestEvent(module.exports, req, { |
|
|
|
|
|
level: 'info', |
|
|
|
|
|
event: 'postUpdateLocalUser', |
|
|
|
|
|
message: 'local user banned from the app', |
|
|
|
|
|
data: { |
|
|
|
|
|
userAccount: { |
|
|
|
|
|
_id: res.locals.userAccount._id, |
|
|
|
|
|
username: res.locals.userAccount.username, |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
res.redirect('/admin/user'); |
|
|
res.redirect('/admin/user'); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
return next(error); |
|
|
return next(error); |
|
|