Beispiel #1
0
 def index(self, environ, start_response):
     #start_response("200 OK", [('Content-type', 'text/html')])
     username = ''
     # If a cookie exists, get it
     try:
         cookie_str = environ.get('HTTP_COOKIE', '')
         cookie = SimpleCookie(cookie_str)
         username = cookie["username"].value
         print "Login: Username = %s" % username
     except:
         #TODO change this from a broad exception
         print "session cookie not set! defaulting username"
         username = ''
     
     #If the cookie was found, redirect to main page, and set current user
     if username is not '':
         meeplib.set_curr_user(username)
         headers = [('Content-type', 'text/html')]
         headers.append(('Location','/main_page'))
         start_response("302 Found", headers)
         return "Cookie found, redirecting"
     #If the cookie wasn't found, prompt the user to login
     else:
         start_response("200 OK", [('Content-type', 'text/html')])
         return [ render_page('index.html') ]
Beispiel #2
0
    def test_main_page(self):
        environ = {}  # make a fake dict
        environ['PATH_INFO'] = '/main_page'

        u = meeplib.User('user', 'name')
        meeplib.set_curr_user(u.username)
        m = meeplib.Message('init title', 'init message', u, '!')

        def fake_start_response(status, headers):
            assert status == '200 OK'
            assert ('Content-type', 'text/html') in headers

        data = self.app(environ, fake_start_response)
        index = 0
        for m in data:
            if "Add Message" in m:
                index += 1
            if 'Create User' in m:
                index += 1
            if 'Logout' in m:
                index += 1
            if 'Show Messages' in m:
                index += 1

            #print m
        assert index is 4
Beispiel #3
0
    def test_main_page(self):
        environ = {}                    # make a fake dict
        environ['PATH_INFO'] = '/main_page'

        u = meeplib.User('user', 'name')
        meeplib.set_curr_user(u.username)
        m = meeplib.Message('init title', 'init message', u ,'!')

        def fake_start_response(status, headers):
            assert status == '200 OK'
            assert ('Content-type', 'text/html') in headers

        data = self.app(environ, fake_start_response)
        index = 0
        for m in data:
            if "Add Message" in m:
                index += 1
            if 'Create User' in m:
                index += 1
            if 'Logout' in m:
                index += 1
            if 'Show Messages' in m:
                index += 1

            #print m
        assert index is 4
Beispiel #4
0
    def login(self, environ, start_response):
        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        returnStatement = "logged in"
        try:
            username = form['username'].value
        except KeyError:
            username = None
        try:
            password = form['password'].value
        except KeyError:
            password = None
        
        k = ''
        v = ''
        print "USERNAME: "******"!"

        # Test whether variable is defined to be None
        if username is not None:
             if password is not None:
                 if meeplib.check_user(username, password) is False:
                     k = 'Location' 
                     v = '/'
                     returnStatement = """<p>Invalid user.  Please try again.</p>"""
           
                 else:
                     new_user = meeplib.User(username, password)
                     meeplib.set_curr_user(username)
                     k = 'Location'
                     v = '/main_page'
             else:      
                 returnStatement = """<p>password was not set. User could not be created</p>"""
        else:
            returnStatement = """<p>username was not set. User could not be created</p>"""

        #print """isValidafter: %s """ %(meeplib.check_user(username, password),)

        # set content-type
        headers = [('Content-type', 'text/html')]

        if returnStatement is "logged in":
            c = SimpleCookie()
            cookie_name, cookie_val = make_set_cookie_header('username', username)
            headers.append((cookie_name, cookie_val))
            print cookie_name + cookie_val
            
       
        headers.append((k, v))
        start_response('302 Found', headers)
        
        #return self.main_page(environ, start_response)
        return returnStatement   
