blob: 41fb8bcb3b7fdf34de1e145ffce1d92e39a61553 [file] [log] [blame]
Akronca9bd982016-12-06 16:59:57 +01001from flask_login import UserMixin
2import jwt
3
4
5__author__ = 'hanl'
6
7
8def decrypt_openid(secret, token=None):
9 values = {}
10 if token:
11 values = jwt.decode(jwt=token, key=secret)
12 print "decoded values %s" % str(values)
13 return values
14
15
16def encrypt_string(secret, *args):
17 jwt_string = jwt.encode(args, key=secret)
18 print "encoded string %s" % str(jwt_string)
19 return jwt_string
20
21
22
23class User(UserMixin):
24 '''
25 the user object
26 '''
27
28 def __init__(self, username, password=None, email=None, firstName=None, lastName=None, address=None,
29 institution=None,
30 phone=None, country=None):
31 if not username:
32 raise ValueError("the username must be set")
33 self.username = username
34 self.password = password
35 self.email = email
36 self.firstName = firstName
37 self.lastName = lastName
38 self.address = address
39 self.institution = institution
40 self.phone = phone
41 self.country = country
42
43 def has_details(self):
44 if self.firstName and self.lastName and self.email:
45 return True
46 return False
47
48 def is_admin(self):
49 '''
50 to be used for admin purposes
51 '''
52 return False
53
54 def get_id(self):
55 '''
56 :return: id reference to retrieve user object from middleware
57 '''
58 return unicode(self.username)
59
60 def get_full_name(self):
61 if self.firstName and self.lastName:
62 return u' '.join([self.firstName, self.lastName])
63 return None