# Path: userena/utils.py
# def generate_sha1(string, salt=None):
#     """
#     Generates a sha1 hash for supplied string. Doesn't need to be very secure
#     because it's not used for password checking. We got Django for that.
# 
#     :param string:
#         The string that needs to be encrypted.
# 
#     :param salt:
#         Optionally define your own salt. If none is supplied, will use a random
#         string of 5 characters.
# 
#     :return: Tuple containing the salt and hash.
# 
#     """
#     if not salt:
#         salt = sha_constructor(str(random.random())).hexdigest()[:5]
#     hash = sha_constructor(salt+str(string)).hexdigest()
# 
#     return (salt, hash)
# 
# def get_profile_model():
#     """
#     Return the model class for the currently-active user profile
#     model, as defined by the ``AUTH_PROFILE_MODULE`` setting.
# 
#     :return: The model that is used as profile.
# 
#     """
#     if (not hasattr(settings, 'AUTH_PROFILE_MODULE')) or \
#            (not settings.AUTH_PROFILE_MODULE):
#         raise SiteProfileNotAvailable
# 
#     profile_mod = get_model(*settings.AUTH_PROFILE_MODULE.split('.'))
#     if profile_mod is None:
#         raise SiteProfileNotAvailable
#     return profile_mod


from django.db import models
from django.db.models import Q
from django.contrib.auth.models import User, UserManager, Permission, AnonymousUser
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import ugettext as _
from django.utils import timezone
from userena import settings as userena_settings
from userena.utils import generate_sha1, get_profile_model
from userena import signals as userena_signals
from guardian.shortcuts import assign, get_perms
import re, datetime
        """
        Checks for expired users and delete's the ``User`` associated with
        it. Skips if the user ``is_staff``.

        :return: A list containing the deleted users.

        """
        deleted_users = []
        for user in User.objects.filter(is_staff=False,
                                        is_active=False):
            if user.userena_signup.activation_key_expired():
                deleted_users.append(user)
                user.delete()
        return deleted_users

    def check_permissions(self):
        """
        Checks that all permissions are set correctly for the users.

        :return: A set of users whose permissions was wrong.

        """
        # Variable to supply some feedback
        changed_permissions = []
        changed_users = []
        warnings = []

        # Check that all the permissions are available.
        for model, perms in ASSIGNED_PERMISSIONS.items():
            if model == 'profile':

# Path: userena/utils.py
# def generate_sha1(string, salt=None):
#     """
#     Generates a sha1 hash for supplied string. Doesn't need to be very secure
#     because it's not used for password checking. We got Django for that.
# 
#     :param string:
#         The string that needs to be encrypted.
# 
#     :param salt:
#         Optionally define your own salt. If none is supplied, will use a random
#         string of 5 characters.
# 
#     :return: Tuple containing the salt and hash.
# 
#     """
#     if not salt:
#         salt = sha_constructor(str(random.random())).hexdigest()[:5]
#     hash = sha_constructor(salt+str(string)).hexdigest()
# 
#     return (salt, hash)
# 
# def get_profile_model():
#     """
#     Return the model class for the currently-active user profile
#     model, as defined by the ``AUTH_PROFILE_MODULE`` setting.
# 
#     :return: The model that is used as profile.
# 
#     """
#     if (not hasattr(settings, 'AUTH_PROFILE_MODULE')) or \
#            (not settings.AUTH_PROFILE_MODULE):
#         raise SiteProfileNotAvailable
# 
#     profile_mod = get_model(*settings.AUTH_PROFILE_MODULE.split('.'))
#     if profile_mod is None:
#         raise SiteProfileNotAvailable
#     return profile_mod


# Path: userena/managers.py
from django.db import models
from django.db.models import Q
from django.contrib.auth.models import User, UserManager, Permission, AnonymousUser
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import ugettext as _
from django.utils import timezone
from userena import settings as userena_settings
from userena.utils import generate_sha1, get_profile_model
from userena import signals as userena_signals
from guardian.shortcuts import assign, get_perms
import re, datetime

        """
        Checks for expired users and delete's the ``User`` associated with
        it. Skips if the user ``is_staff``.

        :return: A list containing the deleted users.

        """
        deleted_users = []
        for user in User.objects.filter(is_staff=False,
                                        is_active=False):
            if user.userena_signup.activation_key_expired():
                deleted_users.append(user)
                user.delete()
        return deleted_users

    def check_permissions(self):
        """
        Checks that all permissions are set correctly for the users.

        :return: A set of users whose permissions was wrong.

        """
        # Variable to supply some feedback
        changed_permissions = []
        changed_users = []
        warnings = []

        # Check that all the permissions are available.
        for model, perms in ASSIGNED_PERMISSIONS.items():
            if model == 'profile':

                model_obj = get_profile_model()