Beispiel #5
0
    def login(self, environ, start_response):
        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        returnStatement = "logged in"
        try:
            username = form['username'].value
        except KeyError:
            username = None
        try:
            password = form['password'].value
        except KeyError:
            password = None

        k = ''
        v = ''
        print "USERNAME: "******"!"

        # Test whether variable is defined to be None
        if username is not None:
            if password is not None:
                if meeplib.check_user(username, password) is False:
                    k = 'Location'
                    v = '/'
                    returnStatement = """<p>Invalid user.  Please try again.</p>"""

                else:
                    new_user = meeplib.User(username, password)
                    meeplib.set_curr_user(username)
                    k = 'Location'
                    v = '/main_page'
            else:
                returnStatement = """<p>password was not set. User could not be created</p>"""
        else:
            returnStatement = """<p>username was not set. User could not be created</p>"""

        #print """isValidafter: %s """ %(meeplib.check_user(username, password),)

        # set content-type
        headers = [('Content-type', 'text/html')]

        if returnStatement is "logged in":
            c = SimpleCookie()
            cookie_name, cookie_val = make_set_cookie_header(
                'username', username)
            headers.append((cookie_name, cookie_val))
            print cookie_name + cookie_val

        headers.append((k, v))
        start_response('302 Found', headers)

        #return self.main_page(environ, start_response)
        return returnStatement
Beispiel #6
0
    def login(self, environ, start_response):
        try:
            cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
            username = cookie["username"].value
            #print "Username = %s" % username
        except:
            #print "session cookie not set! defaulting username"
            username = ''

        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        returnStatement = "logged in"
        try:
            username = form['username'].value
        except KeyError:
            username = None
        try:
            password = form['password'].value
        except KeyError:
            password = None
        k = 'Location'
        v = '/'

        # set content-type
        headers = [('Content-type', 'text/html')]

        # Test whether variable is defined to be None
        if username is not None:
            if password is not None:
                if meeplib.check_user(username, password) is True:
                    new_user = meeplib.User(username, password)
                    meeplib.set_curr_user(username)
                    # set the cookie to the username string
                    cookie_name, cookie_val = meepcookie.make_set_cookie_header(
                        'username', username)
                    headers.append((cookie_name, cookie_val))
                else:
                    returnStatement = """<p>Invalid user.  Please try again.</p>"""

            else:
                returnStatement = """<p>password was not set. User could not be created</p>"""
        else:
            returnStatement = """<p>username was not set. User could not be created</p>"""

        print """isValidafter: %s """ % (meeplib.check_user(
            username, password), )

        headers.append((k, v))
        start_response('302 Found', headers)

        return "no such content"
Beispiel #7
0
    def login(self, environ, start_response):
        try:
            cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
            username = cookie["username"].value
            #print "Username = %s" % username
        except:
            #print "session cookie not set! defaulting username"
            username = ''

        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        returnStatement = "logged in"
        try:
            username = form['username'].value
        except KeyError:
            username = None
        try:
            password = form['password'].value
        except KeyError:
            password = None
        k = 'Location'
        v = '/'

        # set content-type
        headers = [('Content-type', 'text/html')]

        # Test whether variable is defined to be None
        if username is not None:
             if password is not None:
                 if meeplib.check_user(username, password) is True:
                     new_user = meeplib.User(username, password)
                     meeplib.set_curr_user(username)
                     # set the cookie to the username string
                     cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',username)
                     headers.append((cookie_name, cookie_val))
                 else:
                     returnStatement = """<p>Invalid user.  Please try again.</p>"""

             else:      
                 returnStatement = """<p>password was not set. User could not be created</p>"""
        else:
            returnStatement = """<p>username was not set. User could not be created</p>"""

        print """isValidafter: %s """ %(meeplib.check_user(username, password),)

       
        headers.append((k, v))
        start_response('302 Found', headers)
        
        return "no such content"    
