Initial cleanup of the codebase
Change-Id: Idbc92ea3c2d7ee4d4807d1d83ceee9a299b9a9f7
diff --git a/service/providers/utils.py b/service/providers/utils.py
new file mode 100644
index 0000000..41fb8bc
--- /dev/null
+++ b/service/providers/utils.py
@@ -0,0 +1,63 @@
+from flask_login import UserMixin
+import jwt
+
+
+__author__ = 'hanl'
+
+
+def decrypt_openid(secret, token=None):
+ values = {}
+ if token:
+ values = jwt.decode(jwt=token, key=secret)
+ print "decoded values %s" % str(values)
+ return values
+
+
+def encrypt_string(secret, *args):
+ jwt_string = jwt.encode(args, key=secret)
+ print "encoded string %s" % str(jwt_string)
+ return jwt_string
+
+
+
+class User(UserMixin):
+ '''
+ the user object
+ '''
+
+ def __init__(self, username, password=None, email=None, firstName=None, lastName=None, address=None,
+ institution=None,
+ phone=None, country=None):
+ if not username:
+ raise ValueError("the username must be set")
+ self.username = username
+ self.password = password
+ self.email = email
+ self.firstName = firstName
+ self.lastName = lastName
+ self.address = address
+ self.institution = institution
+ self.phone = phone
+ self.country = country
+
+ def has_details(self):
+ if self.firstName and self.lastName and self.email:
+ return True
+ return False
+
+ def is_admin(self):
+ '''
+ to be used for admin purposes
+ '''
+ return False
+
+ def get_id(self):
+ '''
+ :return: id reference to retrieve user object from middleware
+ '''
+ return unicode(self.username)
+
+ def get_full_name(self):
+ if self.firstName and self.lastName:
+ return u' '.join([self.firstName, self.lastName])
+ return None