Exemple #1
0
    def logout(self, environ, start_response):
        # get cookie if there is one
        try:
            cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
            username = cookie["username"].value
            #print "Username = %s" % username
        except:
            #print "session cookie not set! defaulting username"
            username = ''
        
        user = meeplib.get_user(username)
        if user is None:
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/'))
            start_response("302 Found", headers)
            return ["You must be logged in to use that feature."]

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

        # send back a redirect to '/'
        k = 'Location'
        v = '/'
        headers.append((k, v))
        cookie_name, cookie_val = meepcookie.make_set_cookie_header('username','')
        headers.append((cookie_name, cookie_val))
        start_response('302 Found', headers)
        return "no such content"
Exemple #2
0
    def login(self, environ, start_response):
        # hard code the username for now; this should come from Web input!
        username = '******'

        # retrieve user
        user = meeplib.get_user(username)

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

        cookie_name, cookie_val = \
                     meepcookie.make_set_cookie_header('username',
                                                       user.username)
        
	
	print "setting cookie!!!"
	headers.append((cookie_name, cookie_val))
        
        # send back a redirect to '/'
        k = 'Location'
        v = '/'
        headers.append((k, v))
        start_response('302 Found', headers)
        
        return "no such content"
Exemple #3
0
    def login(self, environ, start_response):
        username = '******'
        session_cookie = str(uuid.uuid4())
        username=str(username)
        cur.execute('INSERT INTO sessions (username, cookie) VALUES (?, ?)', (username, session_cookie))
        con.commit()
        print "THE COOKIE",session_cookie
        usernameDB=session_get(cur,session_cookie)
        print "THE USERNAMEDB ",usernameDB



        # hard code the username for now; this should come from Web input!

        # retrieve user
        user = meeplib.get_user(username)

        # set content-type
        headers = [('Content-type', 'text/html')]
        #cookies
        cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',session_cookie)

        headers.append((cookie_name, cookie_val))
        # send back a redirect to '/'
        k = 'Location'
        v = '/'
        headers.append((k, v))
        start_response('302 Found', headers)
        
        return "no such content"
Exemple #4
0
    def create_user(self, environ, start_response):
        # get cookie if there is one
        try:
            cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
            username = cookie["username"].value
        except:
            username = ''

        user = meeplib.get_user(username)
        if user is not None:
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/'))
            start_response("302 Found", headers)
            return ["You must be logged out to use that feature."]

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

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

        try:
            username = form['username'].value
        except KeyError:
            username = ''

        try:
            password = form['password'].value
        except KeyError:
            password = ''

        s = []

        ##if we have username and password
        if username != '':
            user = meeplib.get_user(username)
            ## user already exists
            if user is not None:
                s.append('''Creation Failed! <br>
                    User already exists, please use a different username.<p>'''
                         )
            ## user doesn't exist but they messed up the passwords
            elif password == '':
                s.append('''Creation Failed! <br>
                    Please fill in the Password field<p>''')
            else:
                u = meeplib.User(username, password)
                meeplib.save_state()
                ## send back a redirect to '/'
                k = 'Location'
                v = '/'
                headers.append((k, v))
                cookie_name, cookie_val = meepcookie.make_set_cookie_header(
                    'username', username)
                headers.append((cookie_name, cookie_val))

        start_response('302 Found', headers)

        s.append(render_page("create_user.html", username=username))
        return [''.join(s)]
Exemple #5
0
    def create_user(self, environ, start_response):
        # get cookie if there is one
        try:
            cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
            username = cookie["username"].value
        except:
            username = ''
        
        user = meeplib.get_user(username)
        if user is not None:
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/'))
            start_response("302 Found", headers)
            return ["You must be logged out to use that feature."]

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

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

        try:
            username = form['username'].value
        except KeyError:
            username = ''

        try:
            password = form['password'].value
        except KeyError:
            password = ''

        s=[]

        ##if we have username and password
        if username != '':
            user = meeplib.get_user(username)
            ## user already exists
            if user is not None:
                s.append('''Creation Failed! <br>
                    User already exists, please use a different username.<p>''')
            ## user doesn't exist but they messed up the passwords
            elif password == '':
                s.append('''Creation Failed! <br>
                    Please fill in the Password field<p>''')
            else:
                u = meeplib.User(username, password)
                meeplib.save_state()
                ## send back a redirect to '/'
                k = 'Location'
                v = '/'
                headers.append((k, v))
                cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',username)
                headers.append((cookie_name, cookie_val))

        start_response('302 Found', headers)

        s.append(render_page("create_user.html", username=username))
        return [''.join(s)]
