Vous êtes sur la page 1sur 3

(/)

Courses (/courses) Help (/help) About (/about) Blog (http://ed-blog.mongodb.com/) DMAKETAS (/DASHBOARD)

M101J: MongoDB for Java Developers


Courseware (/courses/10gen/M101J/2013_October/courseware) Discussion (/courses/10gen/M101J/2013_October/discussion/forum) Progress (/courses/10gen/M101J/2013_October/progress) Course Info (/courses/10gen/M101J/2013_October/info) Wiki (/courses/10gen/M101J/2013_October/course_wiki)

SEARCH

Homework: Homework 2.3


Blog User Sign-up and Login Download hw2.3.zip (/static/m101j-october-2013/handouts/hw2-3.7f0c86868288.zip) or hw2.3.tar (/static/m101j-october2013/handouts/hw2-3.a7c14526bec0.tar) and unpack. This is the beginning of the blog project with the UI for creating an logging in blog authors, but nothing to display posts. There is a pom.xml file that describes the project. The project roughly follows the model/view/controller paradigm. BlogController.java is the controller and the model. The templates comprise the view. Here is a description of the directories and files.
/ s r c / m a i n / j a v a / c o u r s e-c o n t a i n ss o u r c ec o d e / s r c / m a i n / r e s o u r c e s / f r e e m a r k e r-c o n t a i n st e m p l a t e s v a l i d a t e . p y-t h ep y t h o ns c r i p tt h a tw i l lv a l i d a t ey o ug o ti tr i g h t r u n . s h-t h em v nc o m m a n dt h a ts t a r t si tr u n n i n gi fy o ud o n ' tw a n tt ou s ea nI D E

If everything is working properly, you should be able to start the blog by typing:
m v nc o m p i l ee x e c : j a v aD e x e c . m a i n C l a s s = c o u r s e . B l o g C o n t r o l l e r

If you goto http://localhost:8082 (http://localhost:8082/) you should see a message this is a placeholder for the blog Here are some URLs that must work when you are done.

h t t p : / / l o c a l h o s t : 8 0 8 2 / s i g n u p h t t p : / / l o c a l h o s t : 8 0 8 2 / l o g i n h t t p : / / l o c a l h o s t : 8 0 8 2 / l o g o u t

When you login or sign-up, the blog will redirect to http://localhost:8082/welcome and that must work properly, welcoming the user by username We have removed four Java statements from UserDAO and marked the areas where you need to work with XXX. You should not need to touch any other code. The java statements that you are going to add will add a new user upon sign-up and validate a login by retrieving the right user document. The blog stores its data in the blog database in two collections, users and sessions. Here are two example docs for a username erlichson with password fubar. You can insert these if you like, but you dont need to.
>d b . u s e r s . f i n d ( ) {" _ i d ":" e r l i c h s o n " ," p a s s w o r d ":" V H 9 I F u + / v U N S K T z Z s F Z E O s K 1 , 1 9 2 4 2 6 1 3 3 0 "} >

>d b . s e s s i o n s . f i n d ( ) {" _ i d ":" A N 4 M 7 w a r H + f d K O s z U 8 q n d 2 H m f n 8 J Z F F Z 9 s f f 4 z c P R p w = " ," u s e r n a m e ":" e r l i c h s o n "} >

Once you have the the project working, the following steps should work: go to http://localhost:8082/signup create a user It should redirect you to the welcome page and say: welcome username, where username is the user you signed up with. Now Goto http://localhost:8082/logout Now login http://localhost:8082/login.

Ok, now its time to validate you got it all working. There was one additional program that should have been downloaded in the project called validate.py.
p y t h o nv a l i d a t e . p y

If you got it right, it will provide a validation code for you to enter into the box below. Enter just the code, no spaces. Notes on validation The Python validation script requires the following python modules be installed on your computer: pymongo, urllib, urllib2, and cookielib. A typical Python installation will already have most of these installed except pymongo. If you have python-setuptools installed, the command "easy_install" makes this simple. Any other missing packages will show up when validate.py is run, and can be installed in a similar fashion.
$e a s y _ i n s t a l lp y m o n g o

Alternative Java-based Validation We also have an alternative validation program written in Java. If you are having trouble getting the Python one to work due to issues with your Python installation, you can try this. Start by downloading Validate.zip (/static/m101j-october2013/handouts/Validate.609667b39521.zip) into a directory. Now cd to that directory and issue the following command
j a v aj a rV a l i d a t e . j a r

Remember to enter just the validation code below and submit.


1

fhj837hf9376hgf93hf832jf9 HIDE ANSWER You have used 0 of 3 submissions

HIDE ANSWER

You have used 0 of 3 submissions

Products & Services (http://www.mongodb.com/products/mongodb) Events (http://www.mongodb.com/events) Partners (http://www.mongodb.com/partners) Customers (http://www.mongodb.com/customers) About MongoDB (http://www.mongodb.com/about) Contact Us (/contact) Careers (http://www.mongodb.com/careers)

(https://twitter.com/mongodbinc)

(http://www.facebook.com/mongodb)

(http://www.linkedin.com/company/783611)

(https://plus.google.com/101024085748034940765/posts) (http://edx.org) (http://www.mongodb.com)


2013 MongoDB, Inc. MongoDB, Mongo, and the leaf logo are registered trademarks of MongoDB Inc.

Vous aimerez peut-être aussi