GOAL1: allow users to create an account GOAL2: validation GOAL3: functionality to login
- Route (GET
/signup
) (insideauth.routes.js
) - Create a view (
auth/signup.hbs
) - We've also updated
layout.hbs
andstyle.css
- Route (POST
/signup
) - Generate the hash/digest
- Query DB (
User.create()
) - Redirect to
/userProfile
(we created the viewusers/user-profile.hbs
and a route GET/userProfile
)
- Basic Client-side validation (HTML required)
- Some examples of Server-side validation
-
Add link to login (
layout.hbs
) -
Route (GET
/login
) -
View (
views/auth/login.hbs
) -
Route (POST
/login
)- Query DB (
User.findOne()
) - Check credentials (
bcryptjs.compareSync
) - If sucessful, redirect to
/userProfile
- Query DB (
-
Send information to the view and display it (ex. the username)
res.render('users/user-profile', { user });
- Session persistance with
express-session
andconnect-mongo
- Route (POST
/logout
) - Add button to nav menu
-
Step 7.a: boilerplate code for authorization
- Added mock routes & links to nav
-
Step 7.b: custom roles
- Add
role
to the User model - Drop
users
collection, create 3 users, change the roles directly in the DB - Display role info in the profile page
- Add
-
Step 7.c: authorization with custom middleware
- isAdmin middleware (check if the user is
admin
) + protect the orders route - isStaff middleware (check if the user is
admin
orshopManager
) + protect all routes to create a new product (GET & POST routes)
- isAdmin middleware (check if the user is