Exemple #6
0
	def logout(self, environ, start_response):
		print "enter logout"
		headers = [('Content-type', 'text/html')]
		k = 'Location'
		v = '/'
		headers.append((k, v))
		cookie_name, cookie_val = meepcookie.make_set_cookie_header('username','')
		headers.append((cookie_name, cookie_val))
		start_response('302 Found', headers)
		print "exit logout"
		return "no such content"
Exemple #7
0
 def logout(self, environ, start_response):
     print "enter logout"
     headers = [('Content-type', 'text/html')]
     k = 'Location'
     v = '/'
     headers.append((k, v))
     cookie_name, cookie_val = meepcookie.make_set_cookie_header(
         'username', '')
     headers.append((cookie_name, cookie_val))
     start_response('302 Found', headers)
     print "exit logout"
     return "no such content"
Exemple #8
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"
Exemple #9
0
 def logout(self, environ, start_response):
     # does nothing
     headers = [('Content-type', 'text/html')]
     
     # send back a redirect to '/'
     k = 'Location'
     v = '/'
     headers.append((k, v))
     cookie_name, cookie_val = meepcookie.make_set_cookie_header('username','')
     headers.append((cookie_name, cookie_val))
     start_response('302 Found', headers)
     
     return ["no such content"]
    def logout(self, environ, start_response):
        headers = [('Content-type', 'text/html')]

        #redirects to '/'
        k = 'Location'
        v = '/'
        headers.append((k, v))
        cookie_name,cookie_value = meepcookie.make_set_cookie_header('username','')
        headers.append((cookie_name, cookie_value))
        
        start_response('302 Found', headers)
        
        return "The content is a Higgs boson."   
Exemple #11
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"    
Exemple #12
0
    def do_login(self, environ, start_response):
        #print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'],
                                environ=environ,
                                keep_blank_values=True)

        try:
            username = form['username'].value
            password = form['password'].value
        except:
            password = None

        # retrieve user
        user = meeplib.get_user(username)

        k = 'Location'
        v = ''
        returnMsg = ""

        loginSuccess = False

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

        if user is not None and password is not None:
            if password == user.password:
                # set content-type

                cookie_name, cookie_val = \
                            meepcookie.make_set_cookie_header('username',
                                                            user.username)
                headers.append((cookie_name, cookie_val))

                # send back a redirect to '/'

                v = '/'

                loginSuccess = True

                headers.append((k, v))

                #print headers

                start_response('302 Found', headers)
                return ["Valid password"]

        if not loginSuccess:
            headers = [('Content-type', 'text/html')]
            start_response("200 OK", headers)

            return [render_page('login.html', invalid='true')]
    def logout(self, environ, start_response):
        # does nothing
        headers = [("Content-type", "text/html")]

        # send back a redirect to '/'
        k = "Location"
        v = "/"
        headers.append((k, v))
        cookie_name, cookie_value = meepcookie.make_set_cookie_header("username", "")
        headers.append((cookie_name, cookie_value))

        start_response("302 Found", headers)

        return "no such content"
Exemple #14
0
    def do_login(self, environ, start_response):
        #print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ, keep_blank_values=True)
        
        try:
            username = form['username'].value
            password = form['password'].value
        except:
            password = None
            
        
        # retrieve user
        user = meeplib.get_user(username)
        
        k = 'Location'
        v = ''
        returnMsg = ""
        
        loginSuccess = False
        
        headers = [('Content-type', 'text/html')]
        
        if user is not None and password is not None:
            if password == user.password:
            # set content-type

                cookie_name, cookie_val = \
                            meepcookie.make_set_cookie_header('username',
                                                            user.username)
                headers.append((cookie_name, cookie_val))
            
                # send back a redirect to '/'
                
                v = '/'
                
                loginSuccess = True
                
                headers.append((k, v))

                #print headers
                
                start_response('302 Found', headers)
                return ["Valid password"]
            
            
        if not loginSuccess:
            headers = [('Content-type', 'text/html')]
            start_response("200 OK", headers)
            
            return [ render_page('login.html', invalid='true') ]  
    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"
