Esempio n. 1
0
def login():

    usern = request.forms.get('nick')
    passw = request.forms.get('password')

    if users.check_login(COMP249Db(), usern, passw) is True:
        users.delete_session(COMP249Db(), usern)
        session = users.generate_session(COMP249Db(), usern)
        return redirect('/')
    return index(False)
Esempio n. 2
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)
Esempio n. 3
0
def about():
    user = users.session_user(COMP249Db())
    info = {
        'title': 'Psst!',
        'message': 'About',
        'header': 'About Psst!',
        'user': user,
        'avatar': interface.user_avatar(COMP249Db(), user),
        'login': login
    }
    return template('views/about.html', info)
Esempio n. 4
0
def mentionspage(name):
    user = users.session_user(COMP249Db())
    info = {
        'title': 'Psst!',
        'message': name + "'s mentions",
        'header': 'Posts that mention ' + name,
        'user': user,
        'avatar': interface.user_avatar(COMP249Db(), user),
        'login': login
    }
    info['posts'] = interface.post_list_mentions(COMP249Db(), name)
    return template('views/mentions.html', info)
Esempio n. 5
0
def myPosts():
    user = users.session_user(COMP249Db())
    searchkey = request.forms.get('searchbar')
    info = {
        'title': 'Psst!',
        'message': "Search",
        'header': 'Posts with "' + searchkey + '"',
        'user': user,
        'avatar': interface.user_avatar(COMP249Db(), user),
        'login': login
    }
    info['posts'] = interface.post_search(COMP249Db(), searchkey)
    print(info['posts'])
    return template('views/search.html', info)
Esempio n. 6
0
def registerSubmit():
    """
    注册用户填写完毕后提交请求
    :return:
    """
    flowTowDataBase = COMP249Db()
    userNick = users.session_user(db=flowTowDataBase)
    if userNick:
        registerInfo = "Please logout first"
        showRegister = False
    else:
        nick = request.POST.get("nick")
        password = request.POST.get("password")
        if users.add_user(flowTowDataBase, nick, password):
            registerInfo = "Registered successfully!You can login in the upper right corner now."
            showRegister = False
        else:
            registerInfo = "Registration failed, your registered user name already exists."
            showRegister = True
    renderDict = {
        "title": "FlowTow!",
        "homeActive": False,
        "aboutActive": False,
        "userNick": userNick,
        "myActive": False,
        "registerInfo": registerInfo,
        "showRegister": showRegister
    }
    return template("register", renderDict)
Esempio n. 7
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)
Esempio n. 8
0
 def setUp(self):
     # open an in-memory database for testing
     self.db = COMP249Db(':memory:')
     self.db.create_tables()
     self.db.sample_data(random=False)
     self.users = self.db.users
     self.posts = self.db.posts
Esempio n. 9
0
 def setUp(self):
     # open an in-memory database for testing
     self.db = COMP249Db(':memory:')
     self.db.create_tables()
     self.db.sample_data()
     self.images = self.db.images
     self.users = self.db.users
Esempio n. 10
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 /
Esempio n. 11
0
def mentions(username):
    """Generate the webpage that displays @users"""
    db = COMP249Db()
    uname = session_user(db) # retrieve user session information from the database
    loginString = ""
    content = ""
    http = ""
    list = interface.post_list_mentions(db, usernick=username, limit=50)
    str = ""
    avatar = ""

    str = "<h2>Posts mentioned " + username + ":</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 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)
Esempio n. 12
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)
Esempio n. 13
0
def upload():
    """Request to Upload an image; When a user is logged in, they have the
    ability to upload an image of there choice. It must be of image file type.
    If it is not the right file type, they will be presented with the File error display.
    Otherwise, they will be redirected to the My Images page."""
    db = COMP249Db()

    curr_user = users.session_user(db)
    if not curr_user:
        redirect('/')

    imagefile = request.files.get('imagefile')
    name, ext = os.path.splitext(imagefile.filename)
    if ext not in ('.jpeg', '.jpg', '.png', '.gif'):
        print("extension error")
        return template('fileerror.html',
                        title="File Error",
                        session=None,
                        name=None)

    save_path = os.path.join(UPLOAD_DIR, imagefile.filename)
    imagefile.save(save_path)

    interface.add_image(db, imagefile.filename, curr_user)

    redirect('/my')
Esempio n. 14
0
 def setUp(self):
     self.app = TestApp(main.application)
     # init database
     self.db = COMP249Db()
     self.db.create_tables()
     self.db.sample_data(random=False)
     self.users = self.db.users
     self.posts = self.db.posts
Esempio n. 15
0
def new_post():
    db = COMP249Db()
    message = request.forms.get('post')
    interface.post_add(db, users.session_user(db), message)

    response.set_header('Location', '/')
    response.status = 303
    return 'Redirect to /'
