Monday, August 18, 2014

M101J: MongoDB for Java Developers Homework 2.3

Homework 2.3 (MongoProc)

1) Step 1:
 you need to setup mongoproc.
Please read Instrcution for mongoproc setup.

2) Step 2:
Download  hw2.3.zip from download handout link

3) Step 3:
you can start script
run.sh
and visit the link http://localhost:8082 

4) Problem:
Problem is when you create a user, you will be redirected to welcome page
and when you logout you will not be able to login again.
goal of this homework is to complete the code in UserDAO.java file.

wherever there is xxx in code we will add java statement.

5) Solution:

open UserDAO.java

in addUser method

add following code in first // XXX WORK HERE
BasicDBObject user = new BasicDBObject("_id", username).append(
"password", passwordHash);

then add in 2nd // XXX WORK HERE
user.append("email", email);

then add in 3rd //XXX work here
usersCollection.insert(user); 

then in validateLogin method
add in 1st //XXX work here
user = usersCollection.findOne(new BasicDBObject("_id", username));


that it. you have change the code, now re - run run.sh

now you should be able to relogin in page. if it is successful

open mongoproc

click on homework 2.3(mongoproc). click on test. you will get feedback 

if it is sucessfull. click on turn in. your homework is submitted.
Enjoy :)

Any feedback welcome.


 

 

 

 

No comments:

Post a Comment