Exemple #16
0
    def logout(self, environ, start_response):

        self.username =  None

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

        # send back a redirect to '/'
        k = 'Location'
        v = '/'
        headers.append((k, v))
        cookieName, cookieValue = \
                    meepcookie.make_set_cookie_header('username', '')
        headers.append((cookieName, cookieValue))
        start_response('302 Found', headers)
        return "no such content"
    def logout(self, environ, start_response):

        self.username = None

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

        # send back a redirect to '/'
        k = 'Location'
        v = '/'
        headers.append((k, v))
        cookieName, cookieValue = \
                    meepcookie.make_set_cookie_header('username', '')
        headers.append((cookieName, cookieValue))
        start_response('302 Found', headers)
        return "no such content"
Exemple #18
0
    def create_user(self, environ, start_response):
        print "enter create user"
        username = check_cookie(environ)
        user = meeplib.get_user(username)
        if user is not None:
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/'))
            start_response("302 Found", headers)
            return ["log out to use that feature"]
        headers = [('Content-type', 'text/html')]
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
        try:
            username = form['username'].value
        except KeyError:
            username = ''
        try:
            password = form['password'].value
        except KeyError:
            password = ''

        s = []

        ##if we have username and password
        if username != '':
            user = meeplib.get_user(username)
            ## user already exists
            if user is not None:
                s.append('''user already exists; <br>
				please use a different username.<p>''')
            ## user doesn't exist but they messed up the passwords
            elif password == '':
                s.append('''enter a password <br/>''')
            else:
                u = meeplib.User(username, password)
                meeplib.save_state()
                ## send back a redirect to '/'
                k = 'Location'
                v = '/'
                headers.append((k, v))
                cookie_name, cookie_val = meepcookie.make_set_cookie_header(
                    'username', username)
                headers.append((cookie_name, cookie_val))

        start_response('302 Found', headers)

        s.append(render_page("create_user.html", username=username))
        print "exit create user"
        return [''.join(s)]
    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."    
Exemple #20
0
	def create_user(self, environ, start_response):
		print "enter create user"
		username = check_cookie(environ)
		user = meeplib.get_user(username)
		if user is not None:
			headers = [('Content-type', 'text/html')]
			headers.append(('Location', '/'))
			start_response("302 Found", headers)
			return ["log out to use that feature"]
		headers = [('Content-type', 'text/html')]
		form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
		try:
			username = form['username'].value
		except KeyError:
			username = ''
		try:
			password = form['password'].value
		except KeyError:
			password = ''
			
		s=[]

		##if we have username and password
		if username != '':
			user = meeplib.get_user(username)
			## user already exists
			if user is not None:
				s.append('''user already exists; <br>
				please use a different username.<p>''')
			## user doesn't exist but they messed up the passwords
			elif password == '':
				s.append('''enter a password <br/>''')
			else:
				u = meeplib.User(username, password)
				meeplib.save_state()
				## send back a redirect to '/'
				k = 'Location'
				v = '/'
				headers.append((k, v))
				cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',username)
				headers.append((cookie_name, cookie_val))

		start_response('302 Found', headers)

		s.append(render_page("create_user.html", username=username))
		print "exit create user"
		return [''.join(s)]
Exemple #21
0
    def logout(self, environ, start_response):
        headers = [('Content-type', 'text/html')]
        #Clear the cookie
        #TODO: remove try block here, need to test that it still works properly
        try:
            #cookie_str = environ.get('HTTP_COOKIE', '')
            #cookie = SimpleCookie(cookie_str)
            cookie_name, cookie_val = meepcookie.make_set_cookie_header('username', '')
            headers.append((cookie_name, cookie_val))
        except:
            print "No cookie exists (this probably shouldn't happen)"

        # send back a redirect to '/'
        k = 'Location'
        v = '/'
        headers.append((k, v))
        start_response('302 Found', headers)
        
        return "Logged out"
Exemple #22
0
    def logout(self, environ, start_response):

        headers = [('Content-type', 'text/html')]
        cookie_name, cookie_val = meepcookie.make_set_cookie_header(
            'username', '')

        cookie = environ.get("HTTP_COOKIE")
        username2 = cookie[9:]
        print "USERNAME2 IN LOGOUT" + username2

        session_delete(c, username2)
        username2 = session_get(c, username2)
        headers.append((cookie_name, cookie_val))

        # send back a redirect to '/'
        k = 'Location'
        v = '/'
        headers.append((k, v))

        start_response('302 Found', headers)
        return "no such content"
