def new(): category_id = None preview = None if 'category' in request.args: rv = Category.query.filter_by(slug=request.args['category']).first() if rv is not None: category_id = rv.id if request.method == 'POST': category_id = request.form.get('category', type=int) if 'preview' in request.form: preview = format_creole(request.form['body']) else: title = request.form['title'] body = request.form['body'] if not body: flash(u'Error: you have to enter a snippet') else: category = Category.query.get(category_id) if category is not None: snippet = Snippet(g.user, title, body, category) db_session.add(snippet) db_session.commit() flash(u'Your snippet was added') return redirect(snippet.url) return render_template('snippets/new.html', categories=Category.query.order_by(Category.name).all(), active_category=category_id, preview=preview)
def new(): category_id = None preview = None if 'category' in request.args: rv = Category.query.filter_by(slug=request.args['category']).first() if rv is not None: category_id = rv.id if request.method == 'POST': category_id = request.form.get('category', type=int) if 'preview' in request.form: preview = format_creole(request.form['body']) else: title = request.form['title'] body = request.form['body'] if not body: flash(u'Error: you have to enter a snippet') else: category = Category.query.get(category_id) if category is not None: snippet = Snippet(g.user, title, body, category) db_session.add(snippet) db_session.commit() flash(u'Your snippet was added') return redirect(snippet.url) return render_template('snippets/new.html', categories=Category.query.order_by( Category.name).all(), active_category=category_id, preview=preview)
def storeAssociation(self, server_url, association): assoc = OpenIDAssociation(server_url=server_url, handle=association.handle, secret=association.secret.encode('base64'), issued=association.issued, lifetime=association.lifetime, assoc_type=association.assoc_type) db_session.add(assoc) db_session.commit()
def storeAssociation(self, server_url, association): assoc = OpenIDAssociation( server_url=server_url, handle=association.handle, secret=association.secret.encode("base64"), issued=association.issued, lifetime=association.lifetime, assoc_type=association.assoc_type, ) db_session.add(assoc) db_session.commit()
def first_login(): if g.user is not None or "openid" not in session: return redirect(url_for(".login")) if request.method == "POST": if "cancel" in request.form: del session["openid"] flash(u"Login was aborted") return redirect(url_for("general.login")) db_session.add(User(request.form["name"], session["openid"])) db_session.commit() flash(u"Successfully created profile and logged in") return redirect(oid.get_next_url()) return render_template("general/first_login.html", next=oid.get_next_url(), openid=session["openid"])
def useNonce(self, server_url, timestamp, salt): if abs(timestamp - time()) > nonce.SKEW: return False rv = OpenIDUserNonce.query.filter( (OpenIDUserNonce.server_url == server_url) & (OpenIDUserNonce.timestamp == timestamp) & (OpenIDUserNonce.salt == salt) ).first() if rv is not None: return False rv = OpenIDUserNonce(server_url=server_url, timestamp=timestamp, salt=salt) db_session.add(rv) db_session.commit() return True
def useNonce(self, server_url, timestamp, salt): if abs(timestamp - time()) > nonce.SKEW: return False rv = OpenIDUserNonce.query.filter( (OpenIDUserNonce.server_url == server_url) & (OpenIDUserNonce.timestamp == timestamp) & (OpenIDUserNonce.salt == salt)).first() if rv is not None: return False rv = OpenIDUserNonce(server_url=server_url, timestamp=timestamp, salt=salt) db_session.add(rv) db_session.commit() return True
def first_login(): if g.user is not None or 'openid' not in session: return redirect(url_for('.login')) if request.method == 'POST': if 'cancel' in request.form: del session['openid'] flash(u'Login was aborted') return redirect(url_for('general.login')) db_session.add(User(request.form['name'], session['openid'])) db_session.commit() flash(u'Successfully created profile and logged in') return redirect(oid.get_next_url()) return render_template('general/first_login.html', next=oid.get_next_url(), openid=session['openid'])
def show(id): snippet = Snippet.query.get(id) if snippet is None: abort(404) if request_wants_json(): return jsonify(snippet=snippet.to_json()) if request.method == 'POST': title = request.form['title'] text = request.form['text'] if text: db_session.add(Comment(snippet, g.user, title, text)) db_session.commit() flash(u'Your comment was added') return redirect(snippet.url) return render_template('snippets/show.html', snippet=snippet)
def new_category(): category = Category(name=request.form['name']) db_session.add(category) db_session.commit() flash(u'Category %s created.' % category.name) return redirect(url_for('.manage_categories'))