Beispiel #8
0
    def login(self, environ, start_response):
        try:
            cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
            username = cookie["username"].value

        except:
            username = ""
        print environ["wsgi.input"]
        form = cgi.FieldStorage(fp=environ["wsgi.input"], environ=environ)
        returnStatement = "You are now logged in."
        try:
            username = form["username"].value
        except KeyError:
            username = None
        try:
            password = form["password"].value
        except KeyError:
            password = None
        k = "Location"
        v = "/"
        headers = [("Content-type", "text/html")]
        # Test whether variable is defined to be None
        if username is not None:
            if password is not None:
                if meeplib.check_user(username, password) is True:
                    new_user = meeplib.User(username, password)
                    meeplib.set_curr_user(username)
                    cookie_name, cookie_value = meepcookie.make_set_cookie_header("username", username)
                    headers.append((cookie_name, cookie_value))
                    # k = 'Location'
                    # v = '/home_page'
                else:
                    # k = 'Location'
                    # v = '/'
                    returnStatement = """<p>Invalid user.  Please try again.</p>"""

            else:
                returnStatement = """<p>password was not set. User could not be created</p>"""
        else:
            returnStatement = """<p>username was not set. User could not be created</p>"""

        print """isValidafter: %s """ % (meeplib.check_user(username, password),)

        # set content-type

        headers.append((k, v))
        start_response("302 Found", headers)

        return "no such content"
Beispiel #9
0
    def login(self, environ, start_response):
        try:
            cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
            username = cookie["username"].value
        except:
            username = ''

        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        returnStatement = "Logged In"
        try:
            username = form['username'].value
        except KeyError:
            username = None
        try:
            password = form['password'].value
        except KeyError:
            password = None
        k = 'Location'
        v = '/'
        headers = [('Content-type', 'text/html')]

        # Check to see if defined as None
        if username is not None:
             if password is not None:
                 if meeplib.check_user(username, password) is True:
                     new_user = meeplib.User(username, password)
                     meeplib.set_curr_user(username)
					 
                     #set the cookie to the username
                     cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',username)
                     headers.append((cookie_name, cookie_val))
                 else:
                     returnStatement = """<p>You entered a Higgs boson user. You do not exist(yet). Please try again.</p>"""

             else:      
                 returnStatement = """<p>Password was not set. User was not created.</p>"""
        else:
            returnStatement = """<p>Username was not set. User was not created</p>"""

        print """isValidafter: %s """ %(meeplib.check_user(username, password),)

       
        headers.append((k, v))
        start_response('302 Found', headers)
        
        return "The content is a Higgs boson."    
Beispiel #10
0
    def list_messages(self, environ, start_response):
        user = meeplib.get_curr_user();
        meeplib._reset()
        meeplib.set_curr_user(user)
        conn = sqlite3.connect('meep.db')
        c = conn.cursor()
        for row in c.execute("SELECT * FROM Message"):
            print row
            meeplib.Message(row[0], row[1], row[2], row[3])
        

        messages = meeplib.get_all_messages()
           
        headers = [('Content-type', 'text/html')]
        start_response("200 OK", headers)
        
        return [render_page('list_messages.html', messages=messages)]
Beispiel #11
0
    def login(self, environ, start_response):
        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        returnStatement = "logged in"
        try:
            username = form['username'].value
        except KeyError:
            username = None
        try:
            password = form['password'].value
        except KeyError:
            password = None
        k = 'Location'
        v = '/'
        # Test whether variable is defined to be None
        if username is not None:
            if password is not None:
                if meeplib.check_user(username, password) is True:
                    new_user = meeplib.User(username, password)
                    meeplib.set_curr_user(username)
                    k = 'Location'
                    v = '/home_page'
                else:
                    k = 'Location'
                    v = '/'
                    returnStatement = """<p>Invalid user.  Please try again.</p>"""

            else:
                returnStatement = """<p>password was not set. User could not be created</p>"""
        else:
            returnStatement = """<p>username was not set. User could not be created</p>"""

        print """isValidafter: %s """ % (meeplib.check_user(
            username, password), )

        # set content-type
        headers = [('Content-type', 'text/html')]

        headers.append((k, v))
        start_response('302 Found', headers)

        return "no such content"
