Example #1
0
    def test_post_list_limit(self):
        """Test that post list works with the limit argument"""

        # now look at the limit argument
        posts = interface.post_list(self.db, limit=3)
        self.assertEqual(3, len(posts))

        posts = interface.post_list(self.db, limit=1)
        self.assertEqual(1, len(posts))

        # limit higher than number of posts
        posts = interface.post_list(self.db, limit=100)
        self.assertEqual(10, len(posts))
Example #2
0
    def test_post_list_user(self):
        """Test that post_list works with a usernick argument"""

        # now restrict to one user
        posts = interface.post_list(self.db, usernick='Mandible')
        self.assertEqual(3, len(posts))

        # try a user with no posts
        posts = interface.post_list(self.db, usernick='*****@*****.**')
        self.assertEqual(0, len(posts))

        # try a user who doesn't exist
        posts = interface.post_list(self.db, usernick='*****@*****.**')
        self.assertEqual(0, len(posts))
Example #3
0
    def test_post_list(self):
        """Test that post_list returns all posts"""

        # first get all posts
        posts = interface.post_list(self.db)

        self.assertEqual(len(self.posts), len(posts))
Example #4
0
def search():
    """Search feature, can search user name and / or contents"""
    db = COMP249Db()
    username = session_user(db) # retrieve user session information from the database
    loginString = ""
    content = ""
    http = ""
    avatar = ""

    if 'search' in request.forms:
        search = request.forms['search'] # get user inputs from the search field
        str = "<h2>Search results for '" + search + "':</h2>" # title
        list = interface.post_list(db, usernick=None, limit=50)
        if not username: # display the things below only if user not logged in
            # display input field for username and password if the user not logged in
            loginString = "<h3>member login</h3></br><form id='loginform' method='POST' action ='/login'><input type='text' name='nick' placeholder='username' class='focus' onKeyPress='return submitenter(this,event)'><input type='password' name='password' placeholder='password' class='focus' onKeyPress='return submitenter(this,event)'></form>"

        if username: # display the things below only if user logged in
            avatar = interface.user_avatar(db,username)
            loginString = "<a href='/users/" + username + "'><img src='" + avatar + "'><h3 style='text-align:center; margin-left:0px;'>" + username + "</h3></a><br><form action= '/logout' id='logoutform' name='logoutform' method='POST' ><input type='submit' value='logout' class='sun-flower-button'></form>"

        for item in list:
            content = interface.post_to_html(item[3])
            http = interface.post_to_html(content)
            dt = datetime.datetime.strptime(item[1],"%Y-%m-%d %H:%M:%S")
            dt_string = dt.strftime("%b %d, %Y %I:%M%p").upper()
            if ((bool(search.lower() in item[2].lower())) | (bool(search.lower() in http.lower()))):
                str = str + "<div class='entry'><a href='/users/" + item[2] + "'><div class='item'><img src='" + item[4] + "'> <p>" + item[2].upper() + "</p></div></a><div class='date'><p>" + dt_string + "</p></div>" + http + "<hr></div>" # contents display

        return template('base.tpl', base=str, validate='', login=loginString)
Example #5
0
def login():
    """Display this page if any invalid user identification"""
    db = COMP249Db()
    list = interface.post_list(db, usernick=None, limit=50)
    content = ""
    http = ""
    str = ""

    # display previous posts
    for item in list:
        content = interface.post_to_html(item[3])
        http = interface.post_to_html(content)
        dt = datetime.datetime.strptime(item[1],"%Y-%m-%d %H:%M:%S")
        dt_string = dt.strftime("%b %d, %Y %I:%M%p").upper()
        str = str + "<div class='entry'><a href='/users/" + item[2] + "'><div class='item'><img src='" + item[4] + "'> <p>" + item[2].upper() + "</p></div></a><div class='date'><p>" + dt_string + "</p></div>" + http + "<hr></div>" # contents display

    # if there are something within the login field...
    if 'nick' in request.forms:
        username = request.forms['nick'] # get username from the 'nick' field
        password = request.forms['password'] # get password from the 'password' field
        str2 = "<p style='color:red;font-size:small;'>Invaild username or password</p>"
        loginString = "<h3>member login</h3></br><form id='loginform' method='POST' action ='/login'><input type='text' name='nick' placeholder='username' class='focus' onKeyPress='return submitenter(this,event)'><input type='password' name='password' placeholder='password' class='focus' onKeyPress='return submitenter(this,event)'></form>"
        if not check_login(db, username, password):
            return template('base.tpl', base=str, validate=str2, login=loginString) # display 'Failed' if invaild user identification
        generate_session(db, username) # generate the user session
        response.set_header('Location', '/')
        response.status = 303
        return "Redirect to /" # redirect to /
