changed _id to username for profile access #2

Merged
Ghost merged 1 commits from userURLPatch into develop 2 years ago
  1. 6
      app/controllers/user.js
  2. 8
      app/views/components/library.pug
  3. 2
      app/views/components/navbar.pug
  4. 2
      app/views/components/off-canvas.pug

6
app/controllers/user.js

@ -33,12 +33,12 @@ class UserController extends SiteController {
const otpSetup = otpAuthService.middleware('Account', { const otpSetup = otpAuthService.middleware('Account', {
adminRequired: false, adminRequired: false,
otpRequired: true, otpRequired: true,
otpRedirectURL: async (req) => { return `/user/${req.user._id}`; }, otpRedirectURL: async (req) => { return `/user/${req.user.username}`; },
}); });
const otpMiddleware = otpAuthService.middleware('Account', { const otpMiddleware = otpAuthService.middleware('Account', {
adminRequired: false, adminRequired: false,
otpRequired: false, otpRequired: false,
otpRedirectURL: async (req) => { return `/user/${req.user._id}`; }, otpRedirectURL: async (req) => { return `/user/${req.user.username}`; },
}); });
router.use( router.use(
@ -203,7 +203,7 @@ class UserController extends SiteController {
if (error) { if (error) {
return next(error); return next(error);
} }
res.redirect(`/user/${res.locals.user._id}`); res.redirect(`/user/${res.locals.user.username}`);
}); });
} catch (error) { } catch (error) {
this.log.error('failed to create new user', { error }); this.log.error('failed to create new user', { error });

8
app/views/components/library.pug

@ -40,9 +40,9 @@ include section-title
function getUserProfileUrl (user) { function getUserProfileUrl (user) {
if (user.core) { if (user.core) {
return `/user/core/${user._id}`; return `/user/core/${user.username}`;
} }
return `/user/${user._id}`; return `/user/${user.username}`;
} }
mixin renderCell (label, value, className) mixin renderCell (label, value, className)
@ -60,6 +60,6 @@ mixin renderBackButton (options)
mixin renderUserLink (user) mixin renderUserLink (user)
if user.coreUserId if user.coreUserId
a(href=`/user/core/${user._id}`)= `${user.username}@${user.core.meta.domainKey}` a(href=`/user/core/${user.username}`)= `${user.username}@${user.core.meta.domainKey}`
else else
a(href=`/user/${user._id}`)= user.displayName || user.username a(href=`/user/${user.username}`)= user.displayName || user.username

2
app/views/components/navbar.pug

@ -47,7 +47,7 @@ nav(uk-navbar).uk-navbar-container.uk-position-fixed.uk-position-top
li.uk-nav-heading.uk-text-center= user.displayName || user.username li.uk-nav-heading.uk-text-center= user.displayName || user.username
li.uk-nav-divider li.uk-nav-divider
li li
a(href= user.core ? `/user/core/${user._id}` : `/user/${user._id}`) a(href= user.core ? `/user/core/${user.username}` : `/user/${user.username}`)
span.nav-item-icon span.nav-item-icon
i.fas.fa-user i.fas.fa-user
span Profile span Profile

2
app/views/components/off-canvas.pug

@ -40,7 +40,7 @@ mixin renderMenuItem (iconClass, label)
.uk-width-expand Chat .uk-width-expand Chat
li(class={ "uk-active": (currentView === 'user-settings') }) li(class={ "uk-active": (currentView === 'user-settings') })
a(href=`/user/${user._id}`).uk-display-block a(href=`/user/${user.username}`).uk-display-block
div(uk-grid).uk-grid-collapse div(uk-grid).uk-grid-collapse
.uk-width-auto .uk-width-auto
.app-menu-icon .app-menu-icon

Loading…
Cancel
Save