Пример #1
0
    def register_new_user(cls, user_data, is_active=False):
        """Creates an user instance."""
        plain_password = user_data.pop('password')

        if 'username' not in user_data and 'email' in user_data:
            user_data['username'] = user_data['email']

        user = User(**user_data)
        user.is_active = is_active
        user.set_password(plain_password)
        user.save()

        return user
Пример #2
0
    def handle(self, **options):
        from apps.accounts.models import User
        from faker import Faker

        print("Create superuser")
        data = {
            'email': '*****@*****.**',
            'first_name': 'Truong',
            'last_name': 'Tran'
        }
        superuser = User(**data)
        superuser.set_password('truong77')
        superuser.is_active = True
        superuser.is_superuser = True
        superuser.save()
Пример #3
0
def sync_user_relations(user: User, attrs: dict):
    dn = attrs.get('distinguishedName')[0]

    user.is_active = True
    user.save(update_fields=['is_active'])

    dn_parts = dn.lower().split(',')
    if 'ou=zaci' in dn_parts:
        class_ = dn.split(',')[1].split('=')[1].replace(' ', '')
        user.school_class = class_

        user.groups.add(_group_cache['student'])
        user.save(update_fields=['school_class'])

    elif 'ou=ucitele' in dn_parts:
        user.groups.add(_group_cache['teacher'])

    elif 'ou=zaci-zakazani' in dn_parts:
        pass  # RIP

    else:
        logger.info("Not group assigned for user: %s.", dn_parts)