-
Couldn't load subscription status.
- Fork 0
worked on question2 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: new_branch3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,15 +19,14 @@ exports.checkAuth = async (req, res, next) => { | |
| if (typeof bearerHeader !== "undefined") { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. improve else if conditions here doesn't look good here |
||
| const bearer = bearerHeader.split(" "); | ||
| const token = bearer[1]; | ||
| const {email}=jwt.verify(token, config.secretKey); | ||
| const {email,id}=jwt.verify(token, config.secretKey); | ||
| if(email){ | ||
| req.data= {email, token} | ||
| req.data= {email, token, id} | ||
| next(); | ||
| }else{ | ||
| res.status(403).send({"success":"false", msg:"email not found in token"}) | ||
| next(); | ||
| } | ||
|
|
||
| } else { | ||
| res.status(401).send({"success":"false", msg:"email not found in token"}) | ||
| next(); | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| const mongoose=require("mongoose"); | ||
| const userModel = require("./userModel"); | ||
| const user = mongoose.Schema({ | ||
| user_id:{ | ||
| type:'ObjectId', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. createdat and updated At field should be there |
||
| required:true, | ||
| ref: 'userModel' | ||
| }, | ||
| address:{ | ||
| type:String | ||
| }, | ||
| city:{ | ||
| type:String | ||
| }, | ||
| state:{ | ||
| type:String | ||
| }, | ||
| pin_code:{ | ||
| type:Number | ||
| }, | ||
| phone:{ | ||
| type:Number | ||
| } | ||
| }); | ||
|
|
||
| module.exports = mongoose.model("useraddress",user) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,14 @@ router.use('/changePassword',mid_register.checkAuth) | |
| router.use('/updateuser',mid_register.checkAuth) | ||
| router.use('/get',mid_register.checkAuth) | ||
| router.use('/delete',mid_register.checkAuth) | ||
| router.use('/address',mid_register.checkAuth) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move middleware in separate file instead route |
||
| router.use('/verify-reset-password',mid_register.checkAuth) | ||
|
|
||
| router.get("/register",mid_register.REG_MIDDLE,userController.signup); | ||
| router.get("/get",userController.getuser); | ||
| router.get("/list/:page",userController.userlist); | ||
| router.post("/auth/signin",userController.login_user); | ||
| router.post("/address",userController.user_address); | ||
| router.put("/changePassword",userController.changePass); | ||
| router.put("/verify-reset-password",userController.forgetPass); | ||
| router.put("/updateuser",userController.updateuser); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,10 @@ const jwt = require("jsonwebtoken"); | |
| const bcrypt = require("bcryptjs"); | ||
| const users = require("../model/userModel"); | ||
| const userToken = require("../model/userToken"); | ||
| const useradd = require("../model/address"); | ||
|
|
||
| const getdata= async ({email})=>{ | ||
| return await users.findOne(email); | ||
| const getdata= async (id)=>{ | ||
| return await users.findOne({_id:id}).populate("address") | ||
| } | ||
|
|
||
| const deleteuser = async ()=>{ | ||
|
|
@@ -54,7 +55,7 @@ const modifyPass = async(email,data) =>{ | |
|
|
||
| const userlogin = async(data) =>{ | ||
| const userData = await users.findOne({ email: data.email }); | ||
| const pass = (userData.password === data.password) | ||
| const pass = bcrypt.compare(userData.password , data.password) | ||
|
|
||
| if(pass && userData){ | ||
| const token = jwt.sign( | ||
|
|
@@ -91,6 +92,23 @@ const user_list = async (page)=>{ | |
| const sliced_data = data.slice(firstindex, lastindex); | ||
| return sliced_data; | ||
| } | ||
|
|
||
| const useraddress = async (data,ID) => { | ||
| let user = new useradd({ | ||
| user_id: ID, | ||
| address: data.address, | ||
| city: data.city, | ||
| state: data.state, | ||
| pin_code: data.pin_code, | ||
| phone: data.phone | ||
| }); | ||
| if(user){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are you checking user here ? you need to verify data |
||
| await user.save(); | ||
| // await user.findByIdAndUpdate({}) | ||
| }else{ | ||
| return false; | ||
| } | ||
| }; | ||
| module.exports={ | ||
| getdata, | ||
| deleteuser, | ||
|
|
@@ -100,5 +118,6 @@ module.exports={ | |
| verifyemail, | ||
| user_list, | ||
| userlogin, | ||
| usersignup | ||
| usersignup, | ||
| useraddress | ||
| } | ||
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.
use classes or object and keep everything inside it a lot of import like this doesn't look good