Skip to content

Commit

Permalink
✨ Conditionally rendering instructor registration
Browse files Browse the repository at this point in the history
  • Loading branch information
reMRKableDev committed Dec 18, 2020
1 parent faf98b4 commit 6df5716
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion api/routes/users.routes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const { Router } = require('express');
const { profilePrefix } = require('../../configs');
const { profilePrefix, instructorPrefix } = require('../../configs');
const { renderUserProfileController } = require('../controllers');
const { isLoggedInUser } = require('../middleware');

const router = Router();

router.get(profilePrefix, isLoggedInUser, renderUserProfileController);
router.get(instructorPrefix, (req, res) =>
res.status(200).render('users/instructor')
);

module.exports = router;
1 change: 1 addition & 0 deletions configs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
profilePrefix: '/profile',
googleAuthPrefix: '/auth/google',
googleAuthCallbackPrefix: '/auth/google/callback',
instructorPrefix: '/instructor',

/* Database */
localMongoUri: LOCAL_MONGO_URI,
Expand Down
3 changes: 3 additions & 0 deletions loaders/express.loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const { googleAuthStrategy } = require('../passport/googleStrategy');
const app = express();
app.disable('x-powered-by');

hbs.registerHelper('ifEqualsHelper', (value1, value2, options) =>
value1 === value2 ? options.fn(this) : options.inverse(this)
);
hbs.registerPartials(path.join(__dirname, '../views/partials'));
app.set('views', path.join(__dirname, '../views'));
app.set('view engine', 'hbs');
Expand Down
5 changes: 5 additions & 0 deletions views/partials/header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
<li><a href="/all-courses">All Courses</a></li>
<li><a href='/my-courses'>My Courses</a></li>
<li><a href='/profile'>My Profile</a></li>

{{#ifEqualsHelper role 'student'}}
<li><a href='/instructor'>Become Instructor</a></li>
{{/ifEqualsHelper}}

<li>
<form action="/logout" method="post">
<button type="submit">Logout</button>
Expand Down
5 changes: 5 additions & 0 deletions views/users/instructor.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<section>
<form action="/instructor" method="post">
<button type="submit">Become Instructor</button>
</form>
</section>

0 comments on commit 6df5716

Please sign in to comment.