summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
authorDenis Costa <deniscostadsc@gmail.com>2016-10-24 17:42:38 -0200
committerDenis Costa <deniscostadsc@gmail.com>2016-10-26 14:34:31 -0200
commitd9c4fb3707d85aa400f7042df2fbf7088f18739e (patch)
tree6b08cd048a885d6e4dc0d03e86bce87a815765d6 /service/pixelated
parent7e805dff08d4cbe14abab567edb7a301bdde6dda (diff)
Fixes tests.
I also split Athenticaton class into two. So I keep the same API for old code and have different things in two different classes. #795
Diffstat (limited to 'service/pixelated')
-rw-r--r--service/pixelated/authentication.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/service/pixelated/authentication.py b/service/pixelated/authentication.py
index 4b268435..c9961476 100644
--- a/service/pixelated/authentication.py
+++ b/service/pixelated/authentication.py
@@ -1,32 +1,34 @@
import re
-from email.utils import parseaddr
+
class Authentication(object):
+ def __init__(self, username, token, uuid, session_id, user_attributes):
+ self.username = username
+ self.token = token
+ self.uuid = uuid
+ self.session_id = session_id
+ self._user_attributes = user_attributes
+
+ def is_admin(self):
+ return self._user_attributes.get('is_admin', False)
+
+class Authenticator(object):
def __init__(self, domain):
self.domain = domain
- # self.token = token
- # self.uuid = uuid
- # self.session_id = session_id
- # self._user_attributes = user_attributes
def authenticate(self, username, password):
self.username = self.validate_username(username)
self.srp_auth(username, password)
def validate_username(self, username):
- if '@' not in username: return True
- extracted_username = self.extract_username(username)
- if self.username_with_domain(extracted_username) == username:
+ if '@' not in username:
return True
- else:
- return False
+ extracted_username = self.extract_username(username)
+ return self.username_with_domain(extracted_username) == username
def extract_username(self, username):
return re.search('^([^@]+)@?.*$', username).group(1)
def username_with_domain(self, username):
return '%s@%s' % (username, self.domain)
-
- def is_admin(self):
- return self._user_attributes.get('is_admin', False)