Exemple #1
0
    def ready(self) -> None:
        super().ready()

        update_dynamic_preferences()

        password_changed.connect(ldap_change_password)
        password_reset.connect(ldap_change_password)
        password_set.connect(ldap_change_password)

        user_signed_up.connect(ldap_create_user)

        from django_auth_ldap.backend import populate_user  # noqa

        populate_user.connect(ldap_sync_user_on_login)
Exemple #2
0
    """
    if not settings.CAS_CHECK_ADMIN_ATTRIBUTES:
        return

    username = kwargs.get("user")
    attributes = kwargs.get("attributes")

    if not attributes:
        return

    User = get_user_model()
    is_administrator = _cas_user_is_administrator(attributes)

    with transaction.atomic():
        user = User.objects.select_for_update().get(username=username)
        if user.is_superuser != is_administrator:
            user.is_superuser = is_administrator
            user.save()


def ldap_populate_user(sender, user, ldap_user, **kwargs):
    if user.pk is None:
        user.save()
        generate_api_key(user)


# This code is imported from MCPClient, which has no
# LDAP_AUTHENTICATION setting :(
if getattr(settings, "LDAP_AUTHENTICATION", False):
    populate_user.connect(ldap_populate_user)
Exemple #3
0
def register_signal_handlers():
    populate_user.connect(populate_user_signal_handler)
Exemple #4
0
                )

                if dorm.code in Dorm.all_objects.filter(official_dorm=False).values_list('code', flat=True)\
                  and dorm.code != "ABR":
                    # If they're off-campus, make sure they're 'symbollically'
                    # a part of the Offcampus dorm.
                    symoff, _ = DormRoom.objects.get_or_create(
                        dorm__code="OFF",
                        number="Symbolic Room",
                    )

                    # Symroom is going to be full of people.
                    symroomur, _ = UserRoom.objects.get_or_create(
                        user=new_user,
                        room=symoff,
                    )
                    symroomur.semesters.add(this_sem)

                ur, _ = UserRoom.objects.get_or_create(
                    user=new_user,
                    room=room,
                )
                ur.semesters.add(this_sem)

            return
    except Exception, e:
        # Don't interrupt core service, no matter what.
        logger.error("caught unhandled exception {}: {}".format(e, e.message))
        return
populate_user.connect(create_user_related_things)
Exemple #5
0
from django.db import models
from django_auth_ldap.backend import populate_user
from django.contrib.auth.models import User


def make_inactive(sender, user, **kwargs):
    if not User.objects.filter(username=user.username):
        user.is_active = False


populate_user.connect(make_inactive)
Exemple #6
0
logger = logging.getLogger(__name__)

#en django 1.7 no funciona AUTH_PROFILE_MODULE actualizamos datos mediante este signal
def update_user(sender, user=None, ldap_user=None, **kwargs):

    # Remember that every attribute maps to a list of values
    dni = ldap_user.attrs.get("employeeNumber", [])
    uid = ldap_user.attrs.get("uid", [])
    if dni:
        user.dni = dni[0]
    if uid:
        user.usuario_rayuela = uid[0]
    user.save()

populate_user.connect(update_user)


def upload_to(instance, filename):
    return '/'.join(['users', instance.username, filename])


@python_2_unicode_compatible
class User(AbstractUser):

    # First Name and Last Name do not cover name patterns
    # around the globe.
    name = models.CharField(_("Name of User"), help_text=_("Name of User"), blank=True, max_length=255)
    dni = models.CharField(_("Card ID Number"), help_text=_("Card ID Number"), blank=True, max_length=20, db_index=True)
    usuario_rayuela = models.CharField(_("Rayuela User"), help_text=_("Rayuela User"), blank=True, max_length=50)
    foto = ImageField(_("User photo"), help_text=_("User photo"), upload_to=upload_to, blank=True)