Example #6
0
def users(username):
    """Generate the webpage that displays the user posts"""
    db = COMP249Db()
    uname = session_user(db) # retrieve user session information from the database
    loginString = ""
    list2 = interface.post_list(db, usernick=None, limit=50)
    str = ""
    content = ""
    http = ""
    avatar = ""

    str = "<h2>" + username + "'s posts:</h2>" # title
    if not uname:
        # display input field for username and password if the user not logged in
        loginString = "<h3>member login</h3></br><form id='loginform' method='POST' action ='/login'><input type='text' name='nick' placeholder='username' class='focus' onKeyPress='return submitenter(this,event)'><input type='password' name='password' placeholder='password' class='focus' onKeyPress='return submitenter(this,event)'></form>"

    if uname:
        avatar = interface.user_avatar(db,uname)
        loginString = "<a href='/users/" + uname + "'><img src='" + avatar + "'><h3 style='text-align:center; margin-left:0px;'>" + uname + "</h3></a><br><form action= '/logout' id='logoutform' name='logoutform' method='POST' ><input type='submit' value='logout' class='sun-flower-button'></form>"

    for item in list2:
        if (username == item[2]): # display the post only if the username and the author is the same person
            content = interface.post_to_html(item[3])
            http = interface.post_to_html(content)
            dt = datetime.datetime.strptime(item[1],"%Y-%m-%d %H:%M:%S")
            dt_string = dt.strftime("%b %d, %Y %I:%M%p").upper()
            str = str + "<div class='entry'><a href='/users/" + item[2] + "'><div class='item'><img src='" + item[4] + "'> <p>" + item[2].upper() + "</p></div></a><div class='date'><p>" + dt_string + "</p></div>" + http + "<hr></div>" # contents display
    return template('base.tpl', base=str, validate='', login=loginString)
Example #7
0
def index():
    """Index of Psst site"""
    db = COMP249Db()
    username = session_user(db)
    loginString = ""
    content = ""
    http = ""
    str = ""
    avatar = ""
    list = interface.post_list(db, usernick=None, limit=50)

    # if user not logged in
    if not username:
        # display input field for username and password if the user not logged in
        loginString = "<h3>member login</h3><br><form id='loginform' method='POST' action ='/login'><input type='text' name='nick' placeholder='username' class='focus' onKeyPress='return submitenter(this,event)'><input type='password' name='password' placeholder='password' class='focus' onKeyPress='return submitenter(this,event)'></form>"

    # if user logged in
    if username:
        avatar = interface.user_avatar(db,username)
        # display the input field for adding posts instead of the title
        str = str + "<form action='/post' id='postform' method='POST'><input type='postfield' name='post' placeholder='post content, formats: [i]image urls[/i][t]title[/t][p]contents[/p]#tags #tags2' value='[i]image urls[/i][t]title[/t][p]contents[/p]#tags #tags2' class='focus' onKeyPress='return submitenter(this,event)'></form>"
        loginString = "<a href='/users/" + username + "'><img src='" + avatar + "'><h3 style='text-align:center; margin-left:0px;'>" + username + "</h3></a><br><form action= '/logout' id='logoutform' name='logoutform' method='POST' ><input type='submit' value='logout' class='sun-flower-button'></form>"

    for item in list:
        content = interface.post_to_html(item[3])
        http = interface.post_to_html(content)
        dt = datetime.datetime.strptime(item[1],"%Y-%m-%d %H:%M:%S")
        dt_string = dt.strftime("%b %d, %Y %I:%M%p").upper()
        str = str + "<div class='entry'><a href='/users/" + item[2] + "'><div class='item'><img src='" + item[4] + "'> <p>" + item[2].upper() + "</p></div></a><div class='date'><p>" + dt_string + "</p></div>" + http + "<hr></div>" # contents display

    return template('base.tpl', base=str, validate='', login=loginString)
