Authentication
Global settings
This commit is contained in:
1 parent
38a9ae2592
commit
21f880e030
4 files changed
+41
-10
No files matched your search
@@ -0,0 +1,24 @@
|
||||
from couchpotato.core.settings import settings
|
||||
from flask import request, Response
|
||||
from functools import wraps
|
||||
|
||||
def check_auth(username, password):
|
||||
return username == settings.get('username') and password == settings.get('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(f):
|
||||
|
||||
@wraps(f)
|
||||
def decorated(*args, **kwargs):
|
||||
auth = request.authorization
|
||||
if settings.get('username') and (not auth or not check_auth(auth.username, auth.password)):
|
||||
return authenticate()
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return decorated
|
||||
@@ -14,16 +14,18 @@ class Settings():
|
||||
|
||||
bool = {'true':True, 'false':False}
|
||||
|
||||
def __init__(self, file):
|
||||
self.file = file
|
||||
|
||||
self.p = ConfigParser.RawConfigParser()
|
||||
self.p.read(file)
|
||||
def __init__(self):
|
||||
|
||||
# Connect signals
|
||||
signal('settings.register').connect(self.registerDefaults)
|
||||
signal('settings.save').connect(self.save)
|
||||
|
||||
def setFile(self, file):
|
||||
self.file = file
|
||||
|
||||
self.p = ConfigParser.RawConfigParser()
|
||||
self.p.read(file)
|
||||
|
||||
def parser(self):
|
||||
return self.p
|
||||
|
||||
@@ -81,3 +83,5 @@ class Settings():
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
settings = Settings()
|
||||
Reference in new issue
Block a user