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
