-
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.
Ft: auth (new user needs to verify one's account before login
- Loading branch information
1 parent
49e409c
commit 9b9ab43
Showing
16 changed files
with
295 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,19 +26,22 @@ describe("testing cart", () => { | |
name: "admin123", | ||
username: "admin123", | ||
email: "[email protected]", | ||
isVerified:true, | ||
password: await bcrypt.hash("password", 10), | ||
roleId: 3, | ||
}; | ||
|
||
const testBuyer = { | ||
name: "buyer123", | ||
username: "buyer123", | ||
isVerified:true, | ||
email: "[email protected]", | ||
password: await bcrypt.hash("password", 10), | ||
}; | ||
const testSeller = { | ||
name: "seller123", | ||
username: "seller123", | ||
isVerified:true, | ||
email: "[email protected]", | ||
password: await bcrypt.hash("password", 10), | ||
}; | ||
|
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ describe("test stripe api payment", () => { | |
const testAdmin = { | ||
name: "admin123", | ||
username: "admin123", | ||
isVerified:true, | ||
email: "[email protected]", | ||
password: await bcrypt.hash("password", 10), | ||
roleId: 3, | ||
|
@@ -30,13 +31,15 @@ describe("test stripe api payment", () => { | |
const testBuyer = { | ||
name: "buyer123", | ||
username: "buyer123", | ||
isVerified:true, | ||
email: "[email protected]", | ||
password: await bcrypt.hash("password", 10), | ||
}; | ||
|
||
const testSeller = { | ||
name: "seller123", | ||
username: "seller123", | ||
isVerified:true, | ||
email: "[email protected]", | ||
password: await bcrypt.hash("password", 10), | ||
}; | ||
|
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ import redisClient from "../src/config/redis"; | |
const userData: any = { | ||
name: "yvanna", | ||
username: "testuser", | ||
isVerified:true, | ||
email: "[email protected]", | ||
role:"seller", | ||
password: "test1234", | ||
|
@@ -22,6 +23,7 @@ const userData: any = { | |
const dummySeller = { | ||
name: "dummy1234", | ||
username: "username1234", | ||
isVerified:true, | ||
email: "[email protected]", | ||
password: "1234567890", | ||
}; | ||
|
@@ -30,6 +32,7 @@ const product:any = { | |
name: "pens", | ||
images: ["image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg"], | ||
stockQuantity: 8, | ||
|
||
price: 5000, | ||
discount: 3.5, | ||
categoryID: 1, | ||
|
@@ -38,6 +41,7 @@ const product:any = { | |
const dummyBuyer = { | ||
name: "test user", | ||
username: "testUser", | ||
isVerified:true, | ||
email: "[email protected]", | ||
password: "soleil00", | ||
} | ||
|
@@ -55,6 +59,7 @@ describe("Testing product Routes", () => { | |
await connect(); | ||
const testAdmin = { | ||
name: "admin123", | ||
isVerified:true, | ||
username: "admin123", | ||
email: "[email protected]", | ||
password: await bcrypt.hash("password", 10), | ||
|
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ let redisClient:any; | |
const userData: any = { | ||
name: "yvanna5", | ||
username: "testuser5", | ||
isVerified:true, | ||
email: "[email protected]", | ||
password: "test12345", | ||
}; | ||
|
@@ -31,11 +32,13 @@ const userData: any = { | |
const dummySeller = { | ||
name: "dummy1234", | ||
username: "username1234", | ||
isVerified:true, | ||
email: "[email protected]", | ||
password: "1234567890", | ||
}; | ||
const userTestData = { | ||
newPassword: "Test@123", | ||
isVerified:true, | ||
confirmPassword: "Test@123", | ||
wrongPassword: "Test456", | ||
}; | ||
|
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,93 @@ | ||
// emailTemplates/verifyUser.ts | ||
const verifyUserEmailTemplate = (username:string,verificationLink:string) => { | ||
return ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Verify Your Email</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f4f4f4; | ||
color: #333333; | ||
} | ||
.container { | ||
max-width: 600px; | ||
margin: 0 auto; | ||
padding: 20px; | ||
background-color: #ffffff; | ||
border-radius: 8px; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); | ||
} | ||
.header { | ||
text-align: center; | ||
padding-bottom: 20px; | ||
} | ||
.header img { | ||
max-width: 100px; | ||
} | ||
.content { | ||
font-size: 16px; | ||
line-height: 1.5; | ||
} | ||
.btn { | ||
display: inline-block; | ||
margin-top: 20px; | ||
padding: 10px 20px; | ||
background-color: #007bff; | ||
color: #ffffff; | ||
text-decoration: none; | ||
border-radius: 4px; | ||
} | ||
.footer { | ||
margin-top: 20px; | ||
font-size: 12px; | ||
color: #666666; | ||
text-align: center; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="header"> | ||
<img src="https://yourcompanylogo.com/logo.png" alt="Company Logo"> | ||
</div> | ||
<div class="content"> | ||
<h1>Welcome, ${username}!</h1> | ||
<p>Thank you for registering with us. Please verify your email address to complete your registration.</p> | ||
<p>Click the button below to verify your email address:</p> | ||
<a href="${verificationLink}" class="btn">Verify Email</a> | ||
<p>If the button above does not work, copy and paste the following link into your browser:</p> | ||
<p><a href="${verificationLink}">${verificationLink}</a></p> | ||
</div> | ||
<div class="footer"> | ||
<p>© 2024 Your Company Name. All rights reserved.</p> | ||
<p>If you did not register for this account, please ignore this email.</p> | ||
</div> | ||
</div> | ||
</body> | ||
</html> | ||
`; | ||
|
||
|
||
}; | ||
|
||
export default verifyUserEmailTemplate; | ||
|
||
|
||
export const generateEmailVerificationEmail = (Username:string)=> { | ||
return ` | ||
Dear ${Username}, | ||
Thank you for verifying your email address. You are now able to start using our system. ${"\n"} | ||
If you have any questions, feel free to reach out to our support team. | ||
${"\n"} | ||
Best regards, | ||
${"\n"} | ||
ATLP-eccommerce | ||
`; | ||
} |
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,16 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import User from '../sequelize/models/users'; | ||
|
||
export const isVerified = async (req: Request, res: Response, next: NextFunction) => { | ||
// @ts-ignore | ||
const { email} = req.body; | ||
const user = await User.findOne({ | ||
where:{ | ||
email:email | ||
} | ||
}); | ||
if (user?.isVerified === false) { | ||
return res.status(403).json({ message: 'Account is not verified' }); | ||
} | ||
next(); | ||
}; |
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
Oops, something went wrong.