Beispiel #1
0
def login():
    ''' For GET Requests, display login form
    For POSTs, login user by processing form
    '''
    # If user is logged in, redirect to home immediately
    if(current_user.is_active):
        return redirect(url_for('home'))
    # Otherwise, handle GET and POST normally
    if (request.method == 'GET'):
        return render_template('login.html', page='login')
    elif (request.method == 'POST'):
        user = User.query.filter_by(username=request.form['username']).first()
        if(user is None):
            flash("Username and password combination not found", 'error')
            return redirect(url_for("login"))
        elif(bcrypt.check_password_hash(user.pwd, request.form['password'])):
            user.authenticated = True
            db.session.add(user)
            db.session.commit()
            remember_login=False
            if('remember' in request.form):
                remember_login=True
            login_user(user, remember=remember_login)
            # Re-establish OAuth for reddit object if it exists
            reddit_oauth = r_h.establish_oauth(reddit,
                            current_user.reddit_user)
            return redirect(url_for('home'))
Beispiel #2
0
def upload_and_post():
    if (request.method == 'POST' and
            r_h.establish_oauth(reddit, current_user.reddit_user)):
        # TODO: Sanitize inputs
        print(request.form)
        imgur_response = im_control.image_upload(db, 
                request.form['img_url'], current_user.imgur_user)
        print(imgur_response)
        if ('success' in imgur_response and 
                imgur_response['success'] == True):
            # Image Uploaded
            # Optional comments
            cur_comment = ""
            if ('comment' in request.form):
                cur_comment = request.form['comment']

            args = {'url': imgur_response['imgur_url'],
                    'title': request.form['title'],
                    'subreddit': request.form['subreddit'],
                    'comment': cur_comment}
            link = r_h.submit_post_and_comment(reddit, 
                    current_user.reddit_user,
                    args)
            flash(link, "success")
        elif ('success' not in imgur_response): 
            """Internal coding error or structural
            change in imgur_backend handling"""
            return 'Unhandled server error'
        elif (imgur_response['success'] == False):
            flash(imgur_response['error'], 'danger')
    return redirect(url_for("home")) # Always redirect back to home
Beispiel #3
0
def account_reddit():
    if (current_user.reddit_user):
        if(r_h.establish_oauth(reddit, current_user.reddit_user)):
            return render_template("account_reddit_linked.html",
                    page="account_reddit_linked",
                    in_title="Account | Reddit | Linking")
        else:
            return "Unhandled error"
    else:
        return render_template('account_reddit_unlinked.html',
                page='account_reddit_unlinked',
                in_title="Account | Reddit | Linking",
                request_url = r_h.get_authorize_url(reddit))