示例#1
0
def new():

    code = title = ''
    author = session.get('author', '')
    ## get the language from the session (if present)
    language = session.get('language', 'text')
    parent = None
    private = False
    verified = session.get('verified')

    if request.method == 'POST':
        ## if user is not verified, then we check a captcha

        if not verified:

            payload = { 'privatekey' : config['recaptcha_private_key']
                      , 'remoteip' : request.remote_addr
                      , 'challenge' : request.form['recaptcha_challenge_field']
                      , 'response' : request.form['recaptcha_response_field']
                      }
            response = requests.post("http://www.google.com/recaptcha/api/verify", data=payload)

        if verified or response.text.split('\n')[0] == 'true':
            session['verified'] = True
            code = request.form['code']
            language = request.form['language']
            author = request.form['author']
            title = request.form['title']
            private = 'private' in request.form
            if 'parent' in request.form:
                parent = Paste.get(request.form['parent'])

            if code and language:
                paste = Paste(code, language, session['user'], title, author,
                              parent, private)
                paste.save()

                ## set some defaults for next time around
                session['language'] = language
                session['author'] = author

                ## show the paste
                return redirect(url_for('view', uri=paste.uri))

    return render_template(
        'new.html',
        code=code,
        author=author,
        session_author=author,
        title=title,
        private=private,
        language=language,
        languages=languages,
        preferred=preferred_languages,
        recaptcha_public_key=config['recaptcha_public_key'],
        not_verified=(not verified)
    )
示例#2
0
def view(uri, raw=False):
    session_author = session.get('author', '')
    paste = Paste.get(uri)
    if not paste:
        abort(404)

    if raw:
        ## weed out @h@ lines
        code = paste.code.splitlines()
        for idx, line in enumerate(code):
            if line[0:3] == '@h@':
                code[idx] = line[3:]
        code = '\n'.join(code)
        return Response(code, 200, mimetype='text/plain; charset=utf-8')
    else:
        return render_template(
            'view.html',
            session_author=session_author,
            paste=paste,
            user=session['user'],
        )
示例#3
0
def delete(uri=None):
    session_author = session.get('author', '')

    uri = request.form.get('uri', uri)
    paste = Paste.get(uri)
    if not paste:
        abort(404)

    if request.method == 'POST':

        if paste.user != session['user']:
            abort(403)

        paste.delete()
        flash("Deleted Paste")

        return redirect(url_for('all'))

    return render_template(
        'delete.html',
        paste=paste,
        user=session['user'],
        session_author=session_author,
    )