Exemple #23
0
    def logout(self, environ, start_response):


        # does nothing
        headers = [('Content-type', 'text/html')]
        cookie_name, cookie_val = meepcookie.make_set_cookie_header('username','')

        cookie = environ.get("HTTP_COOKIE")
        cookie = cookie[9:]
        session_cookie=str(cookie)
        cur.execute('DELETE from sessions WHERE cookie=?', [session_cookie])
        con.commit()

        headers.append((cookie_name, cookie_val))
        # send back a redirect to '/'
        k = 'Location'
        v = '/'
        headers.append((k, v))
        start_response('302 Found', headers)
        
        return "no such content"
Exemple #24
0
    def login(self, environ, start_response):

        #sqlstuff

        c.execute('''CREATE TABLE IF NOT EXISTS sessions (id INTEGER PRIMARY KEY ,username TEXT,cookie TEXT UNIQUE,created DATETIME)''')


        
        username = '******'
        userCookie=session_login(c,username)
        print "THE COOKIE",userCookie
        usernameDB=session_get(c,userCookie)
        print "THE USERNAMEDB ",usernameDB



#end sql stuff
        
        u = meeplib.User('test', 'foo',-1)
        # retrieve user
        user = meeplib.get_user(username)
        # set content-type
        headers = [('Content-type', 'text/html')]
        cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',userCookie)        #pass the cookie out, use it to check if somone is logged in
        print "COOKIE_VAL"+cookie_val
        print type(cookie_val)
    
        headers.append((cookie_name, cookie_val))
        # send back a redirect to '/'
        k = 'Location'
        v = '/'
        headers.append((k, v))
        #start_response('302 Found', headers)
       # return "no such content"
    
        #headers = [('Content-type', 'text/html')]
        
        start_response("200 OK", headers)

        return [ render_page('login.html') ]
Exemple #25
0
    def login(self, environ, start_response):

        #sqlstuff

        c.execute(
            '''CREATE TABLE IF NOT EXISTS sessions (id INTEGER PRIMARY KEY ,username TEXT,cookie TEXT UNIQUE,created DATETIME)'''
        )

        username = '******'
        userCookie = session_login(c, username)
        print "THE COOKIE", userCookie
        usernameDB = session_get(c, userCookie)
        print "THE USERNAMEDB ", usernameDB

        #end sql stuff

        u = meeplib.User('test', 'foo', -1)
        # retrieve user
        user = meeplib.get_user(username)
        # set content-type
        headers = [('Content-type', 'text/html')]
        cookie_name, cookie_val = meepcookie.make_set_cookie_header(
            'username', userCookie
        )  #pass the cookie out, use it to check if somone is logged in
        print "COOKIE_VAL" + cookie_val
        print type(cookie_val)

        headers.append((cookie_name, cookie_val))
        # send back a redirect to '/'
        k = 'Location'
        v = '/'
        headers.append((k, v))
        #start_response('302 Found', headers)
        # return "no such content"

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

        start_response("200 OK", headers)

        return [render_page('login.html')]
Exemple #26
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"
Exemple #27
0
    def logout(self, environ, start_response):

        headers = [('Content-type', 'text/html')]
        cookie_name, cookie_val = meepcookie.make_set_cookie_header('username','')

        
        cookie = environ.get("HTTP_COOKIE")
        username2 = cookie[9:]
        print "USERNAME2 IN LOGOUT" + username2
        
        
        session_delete(c,username2)
        username2=session_get(c,username2)
        headers.append((cookie_name, cookie_val))
        
        # send back a redirect to '/'
        k = 'Location'
        v = '/'
        headers.append((k, v))
        
        start_response('302 Found', headers)
        return "no such content"
Exemple #28
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
Exemple #29
0
 def login(self, environ, start_response):
     user = self.authHandler(environ)
     
     headers = [('Content-type', 'text/html')]
     form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
     try:
         username = form['username'].value
         user = meeplib.get_user(username)
         password = form['password'].value
     except:
         password = None
            
     if ((user is not None) and 
         (password is not None) and 
         (user.password == password)):
         k = 'Location'
         v = '/'
         headers.append((k, v))
         cookie_name, cookie_val = meepcookie.make_set_cookie_header('username', user.username)
         headers.append((cookie_name, cookie_val))
         
     start_response('302 Found', headers)
     return [ render_page('login.html') ]
