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

24 lines
660 B
Python
Raw Permalink Normal View History

from __future__ import absolute_import
2016-09-05 10:37:59 +03:00
from flask import current_app, request, redirect, Blueprint, flash, url_for, session
2015-10-15 01:36:22 +03:00
from flask_ldap_login import LDAPLoginForm
from .models import User
2016-09-05 10:37:59 +03:00
2015-10-15 01:36:22 +03:00
blueprint = Blueprint('auth.ldap', __name__)
2015-11-22 19:19:11 +02:00
2015-10-15 01:36:22 +03:00
@blueprint.route("/login/ldap", methods=['POST'])
def login():
form = LDAPLoginForm()
if not form.validate():
flash('Form invalid', 'warning')
return redirect(url_for('auth.login'))
2015-10-15 23:55:38 +03:00
if User.auth(form.user, request.form['password']):
return redirect(session.get("next_url") or url_for(current_app.config['ROOT_ENDPOINT']))
2015-10-15 01:36:22 +03:00
else:
return redirect(url_for('auth.login'))