2016-08-20 01:48:00 +03:00
|
|
|
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
|
|
|
|
|
2016-08-20 01:48:00 +03:00
|
|
|
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']):
|
2016-07-09 06:39:11 +03:00
|
|
|
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'))
|