Exemple #30
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"	
Exemple #31
0
    def login(self, environ, start_response):
        # get cookie if there is one
        try:
            cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
            username = cookie["username"].value
            #print "Username = %s" % username
        except:
            #print "session cookie not set! defaulting username"
            username = ''
        
        user = meeplib.get_user(username)
        if user is not None:
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/'))
            start_response("302 Found", headers)
            return ["You must be logged out to use that feature."]

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

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

        try:
            username = form['username'].value
            # retrieve user
            #print "we gots a username", username
        except KeyError:
            username = ''
            #print "no user input"

        try:
            password = form['password'].value
            #print "we gots a password", password
        except KeyError:
            password = ''
            #print 'no password input'

        s=[]

        ##if we have username and password
        if username != '' and password != '':
            user = meeplib.get_user(username)
            if user is not None and user.password == password:
                ## send back a redirect to '/'
                k = 'Location'
                v = '/'
                headers.append((k, v))
                # set the cookie to the username string
                cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',user.username)
                headers.append((cookie_name, cookie_val))
            elif user is None:
                s.append('''Login Failed! <br>
                    The Username you provided does not exist<p>''')

            else:
                ## they messed up the password
                s.append('''Login Failed! <br>
                    The Username or Password you provided was incorrect<p>''')

        ##if we have username or password but not both
        elif username != '' or password != '':
            s.append('''Login Failed! <br>
                    The Username or Password you provided was incorrect<p>''')

        start_response('302 Found', headers)

        ##if we have a valid username and password this is not executed
        s.append(render_page("login.html", username=username))
        return [''.join(s)]
    def create_user(self, environ, start_response):
        try:
            cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
            username = cookie["username"].value
        except:
            username = ''
        
        user = meeplib.get_user(username)
        if user is not None:
            headers = [('Content-type', 'text/html')]
			
            headers.append(('Location', '/'))
			
            start_response("302 Found", headers)
			
            return ["Already logged in. Must logout to create a user."]

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

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

        try:
            username = form['username'].value
        except KeyError:
            username = ''

			
        try:
            password = form['password'].value
        except KeyError:
            password = ''

        s=[]

        #if we have username and password
        if username != '':
            user = meeplib.get_user(username)
            # user already exists
            if user is not None:
                s.append('''User creation has failed, miserably. <br>
                    Your lack of creativity has resulted in an already existing username. <br>
					Please be more creative and create a different username.<p>''')
            # user doesn't exist but password is f****d
            elif password == '':
                s.append('''User was not created. <br>
                    Must input a password to use.<p>''')
            else:
                u = meeplib.User(username, password)
                meeplib.save()
                # redirect it back to '/'
                k = 'Location'
                v = '/'
                headers.append((k, v))
                cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',username)
                headers.append((cookie_name, cookie_val))

        start_response('302 Found', headers)

        s.append(render_page("create_user.html", username=username))
        return [''.join(s)]
    def login(self, environ, start_response):
        headers = [('Content-type', 'text/html')]

        print "number of users: %d" % (len(meeplib._users), )

        print "do i have input?", environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
        print "form", form

        try:
            username = form['username'].value
            # retrieve user
            print "we gots a username", username
        except KeyError:
            username = ''
            print "no user input"

        try:
            password = form['password'].value
            print "we gots a password", password
        except KeyError:
            password = ''
            print 'no password input'

        s = []

        ##if we have username and password
        if username != '' and password != '':
            user = meeplib.get_user(username)
            if user is not None and user.password == password:
                ## send back a redirect to '/'
                k = 'Location'
                v = '/'
                headers.append((k, v))
                cookieName, cookieValue = meepcookie.make_set_cookie_header(
                    'username', user.username)
                headers.append((cookieName, cookieValue))
                self.username = username
            elif user is None:
                s.append('''Login Failed! <br>
                    The Username you provided does not exist<p>''')

            else:
                ## they messed up the password
                s.append('''Login Failed! <br>
                    The Username or Password you provided was incorrect<p>''')

        ##if we have username or password but not both
        elif username != '' or password != '':
            s.append('''Login Failed! <br>
                    The Username or Password you provided was incorrect<p>''')

        start_response('302 Found', headers)

        ##if we have a valid username and password this is not executed
        s.append('''
                    <form action='login' method='post'>
                        <label>username:</label> <input type='text' name='username' value='%s'> <br>
                        <label>password:</label> <input type='password' name='password'> <br>
                        <input type='submit' name='login button' value='Login'></form>

                        <p><a href='/create_user'>Or Create a New User</a>''' %
                 (username))
        return [''.join(s)]
Exemple #34
0
    def login(self, environ, start_response):
        headers = [('Content-type', 'text/html')]

        #print "do i have input?", environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
       # print "form", form

        try:
            username = form['username'].value
            # retrieve user
            #print "we gots a username", username
        except KeyError:
            username = ''
            #print "no user input"

        try:
            password = form['password'].value
            #print "we gots a password", password
        except KeyError:
            password = ''
            #print 'no password input'

        s=[]

        ##if we have username and password
        if username != '' and password != '':
            user = meeplib.get_user(username)
            if user is not None and user.password == password:
                ## send back a redirect to '/'
                cookie_name, cookie_val = \
				meepcookie.make_set_cookie_header('username', user.username)
                headers.append((cookie_name, cookie_val))
                k = 'Location'
                v = '/'
                headers.append((k, v))
                self.username = username
            elif user is None:
                s.append('''Login Failed! <br>
                    The Username you provided does not exist<p>''')

            else:
                ## they messed up the password
                s.append('''Login Failed! <br>
                    The Username or Password you provided was incorrect<p>''')

        ##if we have username or password but not both
        elif username != '' or password != '':
            s.append('''Login Failed! <br>
                    The Username or Password you provided was incorrect<p>''')

        start_response('302 Found', headers)

        ##if we have a valid username and password this is not executed
        s.append('''
                    <form action='login' method='post'>
                        <label>username:</label> <input type='text' name='username' value='%s'> <br>
                        <label>password:</label> <input type='password' name='password'> <br>
                        <input type='submit' name='login button' value='Login'></form>

                        <p><a href='/create_user'>Create a New User</a>''' %(username))
        return [''.join(s)]
Exemple #35
0
    def create_user(self, environ, start_response):
        # get cookie if there is one
        try:
            cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
            username = cookie["username"].value
            #print "Username = %s" % username
        except:
            #print "session cookie not set! defaulting username"
            username = ''
        
        user = meeplib.get_user(username)
        if user is not None:
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/'))
            start_response("302 Found", headers)
            return ["You must be logged out to use that feature."]

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

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

        try:
            username = form['username'].value
            # retrieve user
            #print "we gots a username", username
        except KeyError:
            username = ''
            #print "no user input"

        try:
            password = form['password'].value
            #print "we gots a password", password
        except KeyError:
            password = ''
            #print 'no password input'

        try:
            password2 = form['password_confirm'].value
            #print "we gots a password", password
        except KeyError:
            password2 = ''
            #print 'no password confirmation'

        s=[]

        ##if we have username and password and confirmation password
        if username != '':
            user = meeplib.get_user(username)
            ## user already exists
            if user is not None:
                s.append('''Creation Failed! <br>
                    User already exists, please use a different username.<p>''')
            ## user doesn't exist but they messed up the passwords
            elif password == '':
                s.append('''Creation Failed! <br>
                    Please fill in the Password field<p>''')
            elif password != password2:
                s.append('''Creation Failed! <br>
                    The passwords you provided did not match.<p>''')
            else:
                u = meeplib.User(username, password)
                meeplib.save_state()
                ## send back a redirect to '/'
                k = 'Location'
                v = '/'
                headers.append((k, v))
                cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',username)
                headers.append((cookie_name, cookie_val))
        elif password != '' or password2 != '':
            s.append('''Creation Failed! <br>
            Please provide a username.<p>''')


        start_response('302 Found', headers)

        ##if we have a valid username and password this is not executed
        s.append(render_page("create_user.html", username=username))
        return [''.join(s)]
Exemple #36
0
 def log_user_in(self, environ, headers, username):
     cookie_name, cookie_val = \
         meepcookie.make_set_cookie_header('username', username)
     headers.append((cookie_name, cookie_val))
Exemple #37
0
 def log_user_in(self, environ, headers, username):
     cookie_name, cookie_val = \
         meepcookie.make_set_cookie_header('username', username)
     headers.append((cookie_name, cookie_val))