|
|
@ -58,6 +58,12 @@ class UserController extends SiteController { |
|
|
|
|
|
|
|
router.param('userId', this.populateUser.bind(this)); |
|
|
|
|
|
|
|
router.post('/:userId/profile-photo', |
|
|
|
limiterService.create(limiterService.config.user.postProfilePhoto), |
|
|
|
upload.single('imageFile'), |
|
|
|
this.postProfilePhoto.bind(this), |
|
|
|
); |
|
|
|
|
|
|
|
router.post('/:userId/settings', |
|
|
|
limiterService.create(limiterService.config.user.postUpdateSettings), |
|
|
|
upload.none(), |
|
|
@ -83,6 +89,13 @@ class UserController extends SiteController { |
|
|
|
checkProfileOwner, |
|
|
|
this.getUserView.bind(this), |
|
|
|
); |
|
|
|
|
|
|
|
router.delete('/:userId/profile-photo', |
|
|
|
limiterService.create(limiterService.config.user.deleteProfilePhoto), |
|
|
|
authRequired, |
|
|
|
checkProfileOwner, |
|
|
|
this.deleteProfilePhoto.bind(this), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
async populateUser (req, res, next, userId) { |
|
|
@ -136,6 +149,30 @@ class UserController extends SiteController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async postProfilePhoto (req, res) { |
|
|
|
const { user: userService } = this.dtp.services; |
|
|
|
try { |
|
|
|
const displayList = this.createDisplayList('profile-photo'); |
|
|
|
|
|
|
|
this.log.debug('received profile photo', { file: req.file }); |
|
|
|
await userService.updatePhoto(req.user, req.file); |
|
|
|
|
|
|
|
displayList.showNotification( |
|
|
|
'Profile photo updated successfully.', |
|
|
|
'success', |
|
|
|
'bottom-center', |
|
|
|
2000, |
|
|
|
); |
|
|
|
res.status(200).json({ success: true, displayList }); |
|
|
|
} catch (error) { |
|
|
|
this.log.error('failed to update profile photo', { error }); |
|
|
|
return res.status(error.statusCode || 500).json({ |
|
|
|
success: false, |
|
|
|
message: error.message, |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async postUpdateSettings (req, res) { |
|
|
|
const { user: userService } = this.dtp.services; |
|
|
|
try { |
|
|
@ -177,6 +214,29 @@ class UserController extends SiteController { |
|
|
|
return next(error); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async deleteProfilePhoto (req, res) { |
|
|
|
const { user: userService } = this.dtp.services; |
|
|
|
try { |
|
|
|
const displayList = this.createDisplayList('app-settings'); |
|
|
|
|
|
|
|
await userService.removePhoto(req.user); |
|
|
|
|
|
|
|
displayList.showNotification( |
|
|
|
'Profile photo removed successfully.', |
|
|
|
'success', |
|
|
|
'bottom-center', |
|
|
|
2000, |
|
|
|
); |
|
|
|
res.status(200).json({ success: true, displayList }); |
|
|
|
} catch (error) { |
|
|
|
this.log.error('failed to remove profile photo', { error }); |
|
|
|
return res.status(error.statusCode || 500).json({ |
|
|
|
success: false, |
|
|
|
message: error.message, |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = { |
|
|
|