Skip to content

Commit

Permalink
linter annoying
Browse files Browse the repository at this point in the history
  • Loading branch information
Patle1234 authored Jul 22, 2024
1 parent 6ffda3e commit 049519d
Showing 1 changed file with 59 additions and 58 deletions.
117 changes: 59 additions & 58 deletions src/services/sponsor/sponsor-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Database } from "../../database";
import RoleChecker from "../../middleware/role-checker";
import { Role } from "../auth/auth-models";
import { StatusCodes } from "http-status-codes";
import {sendEmail} from "../ses/ses-utils"
import { sendEmail } from "../ses/ses-utils";
import jsonwebtoken from "jsonwebtoken";
import { Config } from "../../config";
const bcrypt = require('bcrypt');
const bcrypt = require("bcrypt");

Check failure on line 9 in src/services/sponsor/sponsor-router.ts

View workflow job for this annotation

GitHub Actions / lint

Require statement not part of import statement
const sponsorRouter = Router();

// Get favorite events for an attendee
Expand Down Expand Up @@ -34,8 +34,8 @@ sponsorRouter.get(
);

function createSixDigitCode() {
let result = '';
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let result = "";
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for (let i = 0; i < 6; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
Expand All @@ -50,70 +50,71 @@ function encryptSixDigitCode(sixDigitCode: string): string {
const hash = bcrypt.hashSync(sixDigitCode, saltRounds);
return hash;
} catch (err) {
console.error('Error encrypting the code:', err);
console.error("Error encrypting the code:", err);
throw err;
}
}

sponsorRouter.post(
"/login",
async (req, res, next) => {
const { email } = req.body;
try {
const sixDigitCode = createSixDigitCode();
const expTime = Math.floor(Date.now() / 1000) + 300;
const hashedVerificationCode = encryptSixDigitCode(sixDigitCode);
await Database.SPONSOR.findOneAndUpdate(
{ email },
{
$set: {
sponsorRouter.post("/login", async (req, res, next) => {
const { email } = req.body;
try {
const sixDigitCode = createSixDigitCode();
const expTime = Math.floor(Date.now() / 1000) + 300;
const hashedVerificationCode = encryptSixDigitCode(sixDigitCode);
await Database.SPONSOR.findOneAndUpdate(
{ email },
{
$set: {
hashedVerificationCode: hashedVerificationCode,
expTime: expTime,
},
expTime: expTime,
},
{ upsert: true }
);
await sendEmail(email, 'RP-Sponor Email Verification!', `Here is your verification code: ${sixDigitCode}`);
return res.sendStatus(StatusCodes.CREATED);
} catch (error) {
next(error);
}
},
{ upsert: true }
);
await sendEmail(
email,
"RP-Sponor Email Verification!",
`Here is your verification code: ${sixDigitCode}`
);
return res.sendStatus(StatusCodes.CREATED);
} catch (error) {
next(error);
}
);
});

sponsorRouter.post(
"/verify",
async (req, res, next) => {
const { email, sixDigitCodeInput } = req.body;
try {
const sponsorData = await Database.SPONSOR.findOne({ email });
if (!sponsorData) {
return res.status(401).json({ message: 'No Access' });
}
const { hashedVerificationCode, expTime } = sponsorData
if (Math.floor(Date.now() / 1000) > expTime){
return res.status(401).json({ message: 'Code expired' });
}
const match = await bcrypt.compareSync(sixDigitCodeInput, hashedVerificationCode)
if (!match) {
return res.status(401).json({ message: 'Incorrect Code' });
}
await Database.SPONSOR.deleteOne({ email });
const token = jsonwebtoken.sign(
{
sponsorRouter.post("/verify", async (req, res, next) => {
const { email, sixDigitCodeInput } = req.body;
try {
const sponsorData = await Database.SPONSOR.findOne({ email });
if (!sponsorData) {
return res.status(401).json({ message: "No Access" });
}
const { hashedVerificationCode, expTime } = sponsorData;
if (Math.floor(Date.now() / 1000) > expTime) {
return res.status(401).json({ message: "Code expired" });
}
const match = await bcrypt.compareSync(
sixDigitCodeInput,
hashedVerificationCode
);
if (!match) {
return res.status(401).json({ message: "Incorrect Code" });
}
await Database.SPONSOR.deleteOne({ email });
const token = jsonwebtoken.sign(
{
email,
role: 'CORPORATE'
},
Config.JWT_SIGNING_SECRET,
{
role: "CORPORATE",
},
Config.JWT_SIGNING_SECRET,
{
expiresIn: Config.JWT_EXPIRATION_TIME,
}
);
res.json({ token });
} catch (error) {
next(error);
}
}
);
res.json({ token });
} catch (error) {
next(error);
}
);
});

export default sponsorRouter;

0 comments on commit 049519d

Please sign in to comment.