From fea9a0d0d2e11a55c98e9bde88616249dbf364cd Mon Sep 17 00:00:00 2001 From: EisiBaer Date: Sun, 6 Aug 2023 16:15:50 +0200 Subject: [PATCH] Initial FE Views; Initial API endpoint --- src/server/routes/UserRouter.js | 39 +++++++------ .../blocks/ChangeProfilePicture.vue | 58 +++++++++++++++++++ src/webapp/components/pages/Profile.vue | 9 ++- .../views/UserCustomizationView.vue | 18 ++++++ 4 files changed, 105 insertions(+), 19 deletions(-) create mode 100644 src/webapp/components/blocks/ChangeProfilePicture.vue create mode 100644 src/webapp/components/views/UserCustomizationView.vue diff --git a/src/server/routes/UserRouter.js b/src/server/routes/UserRouter.js index 020f615..707cb1f 100644 --- a/src/server/routes/UserRouter.js +++ b/src/server/routes/UserRouter.js @@ -72,24 +72,6 @@ const fileFilterFn = function( req, file, cb ){ return; } - let indices = file.originalname.split(":"); - if( indices.length !== 3 ){ - cb( new Error( "Image index not found" ) ); - return; - } - if( - - board.categories[indices[0]] === undefined || - board.categories[indices[0]].boardEntries[indices[1]] === undefined || - ( - board.categories[indices[0]].boardEntries[indices[1]].questions[indices[2]] === undefined && - indices[2] !== 'answer' - ) - ){ - cb( new Error( "No entry found for image" ) ); - return; - } - cb( null, true ); } }); @@ -257,6 +239,27 @@ router.get("/boards/:id", (req, res) => { } }); + +router.post("/pfp", upload.single( "pfp" ), (req, res) => { + if( req.session.user === undefined ){ + res.send( { success: false, error: "Not logged in!" } ); + } else { + let imageFile = null; + if( !req.file ){ + console.error( "No file attached" ); + return; + } + imageFile = req.file; + return userController.updateProfilePicture( req.session.user, imageFile.filename ) + .then( ( user ) => { + res.send( { success: true, newProfilePicture: user.profilePicture } ); + }) + .catch( ( err ) => { + res.send( { success: false, error: err } ); + }); + } +}); + module.exports = router; function setSessionUser( req, user ){ diff --git a/src/webapp/components/blocks/ChangeProfilePicture.vue b/src/webapp/components/blocks/ChangeProfilePicture.vue new file mode 100644 index 0000000..84a222f --- /dev/null +++ b/src/webapp/components/blocks/ChangeProfilePicture.vue @@ -0,0 +1,58 @@ + + + + + diff --git a/src/webapp/components/pages/Profile.vue b/src/webapp/components/pages/Profile.vue index 9e06a18..a573356 100644 --- a/src/webapp/components/pages/Profile.vue +++ b/src/webapp/components/pages/Profile.vue @@ -1,9 +1,11 @@ + + + +