Question

- Modify /login router to accept username and password as query string parameter - Read data...

- Modify /login router to accept username and password as query string parameter

- Read data from user.json file

- If username and passsword is valid then send resonse as below

{

status: true,

message: "User Is valid"

}

- If username is invalid then send resonse as below

{

status: false,

message: "User Name is invalid"

}

- If passsword is invalid then send resonse as below

{

status: false,

message: "Password is invalid"

}

*/

router.get('/login', (req,res) => {

res.send('This is login router');

});

user.json

"id":1,

"name":"Leanne Graham",

"username":"bret",

"password":"bret@123",

"email":"[email protected]",

"address":{

"street":"Kulas Light",

"suite":"Apt. 556",

"city":"Gwenborough",

"zipcode":"92998-3874",

"geo":{

"lat":"-37.3159",

"lng":"81.1496"

}

},

"phone":"1-770-736-8031 x56442",

"website":"hildegard.org",

"company":{

"name":"Romaguera-Crona",

"catchPhrase":"Multi-layered client-server neural-net",

"bs":"harness real-time e-markets"

}

}

Homework Answers

Answer #1

require json file in your file and set variable name to jsondata

router.get("/login", (req, res) => {

if (req.username === jsonData.username && req.password === jsonData.password)

res.status(200).json({

status: true,

message: "User Is valid"

});

else if (req.username === jsonData.username)

res.status(200).json({

status: false,

message: "Password is invalid"

});

else

res.status(200).json({

status: false,

message: "User Name is invalid"

});

});

 
 
 
 
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT