-
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 6dda574
Showing
11 changed files
with
279 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
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,92 @@ | ||
// 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. | ||
If you have any questions, feel free to reach out to our support team. | ||
Best regards, | ||
Your Company Name | ||
`; | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/sequelize/migrations/h20240519174339-add-is-verified.js
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,23 @@ | ||
'use strict'; | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
const isVerifiedColumnExists = await queryInterface.describeTable("users").then((columns) => { | ||
return "isAvailable" in columns; | ||
}); | ||
|
||
if (!isVerifiedColumnExists) { | ||
await queryInterface.addColumn("users", "isVerified", { | ||
type: Sequelize.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: false, | ||
}); | ||
} | ||
}, | ||
|
||
async down(queryInterface, Sequelize) { | ||
await queryInterface.removeColumn("users", "isVerified"); | ||
}, | ||
}; | ||
|
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 |
---|---|---|
|
@@ -30,6 +30,7 @@ module.exports = { | |
email: "[email protected]", | ||
password: await bcrypt.hash("soleil00", 10), | ||
roleId: 3, | ||
isVerified:true, | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}, | ||
|
@@ -39,6 +40,7 @@ module.exports = { | |
email: "[email protected]", | ||
password: await bcrypt.hash("soleil00", 10), | ||
roleId: 1, | ||
isVerified:true, | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}, | ||
|
@@ -48,6 +50,7 @@ module.exports = { | |
email: "[email protected]", | ||
password: await bcrypt.hash("Test@123", 10), | ||
roleId: 2, | ||
isVerified:true, | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}, | ||
|
@@ -57,6 +60,7 @@ module.exports = { | |
email: "[email protected]", | ||
password: await bcrypt.hash("Test@123", 10), | ||
roleId: 2, | ||
isVerified:true, | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
}, | ||
|
Oops, something went wrong.