-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed 2fa implemetation by replacing verification link with otp …
…code
- Loading branch information
Showing
23 changed files
with
326 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export const verifyOtpTemplate = (token: number) => { | ||
return `<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Account Verification</title> | ||
</head> | ||
<body style="font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: #f8f9fa; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0;"> | ||
<div style="width: 80%; max-width: 400px; margin:auto; padding: 30px; background-color: #ffffff; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); text-align: center;"> | ||
<h1 style="color: #333333; font-size: 24px; margin-bottom: 20px;">Verify that It's you</h1> | ||
<p style="color: #666666; font-size: 16px; line-height: 1.6; margin-bottom: 20px;"> We noticed a login attempt to your Eagle E-commerce account. If this was you, please verify your new device using the following one-time verification code</p> | ||
<p></> | ||
<div style="display: flex; justify-content: center;width:100%"> | ||
<p style="padding: 12px 24px; font-size: 16px; font-weight: bold; color: white; background-color: blue; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s ease;margin:auto;">${token}</p> | ||
</div> | ||
<p style="color: #999999; font-size: 14px; margin-bottom: 20px;">This verification code is valid for 10 minutes. </p> | ||
<p style="color: #999999; font-size: 14px; margin-bottom: 20px;">If you don't recognize this login attempt, someone may be trying to access your account. We recommend you change your password immediately.</p> | ||
<div style="display: flex; justify-content: center; margin:auto;width:100%"> | ||
<p style="font-style: italic; color: #999999;margin:auto">Your account is safe 😎.</p> | ||
</div> | ||
</div> | ||
</body> | ||
</html> | ||
`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { NextFunction, Request, Response } from "express"; | ||
import Token from "../sequelize/models/Token"; | ||
|
||
export const isTokenFound = async (req: any, res: Response, next: NextFunction) => { | ||
const { token } = req.body; | ||
try { | ||
const foundToken = await Token.findOne({ where: { token: token } }); | ||
|
||
if (foundToken) { | ||
req.token = foundToken; | ||
next(); | ||
} else { | ||
return res.status(404).json({ | ||
message: "Invalid token", | ||
}); | ||
} | ||
} catch (error: any) { | ||
return res.status(500).json({ | ||
message: error.message, | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import { Router } from "express"; | ||
import { fetchAllUsers, createUserController, userLogin, updatePassword } from "../controllers/userControllers"; | ||
import { fetchAllUsers, createUserController, userLogin, updatePassword, tokenVerification } from "../controllers/userControllers"; | ||
import { emailValidation, validateSchema } from "../middleware/validator"; | ||
import signUpSchema from "../schemas/signUpSchema"; | ||
import { isLoggedIn } from "../middlewares/isLoggedIn"; | ||
import { passwordUpdateSchema } from "../schemas/passwordUpdate"; | ||
import { otpVerification } from "../controllers/2faControllers"; | ||
import { isTokenFound } from "../middlewares/isTokenFound"; | ||
|
||
const userRoutes = Router(); | ||
|
||
userRoutes.get("/", fetchAllUsers); | ||
userRoutes.post("/login", userLogin); | ||
userRoutes.post("/register", emailValidation, validateSchema(signUpSchema), createUserController); | ||
userRoutes.put("/passwordupdate", isLoggedIn, validateSchema(passwordUpdateSchema), updatePassword); | ||
userRoutes.get("/2fa/verify", otpVerification); | ||
userRoutes.post("/2fa-verify", isTokenFound, tokenVerification); | ||
|
||
export default userRoutes; |
Oops, something went wrong.