4 changed files with 76 additions and 53 deletions
@ -1,45 +0,0 @@ |
|||||
from couchpotato.core.helpers.variable import md5 |
|
||||
from couchpotato.environment import Env |
|
||||
import base64 |
|
||||
|
|
||||
def check_auth(username, password): |
|
||||
return username == Env.setting('username') and password == Env.setting('password') |
|
||||
|
|
||||
def requires_auth(handler_class): |
|
||||
|
|
||||
def wrap_execute(handler_execute): |
|
||||
|
|
||||
def require_basic_auth(handler, kwargs): |
|
||||
|
|
||||
if Env.setting('username') and Env.setting('password'): |
|
||||
|
|
||||
auth_header = handler.request.headers.get('Authorization') |
|
||||
auth_decoded = base64.decodestring(auth_header[6:]) if auth_header else None |
|
||||
|
|
||||
username = '' |
|
||||
password = '' |
|
||||
|
|
||||
if auth_decoded: |
|
||||
username, password = auth_decoded.split(':', 2) |
|
||||
|
|
||||
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 |
|
@ -0,0 +1,18 @@ |
|||||
|
{% autoescape None %} |
||||
|
<!doctype html> |
||||
|
<html> |
||||
|
<head> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> |
||||
|
<meta name="apple-mobile-web-app-capable" content="yes"> |
||||
|
|
||||
|
<title>Login</title> |
||||
|
</head> |
||||
|
<body> |
||||
|
<form action="" method="post"> |
||||
|
<div><input name="username" type="text" placeholder="Username" /></div> |
||||
|
<div><input name="password" type="password" placeholder="Password" /></div> |
||||
|
<div><label title="for 30 days"><input name="remember_me" type="checkbox" value="1" checked="checked" /> Remember me</label></div> |
||||
|
<div><input name="submit" type="submit" value="Login" /></div> |
||||
|
</form> |
||||
|
</body> |
||||
|
</html> |
Loading…
Reference in new issue