From 03f574010745580d971ae79b2e6aa7daaa25ade7 Mon Sep 17 00:00:00 2001 From: Helen Zhou Date: Thu, 10 May 2018 17:11:06 +0100 Subject: [PATCH 1/4] Add middleware to protected routes and create my profile details edit route Closes #35 --- src/controllers/index.js | 19 ++++++++++++++++++- src/controllers/profileDetails.js | 3 +++ src/views/profileDetails.hbs | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/controllers/profileDetails.js create mode 100644 src/views/profileDetails.hbs diff --git a/src/controllers/index.js b/src/controllers/index.js index a6da2aa..ecfcf6b 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -2,14 +2,25 @@ const router = require('express').Router(); const passport = require('passport'); const home = require('./home'); +const profileDetails = require('./profileDetails'); // const auth = require('./auth'); router.get('/', home.get); +// MIDDLEWARE to ensure used is authenticated +function ensureAuthenticated(req, res, next) { + if (req.isAuthenticated()) { + // req.user is available for use here + return next(); + } + // denied - should redirect to login + res.redirect('/'); +} + // auth routes router.get( '/auth/github/signup', - passport.authenticate('github', { scope: ['read:org'] }), + passport.authenticate('github', { scope: ['read:org'] }) ); router.get( @@ -30,6 +41,12 @@ router.get('/auth/github/logout', (req, res) => { req.logout(); res.redirect('/'); }); + +router.get( + '/myprofile/mydetails/edit', ensureAuthenticated, profileDetails.get +); + + // router.get('/auth/github/signup', auth.signup); // router.get('/auth/github/callback', auth.signupCallback); // router.get('/auth/github/logout', auth.logout); diff --git a/src/controllers/profileDetails.js b/src/controllers/profileDetails.js new file mode 100644 index 0000000..c7d461e --- /dev/null +++ b/src/controllers/profileDetails.js @@ -0,0 +1,3 @@ +exports.get = (req, res) => { + res.render('profileDetails', { activePage: { profile: true }, loggedIn: true }); +}; \ No newline at end of file diff --git a/src/views/profileDetails.hbs b/src/views/profileDetails.hbs new file mode 100644 index 0000000..4eb9b39 --- /dev/null +++ b/src/views/profileDetails.hbs @@ -0,0 +1 @@ +

Hello

> \ No newline at end of file From b5bb56733bccde3397f807dfdf4910d8e32ad0b5 Mon Sep 17 00:00:00 2001 From: Helen Zhou Date: Thu, 10 May 2018 17:59:09 +0100 Subject: [PATCH 2/4] Add html content to my profile - my details - edit form Relate #37 --- src/views/profileDetails.hbs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/views/profileDetails.hbs b/src/views/profileDetails.hbs index 4eb9b39..69ed714 100644 --- a/src/views/profileDetails.hbs +++ b/src/views/profileDetails.hbs @@ -1 +1,34 @@ -

Hello

> \ No newline at end of file +

My Details

+
+ * Required + + + + + + + + +
\ No newline at end of file From 80b364f6d37332e4f0c6e286e80cb64cdc551590 Mon Sep 17 00:00:00 2001 From: Helen Zhou Date: Fri, 11 May 2018 12:10:26 +0100 Subject: [PATCH 3/4] Resolve merge conflict --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index b5020d8..ed92dc4 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "dependencies": { "body-parser": "^1.18.2", "cookie-session": "^2.0.0-beta.3", + "axios": "^0.18.0", "dotenv": "^5.0.1", "express": "^4.16.3", "express-handlebars": "^3.0.0", From 7cb0b3df4bfae7f07feed098a5edd8cfb44eaa96 Mon Sep 17 00:00:00 2001 From: Helen Zhou Date: Fri, 11 May 2018 12:10:48 +0100 Subject: [PATCH 4/4] Resolve merge conflict --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ed92dc4..ba7577d 100644 --- a/package.json +++ b/package.json @@ -39,9 +39,9 @@ "tape": "^4.9.0" }, "dependencies": { + "axios": "^0.18.0", "body-parser": "^1.18.2", "cookie-session": "^2.0.0-beta.3", - "axios": "^0.18.0", "dotenv": "^5.0.1", "express": "^4.16.3", "express-handlebars": "^3.0.0",