24 lines
738 B
JavaScript
24 lines
738 B
JavaScript
|
const express = require("express");
|
||
|
const router = express.Router();
|
||
|
const models = require("../models");
|
||
|
const error = require("./utils/error");
|
||
|
|
||
|
router.get("/check", async (req, res) => {
|
||
|
if (!req.query.token)
|
||
|
return error(req, res, "Missing argument", 400);
|
||
|
let user = await models.User.findOne({where: {"emailToken": req.query.token}});
|
||
|
if (user) {
|
||
|
user.emailVerified = true;
|
||
|
if (user.email.endsWith("@etu.univ-lyon1.fr"))
|
||
|
user.permissions = 1;
|
||
|
else if (user.email.endsWith("@univ-lyon1.fr"))
|
||
|
user.permissions = 2;
|
||
|
await user.save();
|
||
|
res.redirect("/");
|
||
|
} else
|
||
|
return error(req, res, "Invalid token", 4000);
|
||
|
});
|
||
|
|
||
|
|
||
|
module.exports = router;
|