realms-wiki/realms/modules/auth/views.py

31 lines
909 B
Python
Raw Permalink Normal View History

from __future__ import absolute_import
from flask import current_app, render_template, request, redirect, Blueprint, flash, url_for, session
2016-09-05 23:54:53 +03:00
from flask_login import logout_user, current_user
2016-08-20 20:37:22 +03:00
from .models import Auth
2013-12-03 22:09:57 +02:00
blueprint = Blueprint('auth', __name__, template_folder='templates')
2013-12-03 22:09:57 +02:00
2014-08-30 18:06:12 +03:00
@blueprint.route("/login", methods=['GET', 'POST'])
2014-08-20 18:28:25 +03:00
def login():
next_url = request.args.get('next') or url_for(current_app.config['ROOT_ENDPOINT'])
2016-09-06 00:19:28 +03:00
if current_user.is_authenticated:
2016-09-05 23:54:53 +03:00
return redirect(next_url)
session['next_url'] = next_url
2015-10-14 06:52:30 +03:00
return render_template("auth/login.html", forms=Auth.login_forms())
2014-08-30 18:06:12 +03:00
2015-10-14 06:52:30 +03:00
@blueprint.route("/logout")
def logout():
logout_user()
flash("You are now logged out")
return redirect(url_for(current_app.config['ROOT_ENDPOINT']))
2014-08-30 18:06:12 +03:00
@blueprint.route("/settings", methods=['GET', 'POST'])
def settings():
return render_template("auth/settings.html")