Example #8
0
def users(username):
    """Generate the webpage that displays the user posts"""
    db = COMP249Db()
    uname = session_user(db) # retrieve user session information from the database
    loginString = ""
    private = "#private" # string that makes the post private
    list = interface.post_list(db, usernick=username, limit=50)
    list2 = interface.post_list(db, usernick=None, limit=50)
    str = ""
    for item in list:
        str = "<h2><b>" + item[2] + "</b> posted pssts:</h2>" # title
    if not uname:
        # display input field for username and password if the user not logged in
        loginString = "<form id='loginform' method='POST' action ='/login'><input type='text' name='nick' placeholder='username' class='focus' onKeyPress='return submitenter(this,event)'><input type='password' name='password' placeholder='password' class='focus' onKeyPress='return submitenter(this,event)'></form>"
        str = str + "<table>"
        content = ""
        http = ""
        for item in list2:
            if (username == item[2]):
                content = interface.post_to_html(item[3])
                http = interface.post_to_html(content)

                # not display the posts with the #private tag
                if(bool(private.lower() in http.lower())==False):
                    str = str + "<tr>"
                    str = str + "<td valign='top'><img src='" + item[4] + "' width='45'></td>" # user avatar
                    str = str + "<td valign='bottom'><a href='/users/" + item[2] + "'>@" + item[2] + ": </a>" + http + " - <i>posted on " + \
                          item[1] + "</i></br></br></td></tr>" # username and contents
        str = str + "</table>"
    if uname:
        for item in list2:
            if(uname==item[2]): # if user logged in, display his/her avatar, name, previous posts, the post mention, and logout option
                loginString = "<form action= '/logout' id='logoutform' name='logoutform' method='POST' ><table><tr><td><img src='" + item[4] + "' width='85'></td><td><h3>Logged in as " + uname + "</h3><p><a href='/users/" + uname + "'>Posted pssts</a></p><p><a href='/mentions/" + uname + "'>@me pssts</a></p><p><a href='javascript: document.logoutform.submit();'>Logout</a></p></td></tr></table></form>"
        str = str + "<table>"
        content = ""
        http = ""
        for item in list2:
            if (username == item[2]): # display the post only if the username and the author is the same person
                content = interface.post_to_html(item[3])
                http = interface.post_to_html(content)
                str = str + "<tr>"
                str = str + "<td valign='top'><img src='" + item[4] + "' width='45'></td>" # user avatar
                str = str + "<td valign='bottom'><a href='/users/" + item[2] + "'>@" + item[2] + ": </a>" + http + " - <i>posted on " + \
                      item[1] + "</i></br></br></td></tr>" # username and contents
        str = str + "</table>"
    return template('base.tpl', base=str, validate='', login=loginString)
Example #9
0
    def test_post_list(self):
        """Test that post_list returns all posts"""

        # first get all posts
        posts = interface.post_list(self.db)
        self.assertEqual(len(self.posts), len(posts))

        # now restrict to one user
        posts = interface.post_list(self.db, usernick='Mandible')
        self.assertEqual(3, len(posts))

        # try a user with no posts
        posts = interface.post_list(self.db, usernick='*****@*****.**')
        self.assertEqual(0, len(posts))

        # try a user who doesn't exist
        posts = interface.post_list(self.db, usernick='*****@*****.**')
        self.assertEqual(0, len(posts))

        # now look at the limit argument
        posts = interface.post_list(self.db, limit=3)
        self.assertEqual(3, len(posts))

        posts = interface.post_list(self.db, limit=1)
        self.assertEqual(1, len(posts))

        # limit higher than number of posts
        posts = interface.post_list(self.db, limit=100)
        self.assertEqual(10, len(posts))
