forked from DGNum/gestioCOF
Add password auth decorator
This commit is contained in:
parent
be5218f7e1
commit
c1a99453d5
1 changed files with 23 additions and 0 deletions
23
kfet/auth/decorators.py
Normal file
23
kfet/auth/decorators.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
from functools import wraps
|
||||||
|
|
||||||
|
from kfet.auth.backends import AccountBackend
|
||||||
|
|
||||||
|
|
||||||
|
def kfet_password_auth(view_func):
|
||||||
|
def get_kfet_password(request):
|
||||||
|
return request.META.get("HTTP_KFETPASSWORD") or request.POST.get("KFETPASSWORD")
|
||||||
|
|
||||||
|
@wraps(view_func)
|
||||||
|
def _wrapped_view(request, *args, **kwargs):
|
||||||
|
if request.method == "POST":
|
||||||
|
temp_request_user = AccountBackend().authenticate(
|
||||||
|
request, kfet_password=get_kfet_password(request)
|
||||||
|
)
|
||||||
|
|
||||||
|
if temp_request_user:
|
||||||
|
request.real_user = request.user
|
||||||
|
request.user = temp_request_user
|
||||||
|
|
||||||
|
return view_func(request, *args, **kwargs)
|
||||||
|
|
||||||
|
return _wrapped_view
|
Loading…
Add table
Reference in a new issue