Open giuroperto opened 4 years ago
flash messages are not working
add map in client's details
Delete button user list + employees list
Add picture home internal + home users
Add validation fields such as CNPJ, email, phone, coordinates...
Add admin CRUD -> internal home only for admins
FLASH MESSAGES? URL DEFAULT? SELECT OPTIONS? LOAD LAT/LONG FORMS?
CONTENT
ROUTES
AUTH ROUTES
router.post("/login", passport.authenticate("local", { successRedirect: "/", failureRedirect: "/login", failureFlash: true, passReqToCallback: true, }));
const salt = bcrypt.genSaltSync(bcryptSalt); const hashWord = bcrypt.hashSync(password, salt);
), else, render errorif (bcrypt.compareSync(thePassword, user.password)) { // Save the login in the session! req.session.currentUser = user;
router.get("/logout", (req, res) => { req.logout(); res.redirect("/login"); });
router.get("/private-page", ensureLogin.ensureLoggedIn(), (req, res) => { res.render("private", { user: req.user }); });
AUTH - LOGIN
AUTH - ROLES
CSS
SIGNUP
if (username === "" || password === "") { res.render("auth/signup", { message: "Indicate a username and a password to sign up" }); return; }
{{/if}}`
User.findOne({ "username": username }) .then(user => { if (user !== null) { res.render("auth/signup", { message: "The username already exists!" }); return; } // ADD HERE THE ACTION TO SAVE IN DB }) .catch(error => { next(error); })
// User model const User = require("../models/user"); // BCrypt to encrypt passwords const bcrypt = require("bcrypt"); const bcryptSalt = 10; ... router.post("/signup", (req, res, next) => { const username = req.body.username; const password = req.body.password; const salt = bcrypt.genSaltSync(bcryptSalt); const hashPass = bcrypt.hashSync(password, salt); User.create({ username, password: hashPass }) .then(() => { res.redirect("/"); }) .catch(error => { console.log(error); }) });
CONFIGS
app.use(session({ //secret - used to sign the session ID cookie (required) secret: "basic-auth-secret", resave: true, saveUninitialized: true, (?)// cookie: obj for the session ID cookie -> set maxAge attribute which configures the expiration date of (?)//the cookie (in milliseconds) (?)cookie: { maxAge: 60000 }, // store: sets the session store instance -> new instance of connect-mongo to store the session info in our DB store: new MongoStore({ mongooseConnection: mongoose.connection, ttl: 24 * 60 * 60 // 1 day }) }));
passport.serializeUser((user, cb) => { cb(null, user._id); });
passport.deserializeUser((id, cb) => { User.findById(id, (err, user) => { if (err) { return cb(err); } cb(null, user); }); });
app.use(flash()); passport.use(new LocalStrategy({ passReqToCallback: true }, (req, username, password, next) => { User.findOne({ username }, (err, user) => { if (err) { return next(err); } if (!user) { return next(null, false, { message: "Incorrect username" }); } if (!bcrypt.compareSync(password, user.password)) { return next(null, false, { message: "Incorrect password" }); }
return next(null, user); }); }));
app.use(passport.initialize()); app.use(passport.session());