2
2
__all__ = ['LDAP' ]
3
3
4
4
import re
5
+ from functools import wraps
6
+
5
7
import ldap
6
8
import ldap .filter
7
- from functools import wraps
8
- from flask import abort , current_app , g , make_response , redirect , url_for , request
9
+ from flask import abort , current_app , g , make_response , redirect , url_for , \
10
+ request
9
11
10
12
try :
11
13
from flask import _app_ctx_stack as stack
@@ -202,8 +204,8 @@ def get_user_groups(self, user):
202
204
[current_app .config ['LDAP_USER_GROUPS_FIELD' ]])
203
205
conn .unbind_s ()
204
206
if records :
205
- if current_app .config ['LDAP_USER_GROUPS_FIELD' ] in records [ 0 ][
206
- 1 ]:
207
+ if current_app .config ['LDAP_USER_GROUPS_FIELD' ] in \
208
+ records [ 0 ][ 1 ]:
207
209
groups = records [0 ][1 ][
208
210
current_app .config ['LDAP_USER_GROUPS_FIELD' ]]
209
211
result = [re .findall ('(?:cn=|CN=)(.*?),' , group )[0 ] for
@@ -259,7 +261,8 @@ def login_required(func):
259
261
@wraps (func )
260
262
def wrapped (* args , ** kwargs ):
261
263
if g .user is None :
262
- return redirect (url_for (current_app .config ['LDAP_LOGIN_VIEW' ], next = request .path ))
264
+ return redirect (url_for (current_app .config ['LDAP_LOGIN_VIEW' ],
265
+ next = request .path ))
263
266
return func (* args , ** kwargs )
264
267
265
268
return wrapped
@@ -272,7 +275,7 @@ def group_required(groups=None):
272
275
273
276
The login view is responsible for asking for credentials, checking
274
277
them, and setting ``flask.g.user`` to the name of the authenticated
275
- user and ``flask.g.ldap_groups`` to the authenticated's user's groups
278
+ user and ``flask.g.ldap_groups`` to the authenticated user's groups
276
279
if the credentials are acceptable.
277
280
278
281
:param list groups: List of groups that should be able to access the
@@ -284,7 +287,8 @@ def wrapper(func):
284
287
def wrapped (* args , ** kwargs ):
285
288
if g .user is None :
286
289
return redirect (
287
- url_for (current_app .config ['LDAP_LOGIN_VIEW' ], next = request .path ))
290
+ url_for (current_app .config ['LDAP_LOGIN_VIEW' ],
291
+ next = request .path ))
288
292
289
293
match = [group for group in groups if group in g .ldap_groups ]
290
294
if not match :
0 commit comments