Beispiel #12
0
    def test_add_reply(self):
        environ = {}                    # make a fake dict
        environ['PATH_INFO'] = '/m/list'
        u = meeplib.User('foo', 'bar')
        m = meeplib.Message('the title', 'the content', u ,'!')
        n = meeplib.Message('the reply title', 'the reply', u, m.id)
        o = meeplib.Message('the 2nd title', 'the 2nd reply', u, n.id)

        assert n.id in m.replies
        assert o.id in n.replies

        meeplib.set_curr_user(u.username)
        def fake_start_response(status, headers):
            assert status == '200 OK'
            assert ('Content-type', 'text/html') in headers

        data = self.app(environ, fake_start_response)
        index = 0
        '''print data[0]
Beispiel #13
0
    def login(self, environ, start_response):
        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        returnStatement = "logged in"
        try:
            username = form['username'].value
        except KeyError:
            username = None
        try:
            password = form['password'].value
        except KeyError:
            password = None
        k = 'Location'
        v = '/'
        # Test whether variable is defined to be None
        if username is not None:
             if password is not None:
                 if meeplib.check_user(username, password) is True:
                     new_user = meeplib.User(username, password)
                     meeplib.set_curr_user(username)
                     k = 'Location'
                     v = '/home_page'
                 else:
                     k = 'Location'
                     v = '/'
                     returnStatement = """<p>Invalid user.  Please try again.</p>"""

             else:      
                 returnStatement = """<p>password was not set. User could not be created</p>"""
        else:
            returnStatement = """<p>username was not set. User could not be created</p>"""

        print """isValidafter: %s """ %(meeplib.check_user(username, password),)

        # set content-type
        headers = [('Content-type', 'text/html')]
       
        headers.append((k, v))
        start_response('302 Found', headers)
        
        return "no such content"    
Beispiel #14
0
    def test_add_reply(self):
        environ = {}  # make a fake dict
        environ['PATH_INFO'] = '/m/list'
        u = meeplib.User('foo', 'bar')
        m = meeplib.Message('the title', 'the content', u, '!')
        n = meeplib.Message('the reply title', 'the reply', u, m.id)
        o = meeplib.Message('the 2nd title', 'the 2nd reply', u, n.id)

        assert n.id in m.replies
        assert o.id in n.replies

        meeplib.set_curr_user(u.username)

        def fake_start_response(status, headers):
            assert status == '200 OK'
            assert ('Content-type', 'text/html') in headers

        data = self.app(environ, fake_start_response)
        index = 0
        '''print data[0]
Beispiel #15
0
    def login(self, environ, start_response):
        print "enter login"
        username = check_cookie(environ)
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
        returnStatement = "logged in"
        try:
            username = form['username'].value
        except KeyError:
            username = None
        try:
            password = form['password'].value
        except KeyError:
            password = None
        k = 'Location'
        v = '/'
        headers = [('Content-type', 'text/html')]
        if username is not None:
            if password is not None:
                if meeplib.check_user(username, password) is True:
                    new_user = meeplib.User(username, password)
                    meeplib.set_curr_user(username)
                    # set the cookie to the username string
                    cookie_name, cookie_val = meepcookie.make_set_cookie_header(
                        'username', username)
                    headers.append((cookie_name, cookie_val))
                else:
                    returnStatement = """<p>invalid user,	please try again.</p>"""
            else:
                returnStatement = """<p>password was not set; user was not created</p>"""
        else:
            returnStatement = """<p>username was not set; user was not created</p>"""
        print """isValidafter: %s """ % (meeplib.check_user(
            username, password), )
        headers.append((k, v))
        start_response('302 Found', headers)

        print returnStatement
        print "exit login"
        return "no such content"
