Move work of extracting token from cookie to a @property.
This commit is contained in:
parent
6ce69da7a6
commit
f23ed27683
1 changed files with 15 additions and 6 deletions
|
@ -63,6 +63,19 @@ class RequestHandler(http.server.BaseHTTPRequestHandler):
|
||||||
self.password = password
|
self.password = password
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def auth_token(self):
|
||||||
|
cookie = self.headers.get('Cookie')
|
||||||
|
if not cookie:
|
||||||
|
return None
|
||||||
|
|
||||||
|
cookie = http.cookies.SimpleCookie(cookie)
|
||||||
|
token = cookie.get(TOKEN_COOKIE_NAME)
|
||||||
|
if not token:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return token
|
||||||
|
|
||||||
def check_password(self, attempt):
|
def check_password(self, attempt):
|
||||||
if self.password is None:
|
if self.password is None:
|
||||||
return True
|
return True
|
||||||
|
@ -79,12 +92,8 @@ class RequestHandler(http.server.BaseHTTPRequestHandler):
|
||||||
if self.headers.get('password', None) == self.password:
|
if self.headers.get('password', None) == self.password:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if self.headers.get('Cookie'):
|
if self.accepted_tokens is not None and self.auth_token in self.accepted_tokens:
|
||||||
cookie = http.cookies.SimpleCookie()
|
return True
|
||||||
cookie.load(self.headers.get('Cookie'))
|
|
||||||
token = cookie.get(TOKEN_COOKIE_NAME)
|
|
||||||
if token and token.value in self.accepted_tokens:
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue