Пример #1
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)]
Пример #2
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)]
Пример #3
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)]
Пример #4
0
    def add_message_topic_action(self, environ, start_response):
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        topicId = form['topicid'].value
        topic = meeplib.get_topic(int(topicId))

        title = form['title'].value
        message = form['message'].value

        cookie = environ.get('HTTP_COOKIE', '')

        username = meepcookie.load_username(cookie)
        print username
        user = meeplib.get_user(username)
        print user

        if username != "":
            #print title, message, user
            new_message = meeplib.Message(title, message, user)

            topic.add_message(new_message)
            print "Message added to topic" + topicId

            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/m/topics/view?id=%d' % (topic.id)))
            start_response("302 Found", headers)
            return ["message added to topic"]
        else:
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/login'))
            start_response("302 Found", headers)
            return ["session expired"]
Пример #5
0
    def add_topic_action(self, environ, start_response):
        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        title = form['title'].value
        msgtitle = form['msgtitle'].value
        message = form['message'].value

        cookie = environ.get('HTTP_COOKIE', '')
        username = meepcookie.load_username(cookie)

        if username == "":
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/login'))
            start_response("302 Found", headers)

            return ["session ended"]

        user = meeplib.get_user(username)

        new_message = meeplib.Message(msgtitle, message, user)
        new_topic = meeplib.Topic(title, new_message, user)

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list_topics'))
        start_response("302 Found", headers)
        return ["topic added"]
Пример #6
0
    def add_message_action(self, environ, start_response):
        if self.username is None:
            headers = [('Content-type', 'text/html')]
            start_response("302 Found", headers)
            return [
                "You must be logged in to use this feature <p><a href='/login'>Log in</a><p><a href='/m/list'>Show messages</a>"
            ]

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

        title = form['title'].value
        message = form['message'].value
        parent = int(form['parent_id'].value)

        user = meeplib.get_user(self.username)

        new_message = meeplib.Message(title, message, user, parent)

        with con:
            cur.execute(
                "INSERT INTO Messages (ID, Title, Post, Author, Parent) VALUES (?, ?, ?, ?, ?)",
                (new_message.id, title, message, self.username, parent))

        con.commit()
        #meeplib.save()

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list'))
        start_response("302 Found", headers)
        return ["message added"]
Пример #7
0
 def userManager(self, environ):
     try:
         cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
         username = cookie["username"].value
         return meeplib.get_user(username)
     except:
         return None
Пример #8
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"
Пример #9
0
    def add_topic_action(self, environ, start_response):
        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        title = form['title'].value
        msgtitle = form['msgtitle'].value
        message = form['message'].value
        
        cookie = environ.get('HTTP_COOKIE', '')
        username = meepcookie.load_username(cookie)
        
        if username == "":
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/login'))
            start_response("302 Found", headers)
            
            return ["session ended"]
            
        user = meeplib.get_user(username)
        
        new_message = meeplib.Message(msgtitle, message, user)
        new_topic = meeplib.Topic(title, new_message, user)

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list_topics'))
        start_response("302 Found", headers)
        return ["topic added"]
Пример #10
0
    def reply_action(self, environ, start_response):

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

        post = form["post"].value

        # username = '******'

        cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
        username = cookie["username"].value

        user = meeplib.get_user(username)

        new_message = meeplib.Message(post, user)
        thread_id = int(form["thread_id"].value)

        t = meeplib.get_thread(thread_id)
        t.add_post(new_message)
        meeplib.save()

        headers = [("Content-type", "text/html")]
        headers.append(("Location", "/m/list"))
        start_response("302 Found", headers)
        return ["reply added"]
Пример #11
0
 def reply(self, environ, start_response):
     print "enter reply"
     username = check_cookie(environ)
     user = meeplib.get_user(username)
     if user is None:
         headers = [('Content-type', 'text/html')]
         headers.append(('Location', '/'))
         start_response("302 Found", headers)
         return ["log in to use that feature"]
     headers = [('Content-type', 'text/html')]
     form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
     thread_id = int(form['thread_id'].value)
     t = meeplib.get_thread(thread_id)
     s = []
     try:
         post = form['post'].value
     except KeyError:
         post = ''
     if post != '':
         new_message = meeplib.Message(post, user)
         t.add_post(new_message)
         meeplib.save_state()
         headers.append(('Location', '/m/list'))
     start_response("302 Found", headers)
     s.append(render_page("reply.html", thread=t))
     print "exit reply"
     return ["".join(s)]
Пример #12
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"
Пример #13
0
    def reply_action(self, environ, start_response):

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

        post = form['post'].value

        #username = '******'

        cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
        username = cookie["username"].value

        user = meeplib.get_user(username)

        new_message = meeplib.Message(post, user)
        thread_id = int(form['thread_id'].value)

        t = meeplib.get_thread(thread_id)
        t.add_post(new_message)
        meeplib.save()

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list'))
        start_response("302 Found", headers)
        return ["reply added"]
Пример #14
0
	def reply(self, environ, start_response):
		print "enter reply"
		username = check_cookie(environ)
		user = meeplib.get_user(username)
		if user is None:
			headers = [('Content-type', 'text/html')]
			headers.append(('Location', '/'))
			start_response("302 Found", headers)
			return ["log in to use that feature"]
		headers = [('Content-type', 'text/html')]
		form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
		thread_id = int(form['thread_id'].value)
		t = meeplib.get_thread(thread_id)
		s = []
		try:
			post = form['post'].value
		except KeyError:
			post = ''
		if post != '':
			new_message = meeplib.Message(post, user)
			t.add_post(new_message)
			meeplib.save_state()
			headers.append(('Location','/m/list'))
		start_response("302 Found", headers)
		s.append(render_page("reply.html", thread=t))
		print "exit reply"
		return ["".join(s)]
Пример #15
0
    def add_message_action(self, environ, start_response):
        print environ['wsgi.input']
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        title = form['title'].value
        message = form['message'].value
        pID = form['pID'].value
        
        username = meeplib.get_curr_user()
        user = meeplib.get_user(username)
        
        conn = sqlite3.connect('meep.db')
        c = conn.cursor()
        c.execute("INSERT INTO Message VALUES('" + title + "', '" + message + "', '" + username + "', '" + pID + "')")
        conn.commit()

        #new_message = meeplib.Message(title, message, user, pID)

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list'))
        start_response("302 Found", headers)
        
        #SaveMessages()

        if(pID != '!'):
            return ["Message Added"]
        else:
            return ["Reply Added"]
Пример #16
0
    def index(self, environ, start_response):
        start_response("200 OK", [('Content-type', 'text/html')])
        # 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)
        print "User = %s" % user
        if user is None:
            s = [
                """<h1>Welcome <i style = "color:red;">Human</i>!</h1><h2>Please Login or create an account.</h2>
<form action='login' method='POST'>
Username:<input type='text' name='username'><br>
Password:<input type='password' name='password'>&nbsp;<br>
<input type='submit' value='Login'></form>

<p>Don't have an account? Create a user <a href='/create_user'>here</a>"""
            ]

        elif user is not None:
            s = [
                """%s logged in!<p><a href='/m/add_message'>Add a Message</a><p><a href='/create_user'>Create a User</a><p><a href='/logout'>Log out</a><p><a href='/m/list'>Show All Messages</a>"""
                % (username, )
            ]
        return s
Пример #17
0
 def authHandler(self, environ):
     try:
         cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
         username = cookie["username"].value
         return meeplib.get_user(username)
     except:
         return None
Пример #18
0
    def add_message_action(self, environ, start_response):
        if self.username is None:
            headers = [('Content-type', 'text/html')]
            start_response("302 Found", headers)
            return ["You must be logged in to use this feature <p><a href='/login'>Log in</a><p><a href='/m/list'>Show messages</a>"]


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

        title = form['title'].value
        message = form['message'].value
        parent = int(form['parent_id'].value)
        
        user = meeplib.get_user(self.username)
        
        new_message = meeplib.Message(title, message, user, parent)
  
        with con:
            cur.execute("INSERT INTO Messages (ID, Title, Post, Author, Parent) VALUES (?, ?, ?, ?, ?)", (new_message.id, title, message, self.username, parent))
			
        con.commit()
        #meeplib.save()

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list'))
        start_response("302 Found", headers)
        return ["message added"]
Пример #19
0
    def add_message_topic_action(self, environ, start_response):
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        topicId = form['topicid'].value
        topic = meeplib.get_topic(int(topicId))
        
        title = form['title'].value
        message = form['message'].value
        
        cookie = environ.get('HTTP_COOKIE', '')

        username = meepcookie.load_username(cookie)
        print username
        user = meeplib.get_user(username)
        print user
        
        if username != "":
            #print title, message, user
            new_message = meeplib.Message(title, message, user)
            
            topic.add_message(new_message)
            print "Message added to topic" + topicId
            
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/m/topics/view?id=%d' % (topic.id)))
            start_response("302 Found", headers)
            return ["message added to topic"]
        else:
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/login'))
            start_response("302 Found", headers)
            return ["session expired"]
Пример #20
0
    def delete_message_action(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."]

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

        thread_id = int(form['thread_id'].value)
        post_id = int(form['post_id'].value)

        t = meeplib.get_thread(thread_id)
        post = t.get_post(post_id)
        t.delete_post(post)
        meeplib.save_state()

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list'))
        start_response("302 Found", headers)

        return["post deleted"]
Пример #21
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"
Пример #22
0
    def index(self, environ, start_response):
        start_response("200 OK", [("Content-type", "text/html")])
        # 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)
        print "User = %s" % user
        if user is None:
            s = [
                """<h1>Welcome <i style = "color:red;">Human</i>!</h1><h2>Please Login or create an account.</h2>
<form action='login' method='POST'>
Username:<input type='text' name='username'><br>
Password:<input type='password' name='password'>&nbsp;<br>
<input type='submit' value='Login'></form>

<p>Don't have an account? Create a user <a href='/create_user'>here</a>"""
            ]

        elif user is not None:
            s = [
                """%s logged in!<p><a href='/m/add_message'>Add a Message</a><p><a href='/create_user'>Create a User</a><p><a href='/logout'>Log out</a><p><a href='/m/list'>Show All Messages</a>"""
                % (username,)
            ]
        return s
Пример #23
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)]
Пример #24
0
    def alter_message_action(self, environ, start_response):
        post = (environ.get('REQUEST_METHOD') == 'POST')
        if post:
            form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
        else:
            form = parse_qs(environ['QUERY_STRING'])
        """
        try:
            form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
            #params = dict([part.split('=') for part in environ['QUERY_STRING'].split('&')])
            #msgId = int(params['id'])
        except:
            headers = [('Content-type', 'text/html')]
            start_response("200 OK", headers)
            return ["Error Processing provided ID"]

        id = int(form['id'].value)
        
        action = form['bttnSubmit'].value
        """

        print 'post %s' % (post, )
        id = int(self.get_value(form, post, 'id', ''))
        action = self.get_value(form, post, 'bttnSubmit', '')
        msg = meeplib.get_message(id)

        error = False
        errorMsg = ""
        response = "200 OK"

        headers = [('Content-type', 'text/html')]
        u = self.getUser(environ)
        if u == None:
            error = True
            errorMsg = """You must be logged in to proceed."""
        if msg == None:
            error = True
            errorMsg = """Message id: %d could not be found.""" % (id, )
        elif action == "Delete":
            if msg.author.username == u.username:
                meeplib.delete_message(msg)
                response = "302 Found"
                headers.append(('Location', '/'))
                errorMsg = "message removed"
            else:
                errorMsg = "You cannot delete another user's post."
        elif action == "Reply":
            title = ""
            message = form['replyText'].value
            user = meeplib.get_user(u.username)
            new_message = meeplib.Message(title, message, user, True)
            msg.add_reply(new_message)
            response = "302 Found"
            headers.append(('Location', '/'))
            errorMsg = "message replied"

        start_response(response, headers)
        return [errorMsg]
Пример #25
0
    def alter_message_action(self, environ, start_response):
        post = (environ.get('REQUEST_METHOD') == 'POST')
        if post:
            form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
        else:
            form = parse_qs(environ['QUERY_STRING'])
        """
        try:
            form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
            #params = dict([part.split('=') for part in environ['QUERY_STRING'].split('&')])
            #msgId = int(params['id'])
        except:
            headers = [('Content-type', 'text/html')]
            start_response("200 OK", headers)
            return ["Error Processing provided ID"]

        id = int(form['id'].value)
        
        action = form['bttnSubmit'].value
        """

        print 'post %s' % (post,)
        id = int(self.get_value(form,post,'id',''))
        action = self.get_value(form,post,'bttnSubmit','')
        msg = meeplib.get_message(id)
        
        error = False
        errorMsg = ""
        response = "200 OK"
        
        headers = [('Content-type', 'text/html')]
        u = self.getUser(environ)
        if u == None:
            error = True
            errorMsg = """You must be logged in to proceed."""
        if msg == None:
            error = True
            errorMsg = """Message id: %d could not be found.""" % (id,)
        elif action == "Delete":
            if msg.author.username == u.username:
                meeplib.delete_message(msg)
                response = "302 Found"
                headers.append(('Location', '/'))
                errorMsg = "message removed"
            else:
                errorMsg = "You cannot delete another user's post."
        elif action == "Reply":
            title = ""
            message = form['replyText'].value
            user = meeplib.get_user(u.username)
            new_message = meeplib.Message(title, message, user, True)
            msg.add_reply(new_message)
            response = "302 Found"
            headers.append(('Location', '/'))
            errorMsg = "message replied"

        start_response(response, headers)
        return [errorMsg]
Пример #26
0
def add_message(title, message, pid):
    try:
        username = "******"
        user = meeplib.get_user(username)

        new_message = meeplib.Message(title, message, user, pid)
        return new_message.id
    except:
        return -1
Пример #27
0
def add_message(title, message, pid):
    try:
        username = "******"
        user = meeplib.get_user(username)

        new_message = meeplib.Message(title, message, user, pid)
        return new_message.id
    except:
        return -1
Пример #28
0
    def test_message_ownership(self):
        x = meeplib.get_all_users()
        assert len(x) != 0
        u = meeplib.get_user('foo')

        x = meeplib.get_all_messages()
        assert len(x) != 0
        m = x[len(x) - 1]

        assert m.author == u
Пример #29
0
    def test_message_ownership(self):
        x = meeplib.get_all_users()
        assert len(x) != 0
        u = meeplib.get_user('foo')

        x = meeplib.get_all_messages()
        assert len(x) != 0
        m = x[len(x) - 1]

        assert m.author == u
Пример #30
0
    def tearDown(self):
        m = meeplib.get_message(self.msgId)
        if m != None:
            meeplib.delete_message(m)

        l = len(meeplib.get_all_users())
        meeplib.delete_user(meeplib.get_user(self.ux))
        lafter = len(meeplib.get_all_users())

        assert l > lafter
Пример #31
0
	def index(self, environ, start_response):
		print "enter index"
		start_response("200 OK", [('Content-type', 'text/html')])
		username = check_cookie(environ)
		user = meeplib.get_user(username)
		if user is None:
			print "exit index"
			return [ render_page('login.html') ]
		elif user is not None:
			print "exit index"
			return [ render_page('index.html', username=username) ]
Пример #32
0
 def index(self, environ, start_response):
     print "enter index"
     start_response("200 OK", [('Content-type', 'text/html')])
     username = check_cookie(environ)
     user = meeplib.get_user(username)
     if user is None:
         print "exit index"
         return [render_page('login.html')]
     elif user is not None:
         print "exit index"
         return [render_page('index.html', username=username)]
