summaryrefslogtreecommitdiff
path: root/drupal_auth/managers.py
blob: 953c867637282dfc50b99599930463c5043def24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import hashlib

from django.db import models
from django.contrib.auth.models import (
    BaseUserManager, AbstractBaseUser
)

class DrupalUserManager(BaseUserManager):
    def create_user(self, password=None):
        user = self.model()
        if not email:
            raise ValueError('Users must have an email address')

        user.set_password(password)
        user.save(using=self._db)
        return user
    
    def create_superuser(self, username, password):
        user = self.model()
        user.id = 1
        user.username= username
        p = hashlib.md5()
        p.update(password)
        user.pass_field= p.hexdigest()
        user.is_admin = True
        user.save(using=self._db)
        return user