Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
SOD/routes/check.js
2020-08-25 15:49:56 +02:00

21 lines
656 B
JavaScript

const express = require("express");
const router = express.Router();
const error = require("./utils/error");
const models = require("../models");
router.get("/", async (req, res) => {
if (!req.query.token)
return error(req, res, "Can't verify email", 400, "Missing args");
let user = await models.User.findOne({where: {emailToken: req.query.token}});
if (!user)
return error(req, res, "Can't verify email", 400, "Invalid token");
user.emailToken = null;
user.emailVerified = true;
await user.save();
req.session.user = user;
req.session.save(() => res.redirect("/profile"));
});
module.exports = router;