-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored the code to use routers. Closes #18.
- Loading branch information
Peppe L-G
committed
Oct 5, 2021
1 parent
c7bdc8a
commit 0d1bf87
Showing
5 changed files
with
228 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const express = require('express') | ||
|
||
const ADMIN_USERNAME = 'Alice' | ||
const ADMIN_PASSWORD = 'abc123' | ||
|
||
const router = express.Router() | ||
|
||
router.get('/login', function(request, response){ | ||
response.render('login.hbs') | ||
}) | ||
|
||
router.post('/login', function(request, response){ | ||
|
||
const username = request.body.username | ||
const password = request.body.password | ||
|
||
if(username == ADMIN_USERNAME && password == ADMIN_PASSWORD){ | ||
request.session.isLoggedIn = true | ||
// TODO: Do something better than redirecting to start page. | ||
response.redirect('/') | ||
}else{ | ||
// TODO: Display error message to the user. | ||
response.render('login.hbs') | ||
} | ||
|
||
}) | ||
|
||
module.exports = router |
Oops, something went wrong.