Пример #1
0
    def register_with_token(self, device_id, auth_token, token_type, facebook_id):
        consumer = self.__checkIfCurrentUser__(device_id)
        
        if consumer is None: 
            logger.debug("Registering customer with device " + str(device_id))
            consumer = Consumer(device_id=device_id)
                     
        if token_type.lower() == 'google':
            logger.debug("Registering customer with google auth token")
            r = requests.get('https://www.googleapis.com/oauth2/v1/userinfo?access_token=' + auth_token)
            
            if r.status_code == 200 :
                json = r.json()
                consumer.name = json.get('name', '')
                consumer.email_address = json.get('email', '')
                consumer.google_id = json.get('id', '')                   
            else :
                raise InvalidAuthTokenError(auth_token)
        elif token_type.lower() == 'facebook':
            logger.debug("Registering customer with facebook auth token")
            r = requests.get('https://graph.facebook.com/' + facebook_id + '?access_token=' + auth_token)
            
            if r.status_code == 200 :
                json = r.json()
                consumer.name = json.get('name', '')
                consumer.email_address = json.get('email', '')
                consumer.facebook_id = json.get('id', '')                   
            else :
                raise InvalidAuthTokenError(auth_token)
        else:
            raise InvalidAuthTokenTypeError(token_type)

        api_token = hashlib.md5(device_id).hexdigest()

        salt = str(random.randint(10,99))
        hashed_password = hashlib.md5(salt + str(random.randint(10,1000))).hexdigest()
        
        consumer.api_token = api_token
        consumer.salt = salt
        consumer.password = hashed_password
        
        consumer.save()
        return consumer
Пример #2
0
    def register(self, device_id, password, email_address, name):
        consumer = self.__checkIfCurrentUser__(device_id)
        
        if consumer is None: 
            logger.debug("Registering customer with device " + str(device_id))
            consumer = Consumer(device_id=device_id)
        
        api_token = hashlib.md5(device_id).hexdigest()

        salt = str(random.randint(10,99))
        hashed_password = hashlib.md5(salt + password).hexdigest()
        
        consumer.name = name
        consumer.api_token = api_token
        consumer.email_address = email_address
        consumer.salt = salt
        consumer.password = hashed_password
        
        consumer.save()
        return consumer