-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#23187419173 - fx:fixed Two Factor Authentication for Sellers #43
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,8 @@ describe("Testing product Routes", () => { | |
try { | ||
await connect(); | ||
const testAdmin = { | ||
name: "admin", | ||
username: "admin", | ||
name: "admin123", | ||
username: "admin123", | ||
email: "[email protected]", | ||
password: await bcrypt.hash("password", 10), | ||
roleId: 3 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
export const verifyOtpTemplate = (token: number) => { | ||
export const verifyOtpTemplate = (link: string,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> | ||
<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> | ||
|
||
|
||
<div style="margin-bottom: 20px;"> | ||
<p style="padding: 8px; font-size: 16px; font-weight: bold; background-color: blue; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s ease; display: inline-block; max-width: 200px; color: white;">${token}</p> | ||
</div> | ||
|
||
<p>OR</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 style="margin-bottom: 20px;"> | ||
<a href="${link}" style="padding: 12px 24px; text-decoration: none; font-size: 16px; font-weight: bold; background-color: yellow; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s ease; display: inline-block; max-width: 100%;">Click here to verify</a> | ||
</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;"> | ||
<p style="font-style: italic; color: #999999;">Your account is safe 😎.</p> | ||
</div> | ||
</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> | ||
</body> | ||
</html> | ||
|
||
|
||
`; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import { Router } from "express"; | ||
import { fetchAllUsers, createUserController, userLogin, updatePassword, tokenVerification, handleSuccess, handleFailure,updateProfileController, getProfileController } from "../controllers/userControllers"; | ||
import { fetchAllUsers, createUserController, userLogin, updatePassword, tokenVerification, handleSuccess, handleFailure,updateProfileController, getProfileController, otpVerification } from "../controllers/userControllers"; | ||
import { emailValidation, validateSchema } from "../middlewares/validator"; | ||
import { isLoggedIn } from "../middlewares/isLoggedIn"; | ||
import { passwordUpdateSchema } from "../schemas/passwordUpdate"; | ||
import { isTokenFound } from "../middlewares/isTokenFound"; | ||
import { authenticateUser, callbackFn } from "../services/user.service"; | ||
require("../auth/auth"); | ||
import logInSchema from "../schemas/loginSchema"; | ||
|
@@ -26,7 +25,8 @@ userRoutes.put("/passwordupdate", isLoggedIn, validateSchema(passwordUpdateSchem | |
userRoutes.post("/login", emailValidation,validateSchema(logInSchema),userLogin); | ||
userRoutes.post("/register", emailValidation, validateSchema(signUpSchema), createUserController); | ||
userRoutes.put("/passwordupdate", isLoggedIn, validateSchema(passwordUpdateSchema), updatePassword); | ||
userRoutes.post("/2fa-verify", isTokenFound, tokenVerification); | ||
userRoutes.get("/2fa-verify/:token",tokenVerification); | ||
Comment on lines
27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you verifying from get method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oooh I missed this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again for that get its verification link that user click and u can't use post using link since it will be opened directly in browser There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will be handled from front-end tha means link will be front-end link, but leave it for now |
||
userRoutes.post("/2fa-verify",otpVerification); | ||
userRoutes.get('/profile', | ||
isLoggedIn, | ||
getProfileController | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
import Token from "../sequelize/models/Token"; | ||
import { IUser, SUBJECTS } from "../types"; | ||
import { IUser } from "../types"; | ||
import { env } from "../utils/env"; | ||
import { generateMagicLinkToken } from "../utils/jsonwebtoken"; | ||
import transporter from "../utils/transporter"; | ||
import { verifyOtpTemplate } from "../email-templates/verifyotp"; | ||
|
||
export const sendEmailService = async (user: IUser, subject: string, template: any, token: number) => { | ||
export const sendEmailService = async (user: IUser, subject: string, template: any) => { | ||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you think this function can be re-used , why that user can you put email instead whole user object There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes its reusable i removed token since token doesn't have naything todo with that sendEmailService, token or any other related info has be passed as argument in emailTemplate not in service There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also pass email to send to not whole user |
||
const mailOptions = { | ||
from: env.smtp_user, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const generateRandomNumber = () => { | ||
const otp = Math.floor(100000 + Math.random() * 900000); | ||
return otp; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you using this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was about to use it but realy i'm not using it currently, since token don't last long(10min) i decided not to blacklist verification token s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it then