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

28 lines
1 KiB
Python
Raw Normal View History

<<<<<<< HEAD
from flask import current_app, request, redirect, Blueprint, flash, url_for, session
2015-10-15 01:36:22 +03:00
from ..ldap.models import User
=======
from __future__ import absolute_import
from flask import current_app, request, redirect, Blueprint, flash, url_for
>>>>>>> systematic use of `from __future__ import absolute_import`. it eliminates `import NAME` confusion with very common names (eg. `import ldap` is very ambiguous: can be a ldap module from realms-wiki, a ldap module from flask-ldap-login, or `python-ldap` module.
2015-10-15 01:36:22 +03:00
from flask_ldap_login import LDAPLoginForm
from .models import User
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'))