コード例 #1
0
    def test_check_login(self):

        for email, password, first, last in self.users:
            # try the correct password
            self.assertTrue(interface.check_login(self.db, email, password),
                            "Password check failed for email %s" % email)

            # and now incorrect
            self.assertFalse(
                interface.check_login(self.db, email, "badpassword"),
                "Bad Password check failed for email %s" % email)

        # check for an unknown email
        self.assertFalse(
            interface.check_login(self.db, "*****@*****.**", "badpassword"),
            "Bad Password check failed for unknown email")
コード例 #2
0
    def test_check_login(self):

        for email, password, first, last in self.users:
            # try the correct password
            self.assertTrue(
                interface.check_login(self.db, email, password), "Password check failed for email %s" % email
            )

            # and now incorrect
            self.assertFalse(
                interface.check_login(self.db, email, "badpassword"), "Bad Password check failed for email %s" % email
            )

        # check for an unknown email
        self.assertFalse(
            interface.check_login(self.db, "*****@*****.**", "badpassword"),
            "Bad Password check failed for unknown email",
        )
コード例 #3
0
def application(environ, start_response):
    """Demo WSGI application"""   
    formdata = cgi.FieldStorage(environ=environ, fp=environ['wsgi.input'])
    if formdata.has_key('username') and formdata.has_key('password'):
        username = formdata.getvalue('username')
        password = formdata.getvalue('password')
        if interface.check_login(db, username, password) == True:
            cookie = interface.generate_session(db, username)
            # Correct username or password, return a page saying so.
            return login_success(cookie, environ, start_response)
        else:
            # Invalid username or password, return a page with an error box saying so.
            return invalid(environ, start_response)
    elif formdata.has_key('username') or formdata.has_key('password'):
        # Invalid username or password, return a page with an error box saying so.
        return invalid(environ, start_response)
    
    session = str(interface.user_from_cookie(db, environ)) 
    if formdata.has_key('website') and formdata.has_key('addcomment'):
        if formdata.getvalue('website') == 'http://':
            # Shouldn't post a comment about http://!
            return comment_unsuccessful(environ, start_response)
        elif session != 'None':
            topic = formdata.getvalue('website')
            comment = formdata.getvalue('addcomment')
            interface.add_comment(db, session, topic, comment)
            #Comment successfully added. Return a page saying so, with a redirect link to main page.
            return comment_successful(environ, start_response)
        else:
            # Unlogged users should receive a 404 Not Found error
            return no_permission(environ, start_response)
    elif formdata.has_key('website') or formdata.has_key('addcomment'):
        if session != 'None':
            #Invalid form returned. Return a page showing an error box and how to fix it.
            return comment_unsuccessful(environ, start_response)
        else:
            # Unlogged users should receive a 404 Not Found error.
            return no_permission(environ, start_response)  
          
    if environ['PATH_INFO'] == '/':
        return main_page(environ, start_response)
    elif environ['PATH_INFO'] == '/login':
        return login_page(environ, start_response)
    elif environ['PATH_INFO'] == '/my':
        if session != 'None':
            return my_comments(environ, start_response)
        else:
            return show_404_app(environ, start_response)
    elif environ['PATH_INFO'] == '/conversation':
        return conversation_page(environ, start_response)
    elif environ['PATH_INFO'] == '/comment':
        if session != 'None':
            return add_comment(environ, start_response)
        else:
            #Unlogged users should be told they do not have permission to access this page.
            return no_permission(environ, start_response)
    elif environ['PATH_INFO'] == '/logout':
        if session != 'None':
            interface.delete_session(db, session)
            return logout(environ, start_response)
        else:
            # Unlogged users should receive a 404 Not Found error.
            return show_404_app(environ, start_response)
    else:
        # Path invalid, return 404 Not Found
        return show_404_app(environ, start_response)
コード例 #4
0
def application(environ, start_response):
    """Demo WSGI application"""
    formdata = cgi.FieldStorage(environ=environ, fp=environ['wsgi.input'])
    if formdata.has_key('username') and formdata.has_key('password'):
        username = formdata.getvalue('username')
        password = formdata.getvalue('password')
        if interface.check_login(db, username, password) == True:
            cookie = interface.generate_session(db, username)
            # Correct username or password, return a page saying so.
            return login_success(cookie, environ, start_response)
        else:
            # Invalid username or password, return a page with an error box saying so.
            return invalid(environ, start_response)
    elif formdata.has_key('username') or formdata.has_key('password'):
        # Invalid username or password, return a page with an error box saying so.
        return invalid(environ, start_response)

    session = str(interface.user_from_cookie(db, environ))
    if formdata.has_key('website') and formdata.has_key('addcomment'):
        if formdata.getvalue('website') == 'http://':
            # Shouldn't post a comment about http://!
            return comment_unsuccessful(environ, start_response)
        elif session != 'None':
            topic = formdata.getvalue('website')
            comment = formdata.getvalue('addcomment')
            interface.add_comment(db, session, topic, comment)
            #Comment successfully added. Return a page saying so, with a redirect link to main page.
            return comment_successful(environ, start_response)
        else:
            # Unlogged users should receive a 404 Not Found error
            return no_permission(environ, start_response)
    elif formdata.has_key('website') or formdata.has_key('addcomment'):
        if session != 'None':
            #Invalid form returned. Return a page showing an error box and how to fix it.
            return comment_unsuccessful(environ, start_response)
        else:
            # Unlogged users should receive a 404 Not Found error.
            return no_permission(environ, start_response)

    if environ['PATH_INFO'] == '/':
        return main_page(environ, start_response)
    elif environ['PATH_INFO'] == '/login':
        return login_page(environ, start_response)
    elif environ['PATH_INFO'] == '/my':
        if session != 'None':
            return my_comments(environ, start_response)
        else:
            return show_404_app(environ, start_response)
    elif environ['PATH_INFO'] == '/conversation':
        return conversation_page(environ, start_response)
    elif environ['PATH_INFO'] == '/comment':
        if session != 'None':
            return add_comment(environ, start_response)
        else:
            #Unlogged users should be told they do not have permission to access this page.
            return no_permission(environ, start_response)
    elif environ['PATH_INFO'] == '/logout':
        if session != 'None':
            interface.delete_session(db, session)
            return logout(environ, start_response)
        else:
            # Unlogged users should receive a 404 Not Found error.
            return show_404_app(environ, start_response)
    else:
        # Path invalid, return 404 Not Found
        return show_404_app(environ, start_response)