Пример #33
0
    def test_get_next_message_id(self):
        #there should be 1 message initially created
        assert meeplib._get_next_message_id() == 1
        user = meeplib.User('admin', 'admin')
        user.insertIntoDB()
        author = meeplib.get_user('admin')
        message = meeplib.Message('title', 'message', author.id, -1)
        message.insertIntoDB()

        #there should not be two messages
        assert meeplib._get_next_message_id() == 2
Пример #34
0
    def test_delete_user(self):
        #check that there is 1 user
        assert len(meeplib.get_all_users()) == 1
        assert len(meeplib._user_ids) == 1
        for msg in meeplib._messages.values():
            meeplib.delete_message(msg)
        meeplib.delete_user(meeplib.get_user('foo'))

        #check that there are no users
        assert len(meeplib.get_all_users()) == 0
        assert len(meeplib._user_ids) == 0
Пример #35
0
    def tearDown(self):
        m = meeplib.get_message(self.msgId)
        if m != None:
            meeplib.delete_message(m)
            

        l = len(meeplib.get_all_users())
        meeplib.delete_user(meeplib.get_user(self.ux))
        lafter = len(meeplib.get_all_users())
        
        assert l > lafter
Пример #36
0
 def test_get_next_message_id(self):
     #there should be 1 message initially created
     assert meeplib._get_next_message_id() == 1
     user = meeplib.User('admin', 'admin')
     user.insertIntoDB()
     author = meeplib.get_user('admin')
     message = meeplib.Message('title', 'message', author.id, -1)
     message.insertIntoDB()
     
     #there should not be two messages
     assert meeplib._get_next_message_id() == 2
Пример #37
0
    def add_thread(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')]

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

        try:
            title = form['title'].value
        except KeyError:
            title = ''
        try:
            message = form ['message'].value
        except KeyError:
            message = ''

        s = []

        # title and message are non-empty
        if title == '' and message == '':
            pass
        elif title == '' and message != '':
            s.append("Title was empty.<p>")
        elif title != '' and message == '':
            s.append("Message was empty. <p>")
        elif title != '' and message != '':
            new_message = meeplib.Message(message, user)
            t = meeplib.Thread(title)
            t.add_post(new_message)
            meeplib.save_state()
            headers.append(('Location','/m/list'))
            
        start_response("302 Found", headers)

        # doesn't get executed if we had valid input and created a thread
        s.append(render_page("add_thread.html", title=title, message=message))

        return ["".join(s)]
Пример #38
0
    def test_delete_user(self):
        #check that there is 1 user
        assert len(meeplib.get_all_users()) == 1
        assert len(meeplib._user_ids) == 1
        for msg in meeplib._messages.values():
            meeplib.delete_message(msg)
        meeplib.delete_user(meeplib.get_user('foo'))
        

        #check that there are no users
        assert len(meeplib.get_all_users()) == 0
        assert len(meeplib._user_ids) == 0
Пример #39
0
    def add_message(self, environ, start_response):
        #get cookie
        try:
            cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
            username = cookie["username"].value
            print "Username is %s" % username
        except:
            username = ''
        
        user = meeplib.get_user(username)
        if user is None:
            headers = [('Content-type', 'text/html')]
            headers.append(('Location', '/'))
            start_response("302 Found", headers)
            return ["Dude, login first if you want to use this feature."]
        headers = [('Content-type', 'text/html')]

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

        try:
            title = form['title'].value
        except KeyError:
            title = ''
        try:
            message = form ['message'].value
        except KeyError:
            message = ''

        s = []

        #check to see if title and message are not empty
        if title == '' and message == '':
            pass
			
        elif title == '' and message != '':
            s.append("The title is empty.<p>")
			
        elif title != '' and message == '':
            s.append("The message is empty. <p>")
			
        elif title != '' and message != '':
            new_message = meeplib.Message(message, user)
            t = meeplib.Thread(title)
            t.add_post(new_message)
            meeplib.save()
            headers.append(('Location','/m/list'))
            
        start_response("302 Found", headers)
        s.append(render_page("add_message.html", title=title, message=message))

        return ["".join(s)]
Пример #40
0
 def index(self, environ, start_response):
     start_response("200 OK", [('Content-type', 'text/html')])
     # 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)
     return render_page("index.html", user=user)
Пример #41
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') ]  
Пример #42
0
	def list_messages(self, environ, start_response):
		print "enter list messages"
		messages = meeplib.get_all_threads()
		username = check_cookie(environ)
		user = meeplib.get_user(username)
		s = []
		if messages:
			s.append(render_page("list_messages.html", messages=messages, user=user))
		else:
			s.append("no threads exist<p>")
		headers = [('Content-type', 'text/html')]
		start_response("200 OK", headers)
		print "exit list messages"
		return ["".join(s)]
Пример #43
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')]
Пример #44
0
def initialize():
    # create a default user
    #u = meeplib.User('test', 'foo')

    # create a single message
    #meeplib.Message('my title', 'This is my message!', u, "!")

    try:
        fp = open('users.pickle')
        try:
            obj = pickle.load(fp)
            while True:
                #print obj
                (a, b) = obj
                
                u = meeplib.User(a, b);
                try:
                    obj = pickle.load(fp)
                except EOFError:
                    break
        except EOFError:
            pass
    except IOError:
        fp = open('users.pickle', "w")
        fp.close()
    
    
    try:
        fp = open('messages.pickle')
        try:
            obj = pickle.load(fp)
            while True:
                (a, b, c, d, e) = obj
                #print obj
                m = meeplib.Message(a,b,meeplib.get_user(c), d)
                m.id = e
                #print m.post + " is " + str(m.id)
                #obj = pickle.load(fp)
                #m.replies = obj
                #print obj
                try:
                    obj = pickle.load(fp)
                except EOFError:
                    break
        except EOFError:
            pass
    except IOError:
        p = open('messages.pickle', "w")
        fp.close()
Пример #45
0
    def create_user(self, environ, start_response):
        headers = [('Content-type', 'text/html')]

        post = (environ.get('REQUEST_METHOD') == 'POST')
        if post:
            form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
        else:
            form = parse_qs(environ['QUERY_STRING'])
    
        username = self.get_value(form,post,'username','')
        password = self.get_value(form,post,'password','')
        password2 = self.get_value(form,post,'password_confirm','')

        s=[]
        
        ##if we have username and password and confirmation password
        err = False
        if username != '':
            user = meeplib.get_user(username)
            ## user already exists
            if user is not None:
                print 'nouser'
                err = True
            ## user doesn't exist but they messed up the passwords
            elif password == '':
                print 'passblank'
                err = True
            elif password != password2:
                print 'pass2blank'
                err = True
            else:
                print 'else'
                u = meeplib.User(username, password)
                ## send back a redirect to '/'
                k = 'Location'
                v = '/'
                headers.append((k, v))
                self.log_user_in(environ, headers, u.username)
                start_response('302 Found', headers)
                return []
        elif password != '' or password2 != '':
                err = True
                
        if post:
            err = True
            
        headers = [('Content-type', 'text/html')]
        start_response('200 OK', headers)
        return [render_page('createUser.html', error=err)]
Пример #46
0
    def create_user(self, environ, start_response):
        headers = [('Content-type', 'text/html')]

        post = (environ.get('REQUEST_METHOD') == 'POST')
        if post:
            form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
        else:
            form = parse_qs(environ['QUERY_STRING'])

        username = self.get_value(form, post, 'username', '')
        password = self.get_value(form, post, 'password', '')
        password2 = self.get_value(form, post, 'password_confirm', '')

        s = []

        ##if we have username and password and confirmation password
        err = False
        if username != '':
            user = meeplib.get_user(username)
            ## user already exists
            if user is not None:
                print 'nouser'
                err = True
            ## user doesn't exist but they messed up the passwords
            elif password == '':
                print 'passblank'
                err = True
            elif password != password2:
                print 'pass2blank'
                err = True
            else:
                print 'else'
                u = meeplib.User(username, password)
                ## send back a redirect to '/'
                k = 'Location'
                v = '/'
                headers.append((k, v))
                self.log_user_in(environ, headers, u.username)
                start_response('302 Found', headers)
                return []
        elif password != '' or password2 != '':
            err = True

        if post:
            err = True

        headers = [('Content-type', 'text/html')]
        start_response('200 OK', headers)
        return [render_page('createUser.html', error=err)]
Пример #47
0
    def add_message_action(self, environ, start_response):
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        title = form['title'].value
        message = form['message'].value
        
        username = '******'
        user = meeplib.get_user(username)
        
        new_message = meeplib.Message(title, message, user)

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list'))
        start_response("302 Found", headers)
        return ["message added"]
Пример #48
0
    def test_get_root_messages(self):
        user = meeplib.User('admin', 'admin')
        user.insertIntoDB()
        author = meeplib.get_user('admin')
        message1 = meeplib.Message('title1', 'message1', author.id, -1)
        message1.insertIntoDB()
        message2 = meeplib.Message('title2', 'message2', author.id, -1)
        message2.insertIntoDB()
        message3 = meeplib.Message('title3', 'message3', author.id, 0)
        message3.insertIntoDB()

        root_messages = meeplib._get_root_messages()
        assert message1 in root_messages
        assert message2 in root_messages
        assert message3 not in root_messages
Пример #49
0
    def add_message_action(self, environ, start_response):
        form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)

        title = form['title'].value
        message = form['message'].value

        username = '******'
        user = meeplib.get_user(username)

        new_message = meeplib.Message(title, message, user)

        headers = [('Content-type', 'text/html')]
        headers.append(('Location', '/m/list'))
        start_response("302 Found", headers)
        return ["message added"]
