Remove Flask dependencies

This commit is contained in:
Ruud committed 2013-06-12 23:37:08 +02:00
1 parent 1694ed7758
commit 6e0857c6c1
157 files changed
+757 -37916

No files matched your search

+41 -16
View File
@@ -1,26 +1,51 @@
from couchpotato.core.helpers.variable import md5
from couchpotato.environment import Env
from flask import request, Response
from functools import wraps
import base64
def check_auth(username, password):
return username == Env.setting('username') and password == Env.setting('password')
def authenticate():
return Response(
'This is not the page you are looking for. *waves hand*', 401,
{'WWW-Authenticate': 'Basic realm="CouchPotato Login"'}
)
def requires_auth(handler_class):
def requires_auth(f):
def wrap_execute(handler_execute):
@wraps(f)
def decorated(*args, **kwargs):
auth = getattr(request, 'authorization')
if Env.setting('username') and Env.setting('password'):
if (not auth or not check_auth(auth.username.decode('latin1'), md5(auth.password.decode('latin1').encode(Env.get('encoding'))))):
return authenticate()
def require_basic_auth(handler, kwargs):
if Env.setting('username') and Env.setting('password'):
return f(*args, **kwargs)
auth_header = handler.request.headers.get('Authorization')
auth_decoded = base64.decodestring(auth_header[6:]) if auth_header else None
if auth_decoded:
username, password = auth_decoded.split(':', 2)
return decorated
if auth_header is None or not auth_header.startswith('Basic ') or (not check_auth(username.decode('latin'), md5(password.decode('latin')))):
handler.set_status(401)
handler.set_header('WWW-Authenticate', 'Basic realm="CouchPotato Login"')
handler._transforms = []
handler.finish()
return False
return True
def _execute(self, transforms, *args, **kwargs):
if not require_basic_auth(self, kwargs):
return False
return handler_execute(self, transforms, *args, **kwargs)
return _execute
handler_class._execute = wrap_execute(handler_class._execute)
return handler_class
# @wraps(f)
# def decorated(*args, **kwargs):
# auth = getattr(request, 'authorization')
# if Env.setting('username') and Env.setting('password'):
# if (not auth or not check_auth(auth.username.decode('latin1'), md5(auth.password.decode('latin1').encode(Env.get('encoding'))))):
# return authenticate()
#
# return f(*args, **kwargs)
#
# return decorated