Fix / <--> /login loop
This commit is contained in:
parent
f517b6838b
commit
6f8cf69e8c
1 changed files with 22 additions and 18 deletions
36
app.js
36
app.js
|
|
@ -43,9 +43,9 @@ app.use(
|
||||||
// Verification
|
// Verification
|
||||||
app.patch("/generate-otp", async (req, res) => {
|
app.patch("/generate-otp", async (req, res) => {
|
||||||
if (
|
if (
|
||||||
config.sendgrid_verification == true ||
|
config.sendgrid_verification ||
|
||||||
config.discord_verification == true ||
|
config.discord_verification ||
|
||||||
config.smtp_verificaton == true
|
config.smtp_verificaton
|
||||||
) {
|
) {
|
||||||
const OTP = generateCode();
|
const OTP = generateCode();
|
||||||
ACTIVE_CODES.add(OTP);
|
ACTIVE_CODES.add(OTP);
|
||||||
|
|
@ -64,7 +64,7 @@ app.patch("/generate-otp", async (req, res) => {
|
||||||
(this message is automated)`
|
(this message is automated)`
|
||||||
};
|
};
|
||||||
|
|
||||||
if (config.sendgrid_verification == true) {
|
if (config.sendgrid_verification) {
|
||||||
sgMail.setApiKey(config.sendgrid_options.api_key);
|
sgMail.setApiKey(config.sendgrid_options.api_key);
|
||||||
|
|
||||||
email.to = config.sendgrid_options.to_email;
|
email.to = config.sendgrid_options.to_email;
|
||||||
|
|
@ -76,7 +76,7 @@ app.patch("/generate-otp", async (req, res) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.smtp_verification == true) {
|
if (config.smtp_verification) {
|
||||||
const smtpMailerAgent = nodemailer.createTransport(config.smtp_options);
|
const smtpMailerAgent = nodemailer.createTransport(config.smtp_options);
|
||||||
|
|
||||||
email.to = config.smtp_options.to_email;
|
email.to = config.smtp_options.to_email;
|
||||||
|
|
@ -88,7 +88,7 @@ app.patch("/generate-otp", async (req, res) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.discord_verification == true) {
|
if (config.discord_verification) {
|
||||||
try {
|
try {
|
||||||
await fetch(config.webhook_url, {
|
await fetch(config.webhook_url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
@ -117,9 +117,9 @@ function generateCode() {
|
||||||
|
|
||||||
app.post("/validate-otp", (req, res) => {
|
app.post("/validate-otp", (req, res) => {
|
||||||
if (
|
if (
|
||||||
config.sendgrid_verification == true ||
|
config.sendgrid_verification ||
|
||||||
config.discord_verification == true ||
|
config.discord_verification ||
|
||||||
config.smtp_verificaton == true
|
config.smtp_verificaton
|
||||||
) {
|
) {
|
||||||
const OTP = req.body.otp;
|
const OTP = req.body.otp;
|
||||||
|
|
||||||
|
|
@ -163,9 +163,9 @@ app.use(express.static(path.join(__dirname, "public")));
|
||||||
// Login route
|
// Login route
|
||||||
app.get("/login", (req, res) => {
|
app.get("/login", (req, res) => {
|
||||||
if (
|
if (
|
||||||
config.sendgrid_verification == true ||
|
config.sendgrid_verification ||
|
||||||
config.discord_verification == true ||
|
config.discord_verification ||
|
||||||
config.smtp_verificaton == true
|
config.smtp_verificaton
|
||||||
) {
|
) {
|
||||||
res.sendFile(path.join(__dirname, "src", "unv.html"));
|
res.sendFile(path.join(__dirname, "src", "unv.html"));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -175,12 +175,17 @@ app.get("/login", (req, res) => {
|
||||||
|
|
||||||
// General Routes
|
// General Routes
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
|
if (
|
||||||
|
config.sendgrid_verification ||
|
||||||
|
config.discord_verification ||
|
||||||
|
config.smtp_verificaton
|
||||||
|
) {
|
||||||
const verification = req.cookies["validation"];
|
const verification = req.cookies["validation"];
|
||||||
if (!verification || !validateToken(verification)) {
|
if (!verification || !validateToken(verification)) {
|
||||||
res.redirect("/login");
|
return res.redirect("/login");
|
||||||
} else {
|
|
||||||
next();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/", (req, res) => {
|
app.get("/", (req, res) => {
|
||||||
|
|
@ -226,7 +231,6 @@ function hash(token) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateToken(verification) {
|
function validateToken(verification) {
|
||||||
console.log(verification);
|
|
||||||
const [id, token] = verification.split(":");
|
const [id, token] = verification.split(":");
|
||||||
const tokenData = TOKENS.find((token) => token.id == id);
|
const tokenData = TOKENS.find((token) => token.id == id);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue