-
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.
reset password server code completed
- Loading branch information
Showing
10 changed files
with
183 additions
and
54 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 |
---|---|---|
|
@@ -38,3 +38,4 @@ pnpm-debug.log* | |
*.sw? | ||
|
||
# Mac | ||
.vercel |
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,68 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Reset Your Password</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f0f0f0; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
.email-container { | ||
max-width: 600px; | ||
margin: 40px auto; | ||
background-color: #ffffff; | ||
padding: 30px; | ||
border-radius: 10px; | ||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1); | ||
} | ||
h1 { | ||
color: #2c3e50; | ||
font-size: 26px; | ||
margin-bottom: 20px; | ||
} | ||
p { | ||
color: #7f8c8d; | ||
font-size: 16px; | ||
line-height: 1.6; | ||
} | ||
.reset-link { | ||
display: inline-block; | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
color: #ffffff; | ||
background-color: #e74c3c; | ||
border-radius: 5px; | ||
text-decoration: none; | ||
margin: 20px 0; | ||
} | ||
.footer { | ||
margin-top: 30px; | ||
font-size: 14px; | ||
color: #95a5a6; | ||
text-align: center; | ||
} | ||
.warning { | ||
color: #e67e22; | ||
font-size: 14px; | ||
margin-top: 10px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="email-container"> | ||
<h1>Hello, {{name}}!</h1> | ||
<p>We received a request to reset your password. You can reset your password by clicking the button below:</p> | ||
<a href="{{resetLink}}" class="reset-link">Reset Password</a> | ||
<p>This link is valid for only <strong>1 hour</strong>. Please make sure to use it before it expires.</p> | ||
<p class="warning">If you did not request a password reset, please ignore this email or contact our support team immediately.</p> | ||
<div class="footer"> | ||
<p>Best regards,<br><strong>AVM Ayurvedic</strong></p> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
6 changes: 3 additions & 3 deletions
6
...re/database/repositories/OtpRepository.ts → ...rastructure/repositories/OtpRepository.ts
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
8 changes: 4 additions & 4 deletions
8
...atabase/repositories/PatientRepository.ts → ...ructure/repositories/PatientRepository.ts
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,35 +1,60 @@ | ||
import IEmailService from "../../interface/services/IEmailService"; | ||
import nodemailer from "nodemailer"; | ||
import {promisify} from 'util' | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
import { promisify } from "util"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const readFileAsync = promisify(fs.readFile); | ||
|
||
export default class EmailService implements IEmailService{ | ||
|
||
async sendOtp(email: string, name: string, otp: number): Promise<void> { | ||
let htmlTemplate = await readFileAsync(path.join(__dirname, '../../../public/otpEmailTemplate.html'), 'utf-8'); | ||
|
||
htmlTemplate = htmlTemplate.replace('{{name}}', name); | ||
htmlTemplate = htmlTemplate.replace('{{otp}}', otp.toString()); | ||
|
||
const transporter = nodemailer.createTransport({ | ||
service: 'gmail', | ||
auth: { | ||
user: process.env.SENDER_EMAIL, | ||
pass: process.env.NODEMAILER_PASSKEY, | ||
}, | ||
}); | ||
|
||
await transporter.sendMail({ | ||
from: process.env.SENDER_MAIL, | ||
to: email, | ||
subject: 'Your OTP for Verification', | ||
html: htmlTemplate, | ||
}); | ||
|
||
} | ||
|
||
export default class EmailService implements IEmailService { | ||
async sendOtp(email: string, name: string, otp: number): Promise<void> { | ||
let htmlTemplate = await readFileAsync(path.join(__dirname, "../../../public/otpEmailTemplate.html"), "utf-8"); | ||
|
||
htmlTemplate = htmlTemplate.replace("{{name}}", name); | ||
htmlTemplate = htmlTemplate.replace("{{otp}}", otp.toString()); | ||
|
||
const transporter = nodemailer.createTransport({ | ||
service: "gmail", | ||
auth: { | ||
user: process.env.SENDER_EMAIL, | ||
pass: process.env.NODEMAILER_PASSKEY, | ||
}, | ||
}); | ||
|
||
const id = await transporter.sendMail({ | ||
from: process.env.SENDER_MAIL, | ||
to: email, | ||
subject: "No Reply Mail: Otp Verification", | ||
html: htmlTemplate, | ||
}); | ||
|
||
console.log(id.messageId); | ||
|
||
} | ||
|
||
async sendResetMail(email: string, name: string, resetLink: string): Promise<void> { | ||
let htmlTemplate = await readFileAsync( | ||
path.join(__dirname, "../../../public/resetPasswordTemplate.html"), | ||
"utf-8" | ||
); | ||
|
||
htmlTemplate = htmlTemplate.replace("{{name}}", name); | ||
htmlTemplate = htmlTemplate.replace("{{resetLink}}", resetLink); | ||
|
||
const transporter = nodemailer.createTransport({ | ||
service: "gmail", | ||
auth: { | ||
user: process.env.SENDER_EMAIL, | ||
pass: process.env.NODEMAILER_PASSKEY, | ||
}, | ||
}); | ||
|
||
const mail = await transporter.sendMail({ | ||
from: process.env.SENDER_MAIL, | ||
to: email, | ||
subject: "No Reply Mail: Password Reset", | ||
html: htmlTemplate, | ||
}); | ||
|
||
}; | ||
} |
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,3 +1,4 @@ | ||
export default interface IEmailService { | ||
sendOtp(email: string, name: string, otp: number): Promise<void>; | ||
sendResetMail(email:string,name:string,resetLink:string):Promise<void>; | ||
} |
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
771c6b6
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.
Successfully deployed to the following URLs:
avm-care – ./
avm-care-git-main-sinans-projects-8d312afe.vercel.app
avm-care.vercel.app
avm-care-sinans-projects-8d312afe.vercel.app