Esempio n. 1
0
def signup_handler(response):
    name = response.get_field('name', '')
    email = response.get_field('email', '')
    password = response.get_field('password', '')
    confpassword = response.get_field('confpassword', '')
    usr_description = response.get_field('usr_describe', '')

    #when done with mvp keep entered fields
    if (not name) or (not email) or (not password) or (not confpassword):
        user = get_current_user(response)
        html = render_template(
            'signup.html', {
                'user': user,
                'errorMessage':
                "You must fill in all fields. Please try again."
            })
        response.write(html)
    elif password != confpassword:
        user = get_current_user(response)
        html = render_template(
            'signup.html', {
                'user': user,
                'errorMessage': "Password did not match. Please try again."
            })
        response.write(html)
    elif len(password) < 6:
        user = get_current_user(response)
        html = render_template(
            'signup.html', {
                'user':
                user,
                'errorMessage':
                "Password must be longer than 6 characters. Please try again."
            })
        response.write(html)
    elif password.lower() == 'password':
        user = get_current_user(response)
        html = render_template(
            'signup.html', {
                'user':
                user,
                'errorMessage':
                "'Password' is far to weak. Please submit a different password."
            })
        response.write(html)
    else:
        try:
            user = User.register(email, password, name, usr_description)
            response.set_secure_cookie('userCookie', email)
            response.redirect('/home')
        except ValueError as e:
            user = get_current_user(response)
            html = render_template('signup.html', {
                'user': user,
                'errorMessage': str(e)
            })
            response.write(html)
Esempio n. 2
0
def demo(response):
    user = get_current_user(response)
    html = render_template('demo.html', {
        'user': user,
        'comments': ['great', 'meh']
    })
    response.write(html)
Esempio n. 3
0
def view_post(response, post_id):
    try:
        post = Post.get(post_id)
        user = get_current_user(response)
        comments = Post.comments(post_id)
        for c in comments:
            c.author = User.get_by_id(c.author)

        poster = User.get_by_id(post.author_id)
        html = render_template('content.html', {
            'user': user,
            'post': post,
            'poster': poster,
            'comments': comments
        })
        response.write(html)
    except Exception as e:
        print(e)
        user = get_current_user(response)
        html = render_template('404errorpage.html', {'user': user})
        response.write(html)
Esempio n. 4
0
def login_handler(response):
    email = response.get_field("email")
    password = response.get_field("password")
    try:
        user = User.login(email, password)
        response.set_secure_cookie('userCookie', email)
        response.redirect('/home')
    except ValueError:
        user = get_current_user(response)
        html = render_template('login.html', {
            'user': user,
            'invalidUser': "******"
        })
        response.write(html)
Esempio n. 5
0
def submit_handler(response):
    user = get_current_user(response)
    title = response.get_field("title")
    location = response.get_field("location")
    image = response.get_file("postImage")
    description = response.get_field("description")

    if (not title) or (not location) or (not image) or (not description) or (
            image[1] is None):
        html = render_template('new_post.html', {
            'user': user,
            'invalidPost': "Please fill in all fields."
        })
        response.write(html)
    else:
        pictureName = 'static/postimages/' + title + '.' + image[1].split(
            '/')[1]
        with open(pictureName, 'wb') as pictureFile:
            pictureFile.write(image[2])
        createPost = Post.create(user.user_id, title, description, pictureName,
                                 location)
        response.redirect("/post/" + str(createPost.id))
Esempio n. 6
0
def home(response):
    user = get_current_user(response)
    posts = Post.get_by_recent(10)
    print(posts)
    html = render_template('main.html', {'user': user, 'posts': posts})
    response.write(html)
Esempio n. 7
0
def profile(response, name):
    user = get_current_user(response)
    posts = User.get_posts(user.user_id)
    html = render_template('profile.html', {'user': user, 'posts': posts})
    response.write(html)
Esempio n. 8
0
def submit(response):
    user = get_current_user(response)
    html = render_template('new_post.html', {'user': user})
    response.write(html)
Esempio n. 9
0
def signup(response):
    user = get_current_user(response)
    html = render_template('signup.html', {'user': user})
    response.write(html)
Esempio n. 10
0
def login(response):
    user = get_current_user(response)
    html = render_template('login.html', {'user': user})
    response.write(html)
Esempio n. 11
0
def notfound(response):
    user = get_current_user(response)
    html = render_template('404errorpage.html', {'user': user})
    response.write(html)
Esempio n. 12
0
def profile(response, name):
    user = get_current_user(response)
    print(user)
    print(user.profile_picture)
    html = render_template('profile.html', {'user': user})
    response.write(html)