-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,49 @@ | ||
const express = require('express'); | ||
const { checkNotAuth } = require('../handlers/checkAuth'); | ||
const User = require('../models/UserModel'); | ||
const router = express.Router() | ||
const bcrypt = require('bcrypt') | ||
const passport = require('passport') | ||
|
||
router.get("/login", checkNotAuth, function (req, res) { | ||
res.render("auth/login.html") | ||
res.render("auth/login.html", { loginSuccess: req.flash("loginSuccess")}) | ||
}) | ||
|
||
router.post("/login", checkNotAuth, passport.authenticate("local", { | ||
successRedirect: "/dash", | ||
failureRedirect: "/auth/login", | ||
failureFlash: true | ||
})) | ||
|
||
|
||
router.get("/register", checkNotAuth, function (req, res) { | ||
res.render("auth/register.html") | ||
res.render("auth/register.html", { registerError: req.flash("registerError")}) | ||
}) | ||
|
||
router.post("/register", checkNotAuth, async function (req, res) { | ||
const userUsername = await User.findOne({ where: { username: req.body.username}}) | ||
const userEmail = await User.findOne({ where: { email: req.body.email}}) | ||
if (userUsername) { | ||
req.flash("registerError", "User already registered with that username") | ||
res.redirect("/auth/register") | ||
} else if (userEmail) { | ||
req.flash("registerError", "User already registered with that email") | ||
res.redirect("/auth/register") | ||
} else { | ||
const hashedPassword = await bcrypt.hash(req.body.password, 10) | ||
User.create({ | ||
username: req.body.username, | ||
password: hashedPassword, | ||
email: req.body.email, | ||
pteroId: 0, // TODO: Implement Ptero API | ||
ipAddress: "", // TODO: Register IP address | ||
credits: 0, | ||
verifiedEmail: false | ||
}) | ||
req.flash("loginSuccess", "User registered successfully") | ||
res.redirect("/auth/login") | ||
} | ||
}) | ||
|
||
|
||
module.exports = router |
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
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,18 @@ | ||
{% extends "template.html" %} | ||
|
||
{% block head %} | ||
<title>PanelMgr | Dashboard</title> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> | ||
<div class="container-fluid"> | ||
<a class="navbar-brand" href="#">PanelMgr</a> | ||
</div> | ||
</nav> | ||
<div class="container"> | ||
<h1>Dashboard</h1> | ||
<p>Welcome to the dashboard</p> | ||
</div> | ||
<form> | ||
{% endblock %} |