Example #10
0
    def test_post_list(self):
        """Test that post_list returns all posts"""

        # first get all posts
        posts = interface.post_list(self.db)
        print(posts)
        self.assertEqual(len(self.posts), len(posts))
        print(posts)
        # now restrict to one user
        posts = interface.post_list(self.db, usernick='Mandible')
        print(posts)
        self.assertEqual(3, len(posts))

        # try a user with no posts
        posts = interface.post_list(self.db, usernick='*****@*****.**')
        print(posts)
        self.assertEqual(0, len(posts))

        # try a user who doesn't exist
        posts = interface.post_list(self.db, usernick='*****@*****.**')
        print(posts)
        self.assertEqual(0, len(posts))

        # now look at the limit argument
        posts = interface.post_list(self.db, limit=3)
        self.assertEqual(3, len(posts))

        posts = interface.post_list(self.db, limit=1)
        self.assertEqual(1, len(posts))

        # limit higher than number of posts
        posts = interface.post_list(self.db, limit=100)
        self.assertEqual(10, len(posts))
Example #11
0
def index():
    """Generate the main page of the app 
    with a list of the most recent posts"""

    db = COMP249Db()
    session_user = users.session_user(db)
    info = {'title': "¡Welcome to Psst!", 'posts': interface.post_list(db)}

    return template('index', info, session_user=session_user)
Example #12
0
def index(dic=None):
    """ Return homepage with most current posts from users
    :param dic: Dictionary containing previous request data
    :return: Homepage
    """
    if dic is None:
        dic = {"loginFailed": ""}
    posts = get_recent_posts(interface.post_list(db, None))
    dic.update({"posts": posts})
    dic.update(determine_user())
    return template("main.tpl", dic)
Example #13
0
def index(login=None):
    user = users.session_user(COMP249Db())
    info = {
        'title': 'Psst!',
        'message': 'Welcome to Psst!',
        'user': user,
        'avatar': interface.user_avatar(COMP249Db(), user),
        'login': login
    }
    info['posts'] = interface.post_list(COMP249Db())
    return template('views/index.html', info)
Example #14
0
def userpage(who):
    """Generate a page with just the posts for a given user"""

    db = COMP249Db()

    info = {
        'title': "User page for " + who,
        'posts': interface.post_list(db, usernick=who),
    }

    # re-use the index template since this is just a list of posts
    return template("index", info)
Example #15
0
def userpage(name):
    user = users.session_user(COMP249Db())
    info = {
        'title': 'Psst!',
        'message': name + "'s posts",
        'header': 'Posts by ' + name,
        'user': user,
        'avatar': interface.user_avatar(COMP249Db(), user),
        'login': login
    }
    info['posts'] = interface.post_list(COMP249Db(), name)
    return template('views/user.html', info)
