forked from HackAssistant/registration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
112 lines (92 loc) · 3.13 KB
/
models.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from __future__ import unicode_literals
from django.contrib.auth.base_user import BaseUserManager, AbstractBaseUser
from django.db import models
from django.utils import timezone
class UserManager(BaseUserManager):
def create_user(self, email, name, password=None):
if not email:
raise ValueError('Users must have a email')
user = self.model(
email=email,
name=name
)
user.set_password(password)
user.save(using=self._db)
return user
def create_mlhuser(self, email, name, mlh_id):
if not email:
raise ValueError('Users must have a email')
if not mlh_id:
raise ValueError('Users must have a mlh id')
user = self.model(
email=email,
name=name,
mlh_id=mlh_id
)
user.set_unusable_password()
user.save(using=self._db)
return user
def create_superuser(self, email, name, password):
user = self.create_user(
email,
name=name,
password=password,
)
user.is_director = True
user.is_organizer = True
user.is_admin = True
user.email_verified = True
user.is_volunteer = True
user.is_hardware_admin = True
user.save(using=self._db)
return user
class User(AbstractBaseUser):
email = models.EmailField(
verbose_name='email',
max_length=255,
unique=True,
)
name = models.CharField(
verbose_name='Full name',
max_length=255,
)
email_verified = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
is_volunteer = models.BooleanField(default=False)
is_organizer = models.BooleanField(default=False)
is_director = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)
can_review_dubious = models.BooleanField(default=False)
is_hardware_admin = models.BooleanField(default=False)
created_time = models.DateTimeField(default=timezone.now)
mlh_id = models.IntegerField(blank=True, null=True, unique=True)
objects = UserManager()
USERNAME_FIELD = 'email'
EMAIL_FIELD = 'email'
REQUIRED_FIELDS = ['name', ]
def get_full_name(self):
# The user is identified by their nickname/full_name address
return self.name
def get_short_name(self):
# The user is identified by their email address
return self.email
def __str__(self):
return self.email
def has_perm(self, perm, obj=None):
"Does the user have a specific permission?"
# Simplest possible answer: Yes, always
return True
def has_module_perms(self, app_label):
"Does the user have permissions to view the app `app_label`?"
# Simplest possible answer: Yes, always
return True
@property
def is_superuser(self):
return self.is_admin
@property
def is_staff(self):
"Is the user a member of staff?"
return self.is_admin
@property
def has_dubious_acces(self):
return self.can_review_dubious or self.is_director