Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ exports.PASS = process.env.password
exports.CLIENT_ID = process.env.CLIENT_ID
exports.CLIENT_SECERET = process.env.CLIENT_SECERET
exports.REDIRECT_URI = process.env.REDIRECT_URI
exports.REFRESH_TOKEN = process.env.REFRESH_TOKEN
exports.REFRESH_TOKEN = process.env.REFRESH_TOKEN
exports.USER = process.env.USER
6 changes: 3 additions & 3 deletions controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ exports.forgetPass = async (req, res) => {

exports.updateuser = async (req, res) => {
try {
await userServices.updateuser1(req.data.email , req.body);
res.status(201).send({success: "true", message: "user updated successfully" });
const resp = await userServices.updateuser1(req.data.email , req.body);
res.status(201).send({success: "true", message: "user updated successfully", resposne:resp });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const resposne= await userServices.updateuser1(req.data.email , req.body);
res.status(201).send({success: "true", message: "user updated successfully", resposne});

a better way

} catch (error) {
res.status(402).send({success: "false", message: "user not updated" });
res.status(402).send({success: "false", message:"user not updated"});
}
};

Expand Down
11 changes: 11 additions & 0 deletions models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,16 @@ module.exports = (sequelize, DataTypes) => {
console.log(error)
}
});

User.beforeUpdate(async function(user){
try {
const salt = 10;
const hashedpassword = await bcrypt.hash(user.password, salt);
user.password = hashedpassword
} catch (error) {
console.log(error)
}
});

return User;
};
10 changes: 9 additions & 1 deletion routes/userRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ router.post("/auth/signin",controller.signin);
router.post("/address",mid.checkAuth,controller.user_address);
router.put("/delete",mid.checkAuth,controller.deluser);
router.put("/refresh",mid.verifyRT,controller.refreshuser);

router.put("/changePassword",mid.checkAuth,controller.changePass);
router.post("/forgot-password",controller.verifyuser);
router.put("/verify-reset-password",mid.checkAuth,controller.forgetPass);
router.put("/updateuser",mid.checkAuth,controller.updateuser);
router.get("/list/:page",controller.userlist);
router.put("/profile-image",mid.upload,controller.profileImg);
router.post("/fetch/flipkart/mobile",controller.flipkartMob);
router.post("/fetch/flipkart/mobile/all",controller.flipkartAllMob);
router.post("/fetch/snapdeal/t-shirt",controller.snapdealTshirt);

module.exports = router
21 changes: 10 additions & 11 deletions services/userservices.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ const transport = nodemailer.createTransport({
service:'gmail',
auth: {
type: 'OAuth2',
user: config.USERNAME,
user: config.USER,
clientId: config.CLIENT_ID,
clientSecret: config.CLIENT_SECERET,
refreshToken: config.REFRESH_TOKEN,
accessToken: accessToken
accessToken: accessToken()
},
});

Expand Down Expand Up @@ -57,20 +57,20 @@ await User.destroy({where:{id: id}})
}
};

const updateuser1 = async (data, body_data) => {
await users.updateOne(data.email, body_data);
const updateuser1 = async (email, body_data) => {
await User.update(body_data,{where:{email:email}});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if key and value are same in the object you need not to write both
await User.update(body_data,{where:{email}});

};

const matchpass = async (data) => {
return data.password === data.new_password;
};

const verifyemail = async (data) => {
const emailexist = await users.findOne({ email: data.email });
const emailexist = await User.findOne({where: {email: data.email}});

if (emailexist) {
const token = jwt.sign(
{ email: emailexist.email, id: emailexist._id },
{ email: emailexist.email,id:emailexist._id,username:emailexist.username },
config.ACCESS_TOKEN_SECRET,
{ expiresIn: config.FPASS_EXPIRESIN }
);
Expand All @@ -89,10 +89,9 @@ const verifyemail = async (data) => {
};

const modifyPass = async (email, data) => {
await users.updateOne(
{ email },
{
password: data.password,
await User.update({password: data.password},
{
where:{email:email}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous

}
);
const mailOption = {
Expand Down Expand Up @@ -152,7 +151,7 @@ const usersignup = async (data) => {
const user_list = async (page) => {
const firstindex = (page - 1) * 10;
const lastindex = page * 10;
const data = await users.find();
const data = await User.findAll();
const sliced_data = data.slice(firstindex, lastindex);
return sliced_data;
};
Expand Down