Example #16
0
def index():
    """Index of Psst site"""
    db = COMP249Db()
    username = session_user(db)
    loginString = ""
    private = "#private" # string that makes the post private
    content = ""
    http = ""
    list = interface.post_list(db, usernick=None, limit=50)

    # if user not logged in
    if not username:
        str = "<h2><b>Welcome to Psst.</b> Latest pssts:</h2>" # title
        # display input field for username and password if the user not logged in
        loginString = "<form id='loginform' method='POST' action ='/login'><input type='text' name='nick' placeholder='username' class='focus' onKeyPress='return submitenter(this,event)'><input type='password' name='password' placeholder='password' class='focus' onKeyPress='return submitenter(this,event)'></form>"
        str = str + "<table>"
        for item in list:
            content = interface.post_to_html(item[3])
            http = interface.post_to_html(content)

            # not display the posts with the '#private' tag
            if(bool(private.lower() in http.lower())==False):
                str = str + "<tr>"
                str = str + "<td valign='top'><img src='" + item[4] + "' width='45'></td>" # user avatar
                str = str + "<td valign='bottom'><a href='/users/" + item[2] + "'>@" + item[2] + ": </a>" + http + " - <i>posted on " + item[
                    1] + "</i></br></br></td></tr>" # username and contents
                users(item[2]) # generate /users/username page by users() function
                mentions(item[2]) # generate /mentions/username page by mentions function

    # if user logged in
    if username:
        # display the input field for adding posts instead of the title
        str = "<form action='/post' id='postform' method='POST'><input type='postfield' name='post' placeholder='post pssts (you can add #private tag to make the psst privately)' class='focus' onKeyPress='return submitenter(this,event)'></form>"
        for item in list:
            if(username==item[2]): # if user logged in, display his/her avatar, name, previous posts, the post mention, and logout option
                loginString = "<form action= '/logout' id='logoutform' name='logoutform' method='POST' ><table><tr><td><img src='" + item[4] + "' width='85'></td><td><h3>Logged in as " + username + "</h3><p><a href='/users/" + username + "'>Posted pssts</a></p><p><a href='/mentions/" + username + "'>@me pssts</a></p><p><a href='javascript: document.logoutform.submit();'>Logout</a></p></td></tr></table></form>"
        str = str + "<table>"
        at_user = "******" + username
        for item in list:
            content = interface.post_to_html(item[3])
            http = interface.post_to_html(content)

            # this if situation is for private message feature
            if((bool(private.lower() in http.lower()) == False) | (bool(at_user.lower() in http.lower())) | (bool(private.lower() in http.lower()) & bool(username.lower() in item[2].lower()))):
                str = str + "<tr>"
                str = str + "<td valign='top'><img src='" + item[4] + "' width='45'></td>" # user avatar
                str = str + "<td valign='bottom'><a href='/users/" + item[2] + "'>@" + item[2] + ": </a>" + http + " - <i>posted on " + item[
                        1] + "</i></br></br></td></tr>" # username and contents
                users(item[2]) # generate /users/username page by users() function
                mentions(item[2]) # generate /mentions/username page by mentions function
    str = str + "</table>"
    return template('base.tpl', base=str, validate='', login=loginString)
Example #17
0
def user_page(user_name):
    """ Gets user page with all recent posts
    :param user_name: The username of the user
    :return: The users page
    """
    posts = get_recent_posts(interface.post_list(db, user_name))
    dic = {
        "loginFailed": "False",
        "posts": posts,
        "name": user_name,
        "userpic": interface.user_get(db, user_name)[2]
    }
    dic.update(determine_user())
    return template("user.tpl", dic)
Example #18
0
def search():
    """Search feature, can search user name and / or contents"""
    db = COMP249Db()
    username = session_user(db) # retrieve user session information from the database
    private = "#private" # string that makes the post private
    loginString = ""
    content = ""
    http = ""
    if 'search' in request.forms:
        search = request.forms['search'] # get user inputs from the search field
        str = "<h2>Search results for '" + search + "':</h2>" # title
        list = interface.post_list(db, usernick=None, limit=50)
        if not username: # display the things below only if user not logged in
            # display input field for username and password if the user not logged in
            loginString = "<form id='loginform' method='POST' action ='/login'><input type='text' name='nick' placeholder='username' class='focus' onKeyPress='return submitenter(this,event)'><input type='password' name='password' placeholder='password' class='focus' onKeyPress='return submitenter(this,event)'></form>"
            str = str + "<table>"
            for item in list:
                content = interface.post_to_html(item[3])
                http = interface.post_to_html(content)

                # this if situation is for private message feature
                if ((bool(private.lower() in http.lower())==False) & ((bool(search.lower() in item[2].lower())) | (bool(search.lower() in http.lower())))):
                    str = str + "<tr>"
                    str = str + "<td valign='top'><img src='" + item[4] + "' width='45'></td>" # user avatar
                    str = str + "<td valign='bottom'><a href='/users/" + item[2] + "'>@" + item[2] + ": </a>" + http + " - <i>posted on " + \
                          item[1] + "</i></br></br></td></tr>" # username and contents
                    users(item[2]) # generate /users/username page by users() function
                    mentions(item[2]) # generate /mentions/username page by mentions() function
            str = str + "</table>"
        if username: # display the things below only if user logged in
            at_user = "******" + username
            for item in list:
                if(username==item[2]): # if user logged in, display his/her avatar, name, previous posts, the post mention, and logout option
                    loginString = "<form action= '/logout' id='logoutform' name='logoutform' method='POST' ><table><tr><td><img src='" + item[4] + "' width='85'></td><td><h3>Logged in as " + username + "</h3><p><a href='/users/" + username + "'>Posted pssts</a></p><p><a href='/mentions/" + username + "'>@me pssts</a></p><p><a href='javascript: document.logoutform.submit();'>Logout</a></p></td></tr></table></form>"
            str = str + "<table>"
            for item in list:
                content = interface.post_to_html(item[3])
                http = interface.post_to_html(content)

                # this if situation is for private message feature
                if (((bool(private.lower() in http.lower()) == False) | (bool(at_user.lower() in http.lower())) | (bool(private.lower() in http.lower()) & bool(username.lower() in item[2].lower()))) & ((bool(search.lower() in item[2].lower())) | (bool(search.lower() in http.lower())))):
                    str = str + "<tr>"
                    str = str + "<td valign='top'><img src='" + item[4] + "' width='45'></td>" # user avatar
                    str = str + "<td valign='bottom'><a href='/users/" + item[2] + "'>@" + item[2] + ": </a>" + http + " - <i>posted on " + \
                          item[1] + "</i></br></br></td></tr>" # username and contents
                    users(item[2]) # generate /users/username page by users() function
                    mentions(item[2]) # generate /mentions/username page by mentions() function
            str = str + "</table>"
        return template('base.tpl', base=str, validate='', login=loginString)