Пример #50
0
 def test_get_root_messages(self):
     user = meeplib.User('admin', 'admin')
     user.insertIntoDB()
     author = meeplib.get_user('admin')
     message1 = meeplib.Message('title1', 'message1', author.id, -1)
     message1.insertIntoDB()
     message2 = meeplib.Message('title2', 'message2', author.id, -1)
     message2.insertIntoDB()
     message3 = meeplib.Message('title3', 'message3', author.id, 0)
     message3.insertIntoDB()
     
     root_messages = meeplib._get_root_messages()
     assert message1 in root_messages
     assert message2 in root_messages
     assert message3 not in root_messages
Пример #51
0
    def index(self, environ, start_response):
		start_response("200 OK", [('Content-type', 'text/html')])
		# get cookie if there is one
		try:
			cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
			username = cookie["username"].value
			print "Username is %s" % username
		except:
			print "The session cookie has not been set yet, defaulting username."
			username = ''
		user = meeplib.get_user(username)
		if user is None:
			return [render_page('login.html')]
		elif user is not None:
			return [render_page('index.html', username = username)]
Пример #52
0
def initialize():
    # create a default user
    #u = meeplib.User('test', 'foo')

    # create a single message
    #meeplib.Message('my title', 'This is my message!', u, "!")

    try:
        fp = open('users.pickle')
        try:
            obj = pickle.load(fp)
            while True:
                #print obj
                (a, b) = obj

                u = meeplib.User(a, b)
                try:
                    obj = pickle.load(fp)
                except EOFError:
                    break
        except EOFError:
            pass
    except IOError:
        fp = open('users.pickle', "w")
        fp.close()

    try:
        fp = open('messages.pickle')
        try:
            obj = pickle.load(fp)
            while True:
                (a, b, c, d, e) = obj
                #print obj
                m = meeplib.Message(a, b, meeplib.get_user(c), d)
                m.id = e
                #print m.post + " is " + str(m.id)
                #obj = pickle.load(fp)
                #m.replies = obj
                #print obj
                try:
                    obj = pickle.load(fp)
                except EOFError:
                    break
        except EOFError:
            pass
    except IOError:
        p = open('messages.pickle', "w")
        fp.close()