1 # Import modules for CGI handling
2
3 import cgi, cgitb
4
5 # import pymongo module for connecting to mongodb database
6 import pymongo
7 from pymongo import MongoClient
8
9 # Create instance of FieldStorage
10 form = cgi.FieldStorage()
11
12 # creating a mongo client to the running mongod instance
13 # The code will connect on the default host and port i.e 'localhost' and '27017'
14 client = MongoClient()
15
16 # selecting the database mydb
17 db_mydb = client.mydb
18
19 # selecting the collection user
20 collection_user = db_mydb.user
21
22 #print "Content-type:text/html\r\n\r\n"
23
24 # Get data from fields
25 email = form.getvalue('login-username')
26 password = form.getvalue('login-password')
27
28 #checking whether user inputs are correct or not
29 existence_query = collection_user.find_one({"_id":email,"password":password})
30
31
32 if(existence_query):
33 print "Location:http://localhost/mongo/index.html\r\n"
34 print "Content-type:text/html\r\n\r\n"
35 else:
36 print "Location:http://localhost/mongo/index.html\r\n"
37 print "Content-type:text/html\r\n\r\n"