Just a bug fix
This commit is contained in:
1 parent
d0aa7a0fbd
commit
6819b82723
8 files changed
+37
-6
No files matched your search
@@ -54,9 +54,12 @@ Example:
|
|||||||
retirementCalculator/
|
retirementCalculator/
|
||||||
├── src/
|
├── src/
|
||||||
│ ├── views/
|
│ ├── views/
|
||||||
| ├── css/
|
│ │ └── partials/
|
||||||
| ├── images/
|
│ ├── css/
|
||||||
| └── scripts/
|
│ ├── images/
|
||||||
|
│ ├── scripts/
|
||||||
|
│ └── utils/
|
||||||
|
│
|
||||||
├── app.js
|
├── app.js
|
||||||
├── .env.example
|
├── .env.example
|
||||||
├── .gitignore
|
├── .gitignore
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ app.get('/login', (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/home', (req, res) => {
|
app.get('/home', (req, res) => {
|
||||||
res.render('home');
|
res.render('home', { session: req.session });
|
||||||
return res.status(status.Ok);
|
return res.status(status.Ok);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -106,6 +106,11 @@ app.get('/settings', (req, res) => {
|
|||||||
return res.status(status.Ok);
|
return res.status(status.Ok);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/logout', (req, res) => {
|
||||||
|
req.session.destroy();
|
||||||
|
return res.redirect('/login');
|
||||||
|
});
|
||||||
|
|
||||||
app.get('/*splat', (req, res) => {
|
app.get('/*splat', (req, res) => {
|
||||||
res.send('404 Not Found');
|
res.send('404 Not Found');
|
||||||
return res.status(status.NotFound);
|
return res.status(status.NotFound);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ module.exports = (users) => {
|
|||||||
return res.redirect("/login");
|
return res.redirect("/login");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bcrypt.compare(req.body.password, user.password)) {
|
if (!bcrypt.compareSync(req.body.password, user.password)) {
|
||||||
req.session.errMessage = "Incorrect password";
|
req.session.errMessage = "Incorrect password";
|
||||||
res.status(status.Unauthorized);
|
res.status(status.Unauthorized);
|
||||||
return res.redirect("/login");
|
return res.redirect("/login");
|
||||||
@@ -64,7 +64,7 @@ module.exports = (users) => {
|
|||||||
return res.redirect("/signup");
|
return res.redirect("/signup");
|
||||||
}
|
}
|
||||||
|
|
||||||
let hashedPassword = await bcrypt.hash(req.body.password, salt);
|
let hashedPassword = await bcrypt.hashSync(req.body.password, salt);
|
||||||
|
|
||||||
users.insertOne({
|
users.insertOne({
|
||||||
email: req.body.email,
|
email: req.body.email,
|
||||||
|
|||||||
@@ -31,5 +31,10 @@ module.exports = (middleware) => {
|
|||||||
return res.status(status.Ok);
|
return res.status(status.Ok);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/logout', middleware, (req, res) => {
|
||||||
|
req.session.destroy();
|
||||||
|
return res.redirect('/login');
|
||||||
|
});
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
};
|
};
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<%- include("./partials/header") %>
|
<%- include("./partials/header") %>
|
||||||
|
<% if (session.authenticated) { console.log(session.email); } else { console.log("No user"); } %>
|
||||||
<main>
|
<main>
|
||||||
The Dashboard Page
|
The Dashboard Page
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -44,6 +44,10 @@
|
|||||||
<button type="submit"
|
<button type="submit"
|
||||||
class="border-2 border-gray-600 bg-blue-600 text-white py-1 w-full rounded-md hover:bg-transparent hover:text-indigo-700 font-semibold">Login</button>
|
class="border-2 border-gray-600 bg-blue-600 text-white py-1 w-full rounded-md hover:bg-transparent hover:text-indigo-700 font-semibold">Login</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mt-5 block justify-between items-center">
|
||||||
|
<label>Don't have an account?</label>
|
||||||
|
<a href="/signup" class="text-indigo-600 font-semibold">Register</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -19,6 +19,15 @@
|
|||||||
<li>
|
<li>
|
||||||
<a href="/more" class="block py-2 px-3 lg:p-0 text-gray-900 rounded hover:bg-gray-100 lg:hover:bg-transparent lg:border-0 lg:hover:text-blue-700 dark:text-white lg:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white lg:dark:hover:bg-transparent">More</a>
|
<a href="/more" class="block py-2 px-3 lg:p-0 text-gray-900 rounded hover:bg-gray-100 lg:hover:bg-transparent lg:border-0 lg:hover:text-blue-700 dark:text-white lg:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white lg:dark:hover:bg-transparent">More</a>
|
||||||
</li>
|
</li>
|
||||||
|
<% if (session.authenticated) { %>
|
||||||
|
<li>
|
||||||
|
<a href="/logout" class="block py-2 px-3 lg:p-0 text-gray-900 rounded hover:bg-gray-100 lg:hover:bg-transparent lg:border-0 lg:hover:text-blue-700 dark:text-white lg:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white lg:dark:hover:bg-transparent">Logout</a>
|
||||||
|
</li>
|
||||||
|
<% } else { %>
|
||||||
|
<li>
|
||||||
|
<a href="/login" class="block py-2 px-3 lg:p-0 text-gray-900 rounded hover:bg-gray-100 lg:hover:bg-transparent lg:border-0 lg:hover:text-blue-700 dark:text-white lg:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white lg:dark:hover:bg-transparent">Login</a>
|
||||||
|
</li>
|
||||||
|
<% } %>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -39,6 +39,10 @@
|
|||||||
<button type="submit"
|
<button type="submit"
|
||||||
class="border-2 border-gray-600 bg-blue-600 text-white py-1 w-full rounded-md hover:bg-transparent hover:text-indigo-700 font-semibold">Signup</button>
|
class="border-2 border-gray-600 bg-blue-600 text-white py-1 w-full rounded-md hover:bg-transparent hover:text-indigo-700 font-semibold">Signup</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mt-5 block justify-between items-center">
|
||||||
|
<label>Already have an account?</label>
|
||||||
|
<a href="/login" class="text-indigo-600 font-semibold">Login</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user