fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixes #4076: Recommendations from collections.
[wolnelektury.git]
/
src
/
basicauth.py
diff --git
a/src/basicauth.py
b/src/basicauth.py
index
befcc6f
..
b4acb46
100644
(file)
--- a/
src/basicauth.py
+++ b/
src/basicauth.py
@@
-7,8
+7,8
@@
import base64
from django.http import HttpResponse
from django.contrib.auth import authenticate, login
from django.http import HttpResponse
from django.contrib.auth import authenticate, login
-#
-def view_or_basicauth(view, request, test_func, realm
=
"", *args, **kwargs):
+
+def view_or_basicauth(view, request, test_func, realm
=
"", *args, **kwargs):
"""
This is a helper function used by 'logged_in_or_basicauth' and
'has_perm_or_basicauth' (deleted) that does the nitty of determining if they
"""
This is a helper function used by 'logged_in_or_basicauth' and
'has_perm_or_basicauth' (deleted) that does the nitty of determining if they
@@
-28,7
+28,7
@@
def view_or_basicauth(view, request, test_func, realm = "", *args, **kwargs):
# NOTE: We are only support basic authentication for now.
#
if auth[0].lower() == "basic":
# NOTE: We are only support basic authentication for now.
#
if auth[0].lower() == "basic":
- uname, passwd = base64.b64decode(auth[1]).split(':')
+ uname, passwd = base64.b64decode(auth[1]
.encode('utf-8')).decode('utf-8'
).split(':')
user = authenticate(username=uname, password=passwd)
if user is not None:
if user.is_active:
user = authenticate(username=uname, password=passwd)
if user is not None:
if user.is_active:
@@
-44,10
+44,10
@@
def view_or_basicauth(view, request, test_func, realm = "", *args, **kwargs):
response.status_code = 401
response['WWW-Authenticate'] = 'Basic realm="%s"' % realm
return response
response.status_code = 401
response['WWW-Authenticate'] = 'Basic realm="%s"' % realm
return response
-
+
#
#
-def logged_in_or_basicauth(realm
=
""):
+def logged_in_or_basicauth(realm
=
""):
"""
A simple decorator that requires a user to be logged in. If they are not
logged in the request is examined for a 'authorization' header.
"""
A simple decorator that requires a user to be logged in. If they are not
logged in the request is examined for a 'authorization' header.
@@
-79,7
+79,7
@@
def logged_in_or_basicauth(realm = ""):
def view_decorator(func):
def wrapper(request, *args, **kwargs):
return view_or_basicauth(func, request,
def view_decorator(func):
def wrapper(request, *args, **kwargs):
return view_or_basicauth(func, request,
- lambda u: u.is_authenticated
()
,
+ lambda u: u.is_authenticated,
realm, *args, **kwargs)
return wrapper
return view_decorator
realm, *args, **kwargs)
return wrapper
return view_decorator