Skip to content

Instantly share code, notes, and snippets.

View mpragnarok's full-sized avatar
🎯
Keep learning

Mina Huang mpragnarok

🎯
Keep learning
View GitHub Profile

FWIW: I'm not the author of the content presented here (which is an outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

What's an Effective Engineer?

@mpragnarok
mpragnarok / login.hbs
Created September 12, 2019 02:31
partial template inserting in login view
<div class="row mt-5">
<div class="col-md-5 m-auto">
<div class="card card-body">
<h1 class="text-center mb-3">Login</h1>
{{>messages}}
<form action="/users/login" method="POST">
<div class="form-group">
<label for="email">Email</label>
<input type="email" id="email" class="form-control" name="email" placeholder="Enter Email" />
</div>
@mpragnarok
mpragnarok / messages.hbs
Created September 12, 2019 02:30
Handlebar partial view setting
<!--views\partials\messages.hbs-->
{{#if message}}
<div class="alert alert-danger alert-dismissible fade show" role="alert">
{{{message}}}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
{{/if}}
@mpragnarok
mpragnarok / condition-example.hbs
Created September 12, 2019 02:29
handlebar if condition helper
{{#if condition}}
<h1>show me the partial</h1>
{{/if}}
@mpragnarok
mpragnarok / passport.js
Created September 12, 2019 02:27
Passport.js configuration in LocalStrategy
// config\passport.js
const LocalStrategy = require('passport-local').Strategy
const bcrypt = require('bcryptjs')
const User = require('../src/models/user')
module.exports = passport => {
// setup local passport
passport.use(
@mpragnarok
mpragnarok / user.js
Created September 12, 2019 02:27
message setting in the user router
// src\routers\user.js
// show login page
router.get('/login', async (req, res) => {
try {
res.render('login', { message: req.flash('error') })
} catch (e) {
res.status(500).send()
}
})
@mpragnarok
mpragnarok / package.json
Created September 12, 2019 02:24
Dependencies
// package.json
"dependencies": {
"bcryptjs": "^2.4.3",
"connect-flash": "^0.1.1",
"express": "^4.17.1",
"express-handlebars": "^3.1.0",
"express-session": "^1.16.2",
"mongodb": "^3.3.2",
"mongoose": "^5.6.13",
"passport": "^0.4.0",