updated send email

This commit is contained in:
ROSHAN GARG 2024-07-26 16:08:18 +05:30
parent cf993bf06a
commit ab7b5136b5
4 changed files with 397 additions and 807 deletions

2
.env
View File

@ -32,6 +32,8 @@ RAZERPAY_KEY_ID="rzp_test_2rg1Bq3Ki8xw9e"
RAZERPAY_SECRET_KEY="WFhHbXL7AlLIuull9kKjYiNA" RAZERPAY_SECRET_KEY="WFhHbXL7AlLIuull9kKjYiNA"
FRONTEND_URL="https://smellika.com" FRONTEND_URL="https://smellika.com"
PD_APP_URL="https://principal-distributer-cheminova.netlify.app"
SEND_EMAIL_FROM="cheminova2004@gmail.com" SEND_EMAIL_FROM="cheminova2004@gmail.com"
#brevo send mail #brevo send mail

View File

@ -13,7 +13,7 @@ const sendToken = (user, statusCode, res) => {
res.status(statusCode).cookie("token", token).json({ res.status(statusCode).cookie("token", token).json({
// res.status(statusCode).json({ // res.status(statusCode).json({
user,
success: true, success: true,
userId: user._id, userId: user._id,

1153
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -101,7 +101,11 @@ export const registerUser = async (req, res) => {
await user.save(); await user.save();
// Respond with success and userId // Respond with success and userId
return res.status(200).json({ success: true, message: "User updated successfully", userId: user._id }); return res.status(200).json({
success: true,
message: "User updated successfully",
userId: user._id,
});
} }
// Create a new user if not found // Create a new user if not found
@ -123,18 +127,28 @@ export const registerUser = async (req, res) => {
await user.save(); await user.save();
// Send email with the new user details // Send email with the new user details
await sendEmail({ if (user.role === "principal-Distributor") {
to: email, await sendEmail({
from: process.env.SEND_EMAIL_FROM, to: email,
subject: `Cheminova Account Created`, from: process.env.SEND_EMAIL_FROM,
html: `Your Principal Distributor Account is created successfully. subject: `Cheminova Account Created`,
<br/>Name: <strong>${name}</strong><br/> html: `
<br/>Mobile Number: <strong>${phone}</strong><br/> Your Principal Distributor Account is created successfully.
<br/>Password: <strong>${password}</strong><br/><br/>If you have not requested this email, please ignore it.`, <br/>Name: <strong>${name}</strong><br/>
}); <br/>Mobile Number: <strong>${phone}</strong><br/>
<br/>Password: <strong>${password}</strong><br/><br/>
<a href="${process.env.PD_APP_URL}/login">Click here to login</a><br/><br/>
If you have not requested this email, please ignore it.
`,
});
}
// Respond with success and userId // Respond with success and userId
res.status(201).json({ success: true, message: "User created successfully", userId: user._id }); res.status(201).json({
success: true,
message: "User created successfully",
userId: user._id,
});
} catch (error) { } catch (error) {
console.error(error); console.error(error);
res.status(400).json({ success: false, message: error.message }); res.status(400).json({ success: false, message: error.message });
@ -360,15 +374,16 @@ export const updatePassword = catchAsyncErrors(async (req, res, next) => {
const isPasswordMatched = await user.comparePassword(req.body.oldPassword); const isPasswordMatched = await user.comparePassword(req.body.oldPassword);
if (!isPasswordMatched) { if (!isPasswordMatched) {
return next(new ErrorHander("Old password is incorrect", 400)); return res.status(400).json({ message: "Old password is incorrect" });
} }
if (req.body.newPassword !== req.body.confirmPassword) { if (req.body.newPassword !== req.body.confirmPassword) {
return next(new ErrorHander("password does not match", 400)); return res
.status(400)
.json({ message: "New Password and Confirm Password do not match" });
} }
user.password = req.body.newPassword; user.password = req.body.newPassword;
await user.save(); await user.save();
sendToken(user, 200, res); sendToken(user, 200, res);
@ -378,7 +393,7 @@ export const updatePassword = catchAsyncErrors(async (req, res, next) => {
export const updateProfile = catchAsyncErrors(async (req, res, next) => { export const updateProfile = catchAsyncErrors(async (req, res, next) => {
const newUserData = { const newUserData = {
name: req.body.name, name: req.body.name,
phone:req.body.phone, phone: req.body.phone,
email: req.body.email, email: req.body.email,
}; };