implement new token checking function and modify email.js to use it
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { app, globalConfig } from "../index.js" // Get globals from index
|
||||
import { checkToken } from "../liberals/auth.js"
|
||||
import { checkTokenNew } from "../liberals/auth.js"
|
||||
import { logRequest } from "../liberals/logging.js"
|
||||
import * as nodemailer from 'nodemailer'
|
||||
|
||||
@@ -14,10 +14,10 @@ const transporter = nodemailer.createTransport({
|
||||
})
|
||||
|
||||
app.post("/api/sendemail", (rreq,rres) => {
|
||||
checkToken(rreq.get("Authorization"),"email").then(authRes => {
|
||||
if (authRes === false) {
|
||||
checkTokenNew(rreq.get("Authorization"),"email").then(authRes => {
|
||||
if (authRes.result === false) {
|
||||
rres.sendStatus(401)
|
||||
} else if (authRes === true) {
|
||||
} else if (authRes.result === true) {
|
||||
if (rreq.body == undefined || rreq.body.recipient == undefined) { // 2024-05-11: Turbo bodge check to make sure request JSON is valid, probably wont work but whatever
|
||||
rres.sendStatus(400)
|
||||
} else {
|
||||
@@ -29,14 +29,14 @@ app.post("/api/sendemail", (rreq,rres) => {
|
||||
text: rreq.body.message ?? "Message Not Set"
|
||||
}).then(transportResponse => {
|
||||
if (transportResponse.response.slice(0,1) === "2") {
|
||||
logRequest(rres,rreq,200,transportResponse.response)
|
||||
logRequest(rres,rreq,200,transportResponse.response,authRes)
|
||||
rres.status(200).send(transportResponse.response)
|
||||
} else {
|
||||
logRequest(rres,rreq,400,transportResponse.response)
|
||||
logRequest(rres,rreq,400,transportResponse.response,authRes)
|
||||
rres.status(400).send(transportResponse.response)
|
||||
}
|
||||
}).catch(transportError => {
|
||||
logRequest(rres,rreq,500,transportError)
|
||||
logRequest(rres,rreq,500,transportError,authRes)
|
||||
rres.sendStatus(500)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user