# Path: oauth_provider/compat.py
# AUTH_USER_MODEL = settings.AUTH_USER_MODEL
# class UnsafeRedirect(HttpResponse):
#     def __init__(self, target_url, *args, **kwargs):
# 
# Path: oauth_provider/utils.py
# def check_valid_callback(callback):
#     """
#     Checks the size and nature of the callback.
#     """
#     callback_url = urlparse(callback)
#     return (callback_url.scheme and
#             callback_url.hostname not in OAUTH_BLACKLISTED_HOSTNAMES and
#             len(callback) < MAX_URL_LENGTH)


import uuid
import urllib.request, urllib.parse, urllib.error
import urllib.parse
import oauth2 as oauth
from datetime import datetime
from time import time
from Crypto.PublicKey import RSA
from django.db import models
from oauth_provider.compat import AUTH_USER_MODEL, get_random_string
from oauth_provider.managers import TokenManager
from oauth_provider.consts import KEY_SIZE, RSA_SECRET_SIZE, CONSUMER_KEY_SIZE, CONSUMER_STATES,\
    PENDING, VERIFIER_SIZE, MAX_URL_LENGTH, OUT_OF_BAND, REGULAR_SECRET_SIZE
from oauth_provider.utils import check_valid_callback
#     name = models.CharField(max_length=255)
#     url = models.TextField(max_length=MAX_URL_LENGTH)
#     is_readonly = models.BooleanField(default=True)

#     def __unicode__(self):
#         return u"Resource %s with url %s" % (self.name, self.url)

# LRS CHANGE - NOT NEEDED
# class Resource(Scope):

#     def __init__(self, *args, **kwargs):
#         warnings.warn("oauth_provider.Resource model is deprecated, use oauth_provider.Scope instead", DeprecationWarning)
#         super(Resource, self).__init__(*args, **kwargs)

#     class Meta:
#         proxy = True


class Consumer(models.Model):
    name = models.CharField(max_length=255)
    description = models.TextField(blank=True)

    # LRS CHANGE - ADDED DEFAULT SCOPES FOR CONSUMER WHEN FIRST REGISTERED
    # default_scopes = models.CharField(max_length=100, default="statements/write statements/read/mine")

    key = models.CharField(max_length=CONSUMER_KEY_SIZE)
    secret = models.CharField(max_length=RSA_SECRET_SIZE, blank=True)
    rsa_signature = models.BooleanField(default=False)

    status = models.SmallIntegerField(choices=CONSUMER_STATES, default=PENDING)

# Path: oauth_provider/compat.py
# AUTH_USER_MODEL = settings.AUTH_USER_MODEL
# class UnsafeRedirect(HttpResponse):
#     def __init__(self, target_url, *args, **kwargs):
# 
# Path: oauth_provider/utils.py
# def check_valid_callback(callback):
#     """
#     Checks the size and nature of the callback.
#     """
#     callback_url = urlparse(callback)
#     return (callback_url.scheme and
#             callback_url.hostname not in OAUTH_BLACKLISTED_HOSTNAMES and
#             len(callback) < MAX_URL_LENGTH)


# Path: oauth_provider/models.py
import uuid
import urllib.request, urllib.parse, urllib.error
import urllib.parse
import oauth2 as oauth
from datetime import datetime
from time import time
from Crypto.PublicKey import RSA
from django.db import models
from oauth_provider.compat import AUTH_USER_MODEL, get_random_string
from oauth_provider.managers import TokenManager
from oauth_provider.consts import KEY_SIZE, RSA_SECRET_SIZE, CONSUMER_KEY_SIZE, CONSUMER_STATES,\
    PENDING, VERIFIER_SIZE, MAX_URL_LENGTH, OUT_OF_BAND, REGULAR_SECRET_SIZE
from oauth_provider.utils import check_valid_callback

#     name = models.CharField(max_length=255)
#     url = models.TextField(max_length=MAX_URL_LENGTH)
#     is_readonly = models.BooleanField(default=True)

#     def __unicode__(self):
#         return u"Resource %s with url %s" % (self.name, self.url)

# LRS CHANGE - NOT NEEDED
# class Resource(Scope):

#     def __init__(self, *args, **kwargs):
#         warnings.warn("oauth_provider.Resource model is deprecated, use oauth_provider.Scope instead", DeprecationWarning)
#         super(Resource, self).__init__(*args, **kwargs)

#     class Meta:
#         proxy = True


class Consumer(models.Model):
    name = models.CharField(max_length=255)
    description = models.TextField(blank=True)

    # LRS CHANGE - ADDED DEFAULT SCOPES FOR CONSUMER WHEN FIRST REGISTERED
    # default_scopes = models.CharField(max_length=100, default="statements/write statements/read/mine")

    key = models.CharField(max_length=CONSUMER_KEY_SIZE)
    secret = models.CharField(max_length=RSA_SECRET_SIZE, blank=True)
    rsa_signature = models.BooleanField(default=False)

    status = models.SmallIntegerField(choices=CONSUMER_STATES, default=PENDING)

    user = models.ForeignKey(AUTH_USER_MODEL, null=True, blank=True, on_delete=models.CASCADE)