From af5b8aa5cfbb011fe900839e2ecabeb480ac12f9 Mon Sep 17 00:00:00 2001 From: rob Date: Tue, 23 May 2023 00:03:16 -0400 Subject: [PATCH] update local user admin --- app/controllers/admin/user.js | 17 ++++++++--------- app/services/user.js | 2 +- app/views/admin/user/form.pug | 2 +- app/views/admin/user/index.pug | 4 ++-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/controllers/admin/user.js b/app/controllers/admin/user.js index eb471d4..fc1fd9d 100644 --- a/app/controllers/admin/user.js +++ b/app/controllers/admin/user.js @@ -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); diff --git a/app/services/user.js b/app/services/user.js index 9c4e63d..81a96fb 100644 --- a/app/services/user.js +++ b/app/services/user.js @@ -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(); diff --git a/app/views/admin/user/form.pug b/app/views/admin/user/form.pug index 83b7b9a..279bc32 100644 --- a/app/views/admin/user/form.pug +++ b/app/views/admin/user/form.pug @@ -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 diff --git a/app/views/admin/user/index.pug b/app/views/admin/user/index.pug index 096bd13..66c17c2 100644 --- a/app/views/admin/user/index.pug +++ b/app/views/admin/user/index.pug @@ -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')