Beispiel #16
0
    def login(self, environ, start_response):
        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        username = form['username'].value
        password = form['password'].value

        # set content-type
        headers = [('Content-type', 'text/html')]

        k = 'Location'
        v = '/'

        # Test whether variable is defined to be None
        # No idea why these tests don't work... the None value from the form is viewed as a string
        if username != "None":
             if password != "None":
                 if meeplib.check_user(username, password) is False:
                     returnStatement = """Invalid login"""
           
                 else:
                     meeplib.set_curr_user(username)
                     k = 'Location'
                     v = '/main_page'
                     # Create and set the cookie
                     cookie_name, cookie_val = meepcookie.make_set_cookie_header('username', username)
                     headers.append((cookie_name, cookie_val))
                     print cookie_name, cookie_val
                     returnStatement = """Login successful"""
             else:      
                 returnStatement = """password none"""
        else:
            returnStatement = """username none"""

        headers.append((k, v))
        start_response('302 Found', headers)
        
        return returnStatement
Beispiel #17
0
	def login(self, environ, start_response):
		print "enter login"
		username = check_cookie(environ)
		form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
		returnStatement = "logged in"
		try:
			username = form['username'].value
		except KeyError:
			username = None
		try:
			password = form['password'].value
		except KeyError:
			password = None
		k = 'Location'
		v = '/'
		headers = [('Content-type', 'text/html')]
		if username is not None:
			 if password is not None:
				 if meeplib.check_user(username, password) is True:
					 new_user = meeplib.User(username, password)
					 meeplib.set_curr_user(username)
					 # set the cookie to the username string
					 cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',username)
					 headers.append((cookie_name, cookie_val))
				 else:
					 returnStatement = """<p>invalid user,	please try again.</p>"""
			 else:		
				 returnStatement = """<p>password was not set; user was not created</p>"""
		else:
			returnStatement = """<p>username was not set; user was not created</p>"""
		print """isValidafter: %s """ %(meeplib.check_user(username, password),)
		headers.append((k, v))
		start_response('302 Found', headers)

		print returnStatement
		print "exit login"
		return "no such content"	
Beispiel #18
0
    def login(self, environ, start_response):
        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        returnStatement = "logged in"
        try:
            username = form['username'].value
        except KeyError:
            username = None
        try:
            password = form['password'].value
        except KeyError:
            password = None
        
        k = ''
        v = ''

        conn = sqlite3.connect('meep.db')
        c = conn.cursor()
        if username and password:
            c.execute("SELECT * FROM Users WHERE username = '******' AND password = '******'")
            if c.fetchone():
                k = 'Location'
                v = '/main_page'
                returnStatement = "logged in"
                meeplib.set_curr_user(username)
        else:
            k = 'Location' 
            v = '/'
            returnStatement = """<p>Invalid user.  Please try again.</p>"""
            

        # Test whether variable is defined to be None
        #if username is not None:
        #     if password is not None:
        #         if meeplib.check_user(username, password) is False:
        #             k = 'Location' 
        #             v = '/'
        #             returnStatement = """<p>Invalid user.  Please try again.</p>"""
        #   
        #         else:
        #             new_user = meeplib.User(username, password)
        #             meeplib.set_curr_user(username)
        #             k = 'Location'
        #             v = '/main_page'
        #     else:      
        #         returnStatement = """<p>password was not set. User could not be created</p>"""
        #else:
        #    returnStatement = """<p>username was not set. User could not be created</p>"""

        #print """isValidafter: %s """ %(meeplib.check_user(username, password),)

        # set content-type
        headers = [('Content-type', 'text/html')]

        if returnStatement is "logged in":
            c = SimpleCookie()
            cookie_name, cookie_val = make_set_cookie_header('username', username)
            headers.append((cookie_name, cookie_val))
            print cookie_name + cookie_val
            
       
        headers.append((k, v))
        start_response('302 Found', headers)
        print "everything seems to be working up till now..."
        #return self.main_page(environ, start_response)
        return returnStatement