Esempio n. 16
0
 def setUp(self):
     self.app = webtest.TestApp(main.application)
     self.db = COMP249Db()
     self.db.create_tables()
     self.db.sample_data()
     self.users = self.db.users
     bottle.debug(
     )  # force debug messages in error pages returned by webtest
Esempio n. 17
0
def logout():
    """
    处理登出
    :return:重定向至首页
    """
    flowTowDataBase = COMP249Db()
    requestUser = users.session_user(flowTowDataBase)
    users.delete_session(db=flowTowDataBase, usernick=requestUser)
    return redirect('/')
Esempio n. 18
0
def logout():
    """Logout"""
    db = COMP249Db()
    username = session_user(db) # retrieve user session information from the database
    if username:
        delete_session(db, username) # remove user session
        response.set_header('Location', '/')
        response.status = 303
        return "Redirect to /" # redirect to /
Esempio n. 19
0
def logout():
    """Post request for Logout; Upon login, if user submits logout form
    their session and cookie is deleted. They are then redirected to the Main Page."""
    db = COMP249Db()
    curr_user = users.session_user(db)
    if curr_user:
        users.delete_session(db, curr_user)
        response.delete_cookie(COOKIE_NAME)
    redirect('/')
Esempio n. 20
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)
Esempio n. 21
0
def unlike():
    """Post request to Unlike image; If a user has liked an image,
    they are able to unlike the image (reverse the like process)."""
    db = COMP249Db()
    img = request.forms.get('filename')
    curr_user = None
    if request.get_cookie(COOKIE_NAME):
        curr_user = users.session_user(db)
    interface.unlike(db, img, curr_user)
    redirect('/')
Esempio n. 22
0
def add_post():
    """Adding post"""
    db = COMP249Db()
    username = session_user(db) # retrieve user session information from the database
    if username:
        content = request.forms['post'] # get user inputs from the input form 'post'
        interface.post_add(db, username, content) # add post by post_add function of interface.py
        response.set_header('Location', '/')
        response.status = 303
        return "Redirect to /" # redirect to /
Esempio n. 23
0
def like_img():
    """Post request to Like image; Upon login, when the user likes an image,
    that image information is retrieved and the number of likes is increased by adding
    to the likes table."""
    db = COMP249Db()
    img_liked = request.forms.get('filename')
    curr_user = None
    if request.get_cookie(COOKIE_NAME):
        curr_user = users.session_user(db)
    interface.add_like(db, img_liked, curr_user)
    redirect('/')
Esempio n. 24
0
def index():
    """Home page"""

    db = COMP249Db()

    info = dict()
    info['title'] = 'Have a Conversation'
    # get the list of messages from the database
    info['messages'] = get_messages(db)

    return template('default.tpl', info)
Esempio n. 25
0
def tags(tag):
    """Return a page of messages containing the given tag"""

    db = COMP249Db()

    info = dict()
    info['title'] = 'Messages with tag <em>#' + tag + "</em>"
    # get the list of messages from the database
    info['messages'] = get_tag_messages(db, tag)

    return template('default.tpl', info)
Esempio n. 26
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)
Esempio n. 27
0
def mentions(who):
    """Generate a page that lists the mentions of a 
    given user"""
    db = COMP249Db()

    info = dict()
    info['title'] = "Mentions of " + who

    info['posts'] = interface.post_list_mentions(db, usernick=who)

    # re-use the index template since this is just a list of posts
    return template('index', info)
Esempio n. 28
0
def upload():
    """
    文件上传页面
    :return: 返回页面渲染字典
    """
    flowTowDataBase = COMP249Db()
    userNick = users.session_user(db=flowTowDataBase)
    if userNick:
        uploads.uploadImage(db=flowTowDataBase, userNick=userNick)
        return redirect('/my')
    else:
        return redirect('/')
Esempio n. 29
0
def aboutpg():
    """About page; Displays information on the Flowtow site."""
    db = COMP249Db()
    curr_session = None
    curr_user = None
    if request.get_cookie(COOKIE_NAME):
        curr_session = request.get_cookie(COOKIE_NAME)
        curr_user = users.session_user(db)
    return template('aboutpg.html',
                    title="About",
                    session=curr_session,
                    name=curr_user)
Esempio n. 30
0
def like():
    """
    处理喜欢图片的请求
    :return: 重定向至指定页面
    """
    filename = request.POST.get('filename')
    flowTowDataBase = COMP249Db()
    userNick = users.session_user(db=flowTowDataBase)
    interface.add_like(db=flowTowDataBase,
                       filename=filename,
                       usernick=userNick)
    return redirect('/')