Example #19
0
def index(failed=False):
    db = COMP249Db()

    current_user = users.session_user(db)
    if current_user:
        html = get_form("logout")
    else:
        html = get_form("login")
        if failed:
            html += "Login Failed, please try again"

    posts = interface.post_list(db)

    for post in posts:
        html += format_post(post)

    return template('general', title="Welcome to Psst!", content=html)
Example #20
0
    def test_post_add(self):
        """Test adding new posts"""

        usernick = 'Bean'
        message = "one two three"

        postid = interface.post_add(self.db, usernick, message)

        # result should be an integer
        self.assertEqual(int, type(postid))

        # get all posts for this user (should be just one)
        posts = interface.post_list(self.db, usernick=usernick)
        self.assertEquals(1, len(posts))

        # check it's the same
        self.assertEquals(postid, posts[0][0])
    def test_post_add(self):
        """Test adding new posts"""

        usernick = 'Bean'
        message = "one two three"

        postid = interface.post_add(self.db, usernick, message)

        # result should be an integer
        self.assertEqual(int, type(postid))

        # get all posts for this user (should be just one)
        posts = interface.post_list(self.db, usernick=usernick)
        self.assertEquals(1, len(posts))

        # check it's the same
        self.assertEquals(postid, posts[0][0])
Example #22
0
def index(failed=False):
    db = COMP249Db()

    current_user = users.session_user(db)
    if current_user:
        html = get_form("logout")
    else:
        html = get_form("login")
        if failed:
            html += "Login Failed, please try again"

    posts = interface.post_list(db)

    for post in posts:
        html += format_post(post)

    return template('general', title="Welcome to Psst!", content=html)
Example #23
0
def user_page(name):
    db = COMP249Db()

    posts = interface.post_list(db, name)
    html = ""

    if users.session_user(db):
        html += get_form("logout")

    for post in posts:
        html += format_post(post)

    avatar = ""
    if posts:
        avatar += '<div id="avatar"><img src="' + posts[0][3] + '" alt="avatar"></div>'

    title = name + "'s Profile"
    return template('users', title=title, root="users/" + name, content=html, avatar=avatar)
Example #24
0
def index():
    """Home page, displays the welcome message and the most recent posts"""
    db = PsstDb()
    name = users.session_user(db)
    if users.follows(db, users.session_user(db)) > 0:
        re = interface.post_list_follows(db, users.get_following(db, name),
                                         name, 50)
    else:
        re = interface.post_list(db, None, 50)
    info = {
        'login': has_visited(),
        'searchVal': "",
        'usernamed': users.session_user(db),
        'title': "Welcome to Psst",
        'content': 'Welcome to Psst',
        'posts': re
    }
    return template('index', info)
