update local user admin

master
rob 1 year ago
parent 4a62a37962
commit af5b8aa5cf

@ -22,37 +22,36 @@ class UserController extends SiteController {
return next();
});
router.param('userId', this.populateUserId.bind(this));
router.param('localUserId', this.populateLocalUserId.bind(this));
router.post('/local/:localUserId', this.postUpdateLocalUser.bind(this));
router.get('/local/:localUserId', this.getLocalUserView.bind(this));
router.post('/:userId', this.postUpdateUser.bind(this));
router.get('/:userId', this.getUserView.bind(this));
router.get('/', this.getHomeView.bind(this));
return router;
}
async populateUserId (req, res, next, userId) {
async populateLocalUserId (req, res, next, localUserId) {
const { user: userService } = this.dtp.services;
try {
res.locals.userAccount = await userService.getUserAccount(userId);
res.locals.userAccount = await userService.getLocalUserAccount(localUserId);
return next();
} catch (error) {
return next(error);
}
}
async postUpdateUser (req, res, next) {
async postUpdateLocalUser (req, res, next) {
const { user: userService } = this.dtp.services;
try {
await userService.updateForAdmin(res.locals.userAccount, req.body);
await userService.updateLocalForAdmin(res.locals.userAccount, req.body);
res.redirect('/admin/user');
} catch (error) {
return next(error);
}
}
async getUserView (req, res, next) {
async getLocalUserView (req, res, next) {
const { comment: commentService } = this.dtp.services;
try {
res.locals.pagination = this.getPaginationParameters(req, 20);

@ -225,7 +225,7 @@ class UserService extends SiteService {
);
}
async updateForAdmin (user, userDefinition) {
async updateLocalForAdmin (user, userDefinition) {
userDefinition.username = striptags(userDefinition.username.trim().replace(/[^A-Za-z0-9\-_]/gi, ''));
const username_lc = userDefinition.username.toLowerCase();

@ -5,7 +5,7 @@ block content
div(uk-grid).uk-grid-small
div(class="uk-width-1-1 uk-width-2-3@l")
form(method="POST", action=`/admin/user/${userAccount._id}`).uk-form
form(method="POST", action=`/admin/user/local/${userAccount._id}`).uk-form
input(type="hidden", name="username", value= userAccount.username)
input(type="hidden", name="displayName", value= userAccount.displayName)
.uk-card.uk-card-default.uk-card-small

@ -22,10 +22,10 @@ block content
each userAccount in userAccounts
tr
td
a(href=`/admin/user/${userAccount._id}`)= userAccount.username
a(href=`/admin/user/local/${userAccount._id}`)= userAccount.username
td
if userAccount.displayName
a(href=`/admin/user/${userAccount._id}`)= userAccount.displayName
a(href=`/admin/user/local/${userAccount._id}`)= userAccount.displayName
else
.uk-text-muted N/A
td= moment(userAccount.created).format('YYYY-MM-DD hh:mm a')

Loading…
Cancel
Save