|
|
@ -33,12 +33,12 @@ class UserController extends SiteController { |
|
|
|
const otpSetup = otpAuthService.middleware('Account', { |
|
|
|
adminRequired: false, |
|
|
|
otpRequired: true, |
|
|
|
otpRedirectURL: async (req) => { return `/user/${req.user._id}`; }, |
|
|
|
otpRedirectURL: async (req) => { return `/user/${req.user.username}`; }, |
|
|
|
}); |
|
|
|
const otpMiddleware = otpAuthService.middleware('Account', { |
|
|
|
adminRequired: false, |
|
|
|
otpRequired: false, |
|
|
|
otpRedirectURL: async (req) => { return `/user/${req.user._id}`; }, |
|
|
|
otpRedirectURL: async (req) => { return `/user/${req.user.username}`; }, |
|
|
|
}); |
|
|
|
|
|
|
|
router.use( |
|
|
@ -60,8 +60,9 @@ class UserController extends SiteController { |
|
|
|
return next(); |
|
|
|
} |
|
|
|
|
|
|
|
router.param('userId', this.populateUser.bind(this)); |
|
|
|
router.param('coreUserId', this.populateCoreUser.bind(this)); |
|
|
|
router.param('username', this.populateUsername.bind(this)); |
|
|
|
router.param('userId', this.populateUserId.bind(this)); |
|
|
|
router.param('coreUserId', this.populateCoreUserId.bind(this)); |
|
|
|
|
|
|
|
router.post( |
|
|
|
'/core/:coreUserId/settings', |
|
|
@ -131,7 +132,7 @@ class UserController extends SiteController { |
|
|
|
this.getUserSettingsView.bind(this), |
|
|
|
); |
|
|
|
router.get( |
|
|
|
'/:userId', |
|
|
|
'/:username', |
|
|
|
limiterService.createMiddleware(limiterService.config.user.getUserProfile), |
|
|
|
authRequired, |
|
|
|
otpMiddleware, |
|
|
@ -147,7 +148,21 @@ class UserController extends SiteController { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
async populateUser (req, res, next, userId) { |
|
|
|
async populateUsername (req, res, next, username) { |
|
|
|
const { user: userService } = this.dtp.services; |
|
|
|
try { |
|
|
|
res.locals.userProfile = await userService.getPublicProfile('User', username); |
|
|
|
if (!res.locals.userProfile) { |
|
|
|
throw new SiteError(404, 'Member not found'); |
|
|
|
} |
|
|
|
return next(); |
|
|
|
} catch (error) { |
|
|
|
this.log.error('failed to populate username with public profile', { username, error }); |
|
|
|
return next(error); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async populateUserId (req, res, next, userId) { |
|
|
|
const { user: userService } = this.dtp.services; |
|
|
|
try { |
|
|
|
userId = mongoose.Types.ObjectId(userId); |
|
|
@ -163,7 +178,7 @@ class UserController extends SiteController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async populateCoreUser (req, res, next, coreUserId) { |
|
|
|
async populateCoreUserId (req, res, next, coreUserId) { |
|
|
|
const { coreNode: coreNodeService } = this.dtp.services; |
|
|
|
try { |
|
|
|
coreUserId = mongoose.Types.ObjectId(coreUserId); |
|
|
@ -203,7 +218,7 @@ class UserController extends SiteController { |
|
|
|
if (error) { |
|
|
|
return next(error); |
|
|
|
} |
|
|
|
res.redirect(`/user/${res.locals.user._id}`); |
|
|
|
res.redirect(`/user/${res.locals.user.username}`); |
|
|
|
}); |
|
|
|
} catch (error) { |
|
|
|
this.log.error('failed to create new user', { error }); |
|
|
|