Пример #1
0
 def authenticate(self, request):
     consumer_key=None
     consumer_secret=None
     access_key=None
     access_secret=None
     try:
         consumer = get_consumer_model().objects.get_by_natural_key(consumer_key)
         
         if consumer.check_password(consumer_secret):
             if consumer.is_active:
                 user_access = get_access_key_model().objects.get_by_natural_key(access_key)
                 
                 if user_access.check_password(access_secret):
                     if user_access.is_active:
                         return user_access, None
             
     except get_consumer_model().DoesNotExist:
         return None
     except get_access_key_model().DoesNotExist:
         return None
Пример #2
0
    def authenticate(self, request):
        consumer_key = None
        consumer_secret = None
        access_key = None
        access_secret = None
        try:
            consumer = get_consumer_model().objects.get_by_natural_key(
                consumer_key)

            if consumer.check_password(consumer_secret):
                if consumer.is_active:
                    user_access = get_access_key_model(
                    ).objects.get_by_natural_key(access_key)

                    if user_access.check_password(access_secret):
                        if user_access.is_active:
                            return user_access, None

        except get_consumer_model().DoesNotExist:
            return None
        except get_access_key_model().DoesNotExist:
            return None
def get_credentials__same_system(user, consumer_identifier, client_settings=None):
    length_identifier = 32 #str(uuid) length
    length_secret = 20
    import random, string
    
    AccessKey = get_access_key_model()
    Consumer = get_consumer_model()
    
    consumer = Consumer.objects.get(identifier = consumer_identifier)
    key = AccessKey.objects.create(
            user=             user,
            #auto generated id=                 ''.join(random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for x in range(length_identifier)),
            secret=             ''.join(random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for x in range(length_secret)),
            consumer        = consumer
        )
    
    key.update_client_setings(client_settings)
    
    return key