ldap first pass
This commit is contained in:
parent
3c2f4a0445
commit
2eaf09dc78
13 changed files with 148 additions and 25 deletions
|
@ -0,0 +1,4 @@
|
|||
from flask_ldap_login import LDAPLoginManager
|
||||
|
||||
ldap_mgr = LDAPLoginManager()
|
||||
|
7
realms/modules/auth/ldap/forms.py
Normal file
7
realms/modules/auth/ldap/forms.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from flask_wtf import Form
|
||||
from wtforms import StringField, PasswordField, validators
|
||||
|
||||
|
||||
class LoginForm(Form):
|
||||
email = StringField('Email', [validators.DataRequired()])
|
||||
password = PasswordField('Password', [validators.DataRequired()])
|
31
realms/modules/auth/ldap/models.py
Normal file
31
realms/modules/auth/ldap/models.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
from flask import current_app, render_template
|
||||
from flask.ext.login import login_user
|
||||
from realms import ldap
|
||||
from flask_ldap_login import LDAPLoginForm
|
||||
from ..models import BaseUser
|
||||
import bcrypt
|
||||
|
||||
users = {}
|
||||
|
||||
@ldap.save_user
|
||||
def save_user(username, userdata):
|
||||
users[username] = User(username, userdata)
|
||||
return users[username]
|
||||
|
||||
class User(BaseUser):
|
||||
type = 'ldap'
|
||||
|
||||
def __init__(self, username, data):
|
||||
self.id = username
|
||||
self.username = username
|
||||
self.data = data
|
||||
|
||||
@staticmethod
|
||||
def login_form():
|
||||
form = LDAPLoginForm()
|
||||
return render_template('auth/ldap/login.html', form=form)
|
||||
|
||||
@staticmethod
|
||||
def auth(*args):
|
||||
login_user(args[0].user, remember=True)
|
||||
return True
|
18
realms/modules/auth/ldap/views.py
Normal file
18
realms/modules/auth/ldap/views.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from flask import current_app, request, redirect, Blueprint, flash, url_for
|
||||
from ..ldap.models import User
|
||||
from flask_ldap_login import LDAPLoginForm
|
||||
|
||||
blueprint = Blueprint('auth.ldap', __name__)
|
||||
|
||||
@blueprint.route("/login/ldap", methods=['POST'])
|
||||
def login():
|
||||
form = LDAPLoginForm()
|
||||
|
||||
if not form.validate():
|
||||
flash('Form invalid', 'warning')
|
||||
return redirect(url_for('auth.login'))
|
||||
|
||||
if User.auth(form.user):
|
||||
return redirect(request.args.get("next") or url_for(current_app.config['ROOT_ENDPOINT']))
|
||||
else:
|
||||
return redirect(url_for('auth.login'))
|
Loading…
Add table
Add a link
Reference in a new issue