mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 07:23:46 +00:00
Make the Adherent class the auth class
This commit is contained in:
parent
ef2ddf11de
commit
9381fef889
2 changed files with 35 additions and 21 deletions
|
@ -52,7 +52,7 @@ PASSWORD_HASHERS = (
|
||||||
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
|
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
|
||||||
)
|
)
|
||||||
|
|
||||||
AUTH_USER_MODEL = 'users.User'
|
AUTH_USER_MODEL = 'users.Adherent'
|
||||||
LOGIN_URL = '/login/'
|
LOGIN_URL = '/login/'
|
||||||
LOGIN_REDIRECT_URL = '/'
|
LOGIN_REDIRECT_URL = '/'
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,7 @@ class UserManager(BaseUserManager):
|
||||||
def _create_user(
|
def _create_user(
|
||||||
self,
|
self,
|
||||||
pseudo,
|
pseudo,
|
||||||
|
name,
|
||||||
surname,
|
surname,
|
||||||
email,
|
email,
|
||||||
password=None,
|
password=None,
|
||||||
|
@ -152,6 +153,7 @@ class UserManager(BaseUserManager):
|
||||||
raise ValueError('Username shall only contain [a-z0-9-]')
|
raise ValueError('Username shall only contain [a-z0-9-]')
|
||||||
|
|
||||||
user = self.model(
|
user = self.model(
|
||||||
|
name=name,
|
||||||
pseudo=pseudo,
|
pseudo=pseudo,
|
||||||
surname=surname,
|
surname=surname,
|
||||||
email=self.normalize_email(email),
|
email=self.normalize_email(email),
|
||||||
|
@ -163,19 +165,19 @@ class UserManager(BaseUserManager):
|
||||||
user.make_admin()
|
user.make_admin()
|
||||||
return user
|
return user
|
||||||
|
|
||||||
def create_user(self, pseudo, surname, email, password=None):
|
def create_user(self, pseudo, name, surname, email, password=None):
|
||||||
"""
|
"""
|
||||||
Creates and saves a User with the given pseudo, name, surname, email,
|
Creates and saves a User with the given pseudo, name, surname, email,
|
||||||
and password.
|
and password.
|
||||||
"""
|
"""
|
||||||
return self._create_user(pseudo, surname, email, password, False)
|
return self._create_user(pseudo, name, surname, email, password, False)
|
||||||
|
|
||||||
def create_superuser(self, pseudo, surname, email, password):
|
def create_superuser(self, pseudo, name, surname, email, password):
|
||||||
"""
|
"""
|
||||||
Creates and saves a superuser with the given pseudo, name, surname,
|
Creates and saves a superuser with the given pseudo, name, surname,
|
||||||
email, and password.
|
email, and password.
|
||||||
"""
|
"""
|
||||||
return self._create_user(pseudo, surname, email, password, True)
|
return self._create_user(pseudo, name, surname, email, password, True)
|
||||||
|
|
||||||
|
|
||||||
class User(AbstractBaseUser):
|
class User(AbstractBaseUser):
|
||||||
|
@ -630,6 +632,7 @@ class User(AbstractBaseUser):
|
||||||
'welcome_mail_en': mailmessageoptions.welcome_mail_en,
|
'welcome_mail_en': mailmessageoptions.welcome_mail_en,
|
||||||
'pseudo': self.pseudo,
|
'pseudo': self.pseudo,
|
||||||
})
|
})
|
||||||
|
try :
|
||||||
send_mail(
|
send_mail(
|
||||||
'Bienvenue au %(name)s / Welcome to %(name)s' % {
|
'Bienvenue au %(name)s / Welcome to %(name)s' % {
|
||||||
'name': assooptions.name
|
'name': assooptions.name
|
||||||
|
@ -639,6 +642,8 @@ class User(AbstractBaseUser):
|
||||||
[self.email],
|
[self.email],
|
||||||
html_message=template.render(context)
|
html_message=template.render(context)
|
||||||
)
|
)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return
|
return
|
||||||
|
|
||||||
def reset_passwd_mail(self, request):
|
def reset_passwd_mail(self, request):
|
||||||
|
@ -718,6 +723,7 @@ class User(AbstractBaseUser):
|
||||||
'asso_email': assooptions.contact,
|
'asso_email': assooptions.contact,
|
||||||
'pseudo': self.pseudo,
|
'pseudo': self.pseudo,
|
||||||
})
|
})
|
||||||
|
try:
|
||||||
send_mail(
|
send_mail(
|
||||||
"Ajout automatique d'une machine / New machine autoregistered",
|
"Ajout automatique d'une machine / New machine autoregistered",
|
||||||
'',
|
'',
|
||||||
|
@ -725,6 +731,8 @@ class User(AbstractBaseUser):
|
||||||
[self.email],
|
[self.email],
|
||||||
html_message=template.render(context)
|
html_message=template.render(context)
|
||||||
)
|
)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
return
|
return
|
||||||
|
|
||||||
def set_user_password(self, password):
|
def set_user_password(self, password):
|
||||||
|
@ -761,6 +769,12 @@ class User(AbstractBaseUser):
|
||||||
|
|
||||||
class Adherent(User):
|
class Adherent(User):
|
||||||
PRETTY_NAME = "Adhérents"
|
PRETTY_NAME = "Adhérents"
|
||||||
|
|
||||||
|
USERNAME_FIELD = 'pseudo'
|
||||||
|
REQUIRED_FIELDS = ['name', 'surname', 'email']
|
||||||
|
|
||||||
|
objects = UserManager()
|
||||||
|
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
room = models.OneToOneField(
|
room = models.OneToOneField(
|
||||||
'topologie.Room',
|
'topologie.Room',
|
||||||
|
|
Loading…
Reference in a new issue