You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.6 KiB
JavaScript

// Strict Mode
"use strict";
// Imports
import authentication from "../../authentication/authentication.js";
import cryptography from "../../cryptography/cryptography.js";
import database from "../../database/database.js";
import mail from "../../mail/mail.js";
// Handler
export default async function handler ( req, res ) {
try {
const response = {
success: false,
activated: false
};
const password = await database.loginUser(req.body.Email);
if (password == false) {
res.send({
response
});
} else {
const active = await database.getActive(req.body.Email);
if (await cryptography.compareHash(req.body.Password, password.passphrase)) {
if (active === true) {
const user = await database.getUsername(req.body.Email);
await authentication.setUser(req, res, user);
response.success = true;
response.activated = true;
res.send({
response
});
} else {
await mail.sendAccountActivationEmail(req.body.Email, "http://localhost:3000/" + "activate/" + await database.getActive(req.body.Email));
response.success = true;
res.send({
response
});
};
} else {
res.send({
response
});
};
};
} catch {
res.send(500);
};
};