mirror of
https://github.com/Troplo/Colubrina.git
synced 2024-11-25 12:46:42 +11:00
update email verification rules
This commit is contained in:
parent
b93948fc36
commit
19bca17ba0
4 changed files with 40 additions and 1 deletions
|
@ -20,6 +20,18 @@ router.all("*", auth, async (req, res, next) => {
|
|||
}
|
||||
})
|
||||
|
||||
router.all("*", auth, async (req, res, next) => {
|
||||
try {
|
||||
if (!req.user.emailVerified && process.env.EMAIL_VERIFICATION === "true") {
|
||||
throw Errors.emailVerificationRequired
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
} catch (e) {
|
||||
next(e)
|
||||
}
|
||||
})
|
||||
|
||||
router.get("/", auth, async (req, res, next) => {
|
||||
try {
|
||||
res.json({
|
||||
|
|
|
@ -11,6 +11,18 @@ const {
|
|||
Friend
|
||||
} = require("../models")
|
||||
|
||||
router.all("*", auth, async (req, res, next) => {
|
||||
try {
|
||||
if (!req.user.emailVerified && process.env.EMAIL_VERIFICATION === "true") {
|
||||
throw Errors.emailVerificationRequired
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
} catch (e) {
|
||||
next(e)
|
||||
}
|
||||
})
|
||||
|
||||
router.delete("/:id/:associationId", auth, async (req, res, next) => {
|
||||
try {
|
||||
const io = req.app.get("io")
|
||||
|
|
|
@ -4,9 +4,21 @@ const Errors = require("../lib/errors")
|
|||
const express = require("express")
|
||||
const router = express.Router()
|
||||
|
||||
router.all("*", auth, async (req, res, next) => {
|
||||
try {
|
||||
if (!req.user.emailVerified && process.env.EMAIL_VERIFICATION === "true") {
|
||||
throw Errors.emailVerificationRequired
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
} catch (e) {
|
||||
next(e)
|
||||
}
|
||||
})
|
||||
|
||||
router.get("/", auth, async (req, res, next) => {
|
||||
try {
|
||||
let friends = await Friend.findAll({
|
||||
const friends = await Friend.findAll({
|
||||
where: {
|
||||
userId: req.user.id
|
||||
},
|
||||
|
|
|
@ -75,6 +75,9 @@ router.post("/verify/resend", auth, mailLimiter, async (req, res, next) => {
|
|||
if (process.env.EMAIL_VERIFICATION !== "true") {
|
||||
throw Errors.invalidParameter("Email verification is disabled")
|
||||
}
|
||||
if (req.user.emailVerified) {
|
||||
throw Errors.invalidParameter("Email is already verified")
|
||||
}
|
||||
const token = "COLUBRINA-VERIFY-" + cryptoRandomString({ length: 64 })
|
||||
await req.user.update({
|
||||
emailToken: token
|
||||
|
|
Loading…
Reference in a new issue