Example #25
0
def user_page(name):
    """
    Returns the user about page, with a larger user avatar and username along with the posts made by the user
    """
    db = PsstDb()
    userpage = interface.post_list(db, name, 50)
    av = users.find_user(db, name)

    user = {
        'login': has_visited(),
        'usernamed': users.session_user(db),
        'title': name,
        'avatar': av[0][2],
        'username': name,
        'posts': userpage,
        'follows': users.does_follow(db, users.session_user(db), name),
        'following': users.get_following(db, users.session_user(db))
    }
    return template('userPosts', user)
Example #26
0
def posts(user):
    db = COMP249Db()
    cont = interface.post_list(
        db, user,
        50)  # grab the posts from the database for the user specified
    posts = []
    for row in cont:
        li = list(row)  #converting each tuple into a list
        print(li[4])
        li[4] = interface.post_to_html(
            li[4])  #converting the post message into suitable html
        posts.append(
            li)  #populating a list with data ready to display in the template
        print(li)
    print('posts below')
    print(posts)
    return template(os.path.join('views', 'general'),
                    title="Welcome to Psst!",
                    content=posts)
Example #27
0
def user_page(name):
    db = COMP249Db()

    posts = interface.post_list(db, name)
    html = ""

    if users.session_user(db):
        html += get_form("logout")

    for post in posts:
        html += format_post(post)

    avatar = ""
    if posts:
        avatar += '<div id="avatar"><img src="' + posts[0][
            3] + '" alt="avatar"></div>'

    title = name + "'s Profile"
    return template('users',
                    title=title,
                    root="users/" + name,
                    content=html,
                    avatar=avatar)
Example #28
0
def login():
    """Display this page if any invalid user identification"""
    db = COMP249Db()
    list = interface.post_list(db, usernick=None, limit=50)
    private = "#private" # string that makes the post private
    content = ""
    http = ""
    str = "<h2><b>Welcome to Psst.</b> Latest pssts:</h2>" # title
    str = str + "<table>"

    # display previous posts
    for item in list:
        content = interface.post_to_html(item[3])
        http = interface.post_to_html(content)

        # not display the posts with the '#private' tag
        if(bool(private.lower() in http.lower())==False): # only display the messages without '#private'
            str = str + "<tr>"
            str = str + "<td valign='top'><img src='" + item[4] + "' width='45'></td>" # user avatar
            str = str + "<td valign='bottom'><a href='/users/" + item[2] + "'>@" + item[2] + ": </a>" + http + " - <i>posted on " + item[
                    1] + "</i></br></br></td></tr>" # username and contents
            users(item[2]) # generate /users/username page by users() function
            mentions(item[2]) # generate /mentions/username page by mentions function
    str = str + "</table>"

    # if there are something within the login field...
    if 'nick' in request.forms:
        username = request.forms['nick'] # get username from the 'nick' field
        password = request.forms['password'] # get password from the 'password' field
        str2 = "<p style='color:red'>Failed.</p>"
        loginString = "<form id='loginform' method='POST' action ='/login'><input type='text' name='nick' placeholder='username' class='focus' onKeyPress='return submitenter(this,event)'><input type='password' name='password' placeholder='password' class='focus' onKeyPress='return submitenter(this,event)'></form>"
        if not check_login(db, username, password):
            return template('base.tpl', base=str, validate=str2, login=loginString) # display 'Failed' if invaild user identification
        generate_session(db, username) # generate the user session
        response.set_header('Location', '/')
        response.status = 303
        return "Redirect to /" # redirect to /
Example #29
0
def user_page(usernick):
    """generate the users posts"""
    user_posts = interface.post_list(db, usernick)
    return template('general', title=usernick + "'s Posts", posts=user_posts)
Example #30
0
def index():

    posts = interface.post_list(db)
    return template('general', title="Welcome to Psst", posts=posts)