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) => {
|
router.get("/", auth, async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
res.json({
|
res.json({
|
||||||
|
|
|
@ -11,6 +11,18 @@ const {
|
||||||
Friend
|
Friend
|
||||||
} = require("../models")
|
} = 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) => {
|
router.delete("/:id/:associationId", auth, async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const io = req.app.get("io")
|
const io = req.app.get("io")
|
||||||
|
|
|
@ -4,9 +4,21 @@ const Errors = require("../lib/errors")
|
||||||
const express = require("express")
|
const express = require("express")
|
||||||
const router = express.Router()
|
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) => {
|
router.get("/", auth, async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
let friends = await Friend.findAll({
|
const friends = await Friend.findAll({
|
||||||
where: {
|
where: {
|
||||||
userId: req.user.id
|
userId: req.user.id
|
||||||
},
|
},
|
||||||
|
|
|
@ -75,6 +75,9 @@ router.post("/verify/resend", auth, mailLimiter, async (req, res, next) => {
|
||||||
if (process.env.EMAIL_VERIFICATION !== "true") {
|
if (process.env.EMAIL_VERIFICATION !== "true") {
|
||||||
throw Errors.invalidParameter("Email verification is disabled")
|
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 })
|
const token = "COLUBRINA-VERIFY-" + cryptoRandomString({ length: 64 })
|
||||||
await req.user.update({
|
await req.user.update({
|
||||||
emailToken: token
|
emailToken: token
|
||||||
|
|
Loading…
Reference in a new issue