updated send email
This commit is contained in:
parent
cf993bf06a
commit
ab7b5136b5
2
.env
2
.env
@ -32,6 +32,8 @@ RAZERPAY_KEY_ID="rzp_test_2rg1Bq3Ki8xw9e"
|
||||
RAZERPAY_SECRET_KEY="WFhHbXL7AlLIuull9kKjYiNA"
|
||||
FRONTEND_URL="https://smellika.com"
|
||||
|
||||
PD_APP_URL="https://principal-distributer-cheminova.netlify.app"
|
||||
|
||||
|
||||
SEND_EMAIL_FROM="cheminova2004@gmail.com"
|
||||
#brevo send mail
|
||||
|
@ -13,7 +13,7 @@ const sendToken = (user, statusCode, res) => {
|
||||
|
||||
res.status(statusCode).cookie("token", token).json({
|
||||
// res.status(statusCode).json({
|
||||
|
||||
user,
|
||||
success: true,
|
||||
userId: user._id,
|
||||
|
||||
|
1153
package-lock.json
generated
1153
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -101,7 +101,11 @@ export const registerUser = async (req, res) => {
|
||||
await user.save();
|
||||
|
||||
// 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
|
||||
@ -123,18 +127,28 @@ export const registerUser = async (req, res) => {
|
||||
await user.save();
|
||||
|
||||
// Send email with the new user details
|
||||
if (user.role === "principal-Distributor") {
|
||||
await sendEmail({
|
||||
to: email,
|
||||
from: process.env.SEND_EMAIL_FROM,
|
||||
subject: `Cheminova Account Created`,
|
||||
html: `Your Principal Distributor Account is created successfully.
|
||||
html: `
|
||||
Your Principal Distributor Account is created successfully.
|
||||
<br/>Name: <strong>${name}</strong><br/>
|
||||
<br/>Mobile Number: <strong>${phone}</strong><br/>
|
||||
<br/>Password: <strong>${password}</strong><br/><br/>If you have not requested this email, please ignore it.`,
|
||||
<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
|
||||
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) {
|
||||
console.error(error);
|
||||
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);
|
||||
|
||||
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) {
|
||||
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;
|
||||
|
||||
await user.save();
|
||||
|
||||
sendToken(user, 200, res);
|
||||
|
Loading…
Reference in New Issue
Block a user