def login(): if is_authenticated(): return redirect(url_for("home")) form = LoginForm(request.form) if request.method == 'POST' and form.validate(): user.user_login(form) return redirect(url_for("home")) return render_template('login.html', form=form)
def upvote(topic_id): if request_wants_html(): if not is_authenticated(): return redirect(url_for('login')) if request.method == 'GET': response = create_upvote_html(topic_id) return redirect(url_for('get_topic', topic_id=topic_id)) else: if request.method == 'POST': response = create_upvote_json(request.json, topic_id) return response
def create_topic(): if request_wants_html(): if not is_authenticated(): return redirect(url_for('login')) form = TopicForm(request.form) if request.method == 'POST' and form.validate(): new_topic = topic.create_topic_html(form) return render_template("topic_created.html", topic=new_topic) return render_template('topic.html', form=form) else: if request.method == 'POST': return topic.create_topic_json(request.json)
def logout(): if not is_authenticated(): return redirect(url_for('login')) user.user_logout() return redirect(url_for('login'))