8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 03:13:12 +00:00

Make the Adherent class the auth class

This commit is contained in:
Maël Kervella 2017-11-18 19:26:01 +00:00
parent ef2ddf11de
commit 9381fef889
2 changed files with 35 additions and 21 deletions

View file

@ -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 = '/'

View file

@ -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,15 +632,18 @@ class User(AbstractBaseUser):
'welcome_mail_en': mailmessageoptions.welcome_mail_en, 'welcome_mail_en': mailmessageoptions.welcome_mail_en,
'pseudo': self.pseudo, 'pseudo': self.pseudo,
}) })
send_mail( try :
'Bienvenue au %(name)s / Welcome to %(name)s' % { send_mail(
'name': assooptions.name 'Bienvenue au %(name)s / Welcome to %(name)s' % {
}, 'name': assooptions.name
'', },
general_options.email_from, '',
[self.email], general_options.email_from,
html_message=template.render(context) [self.email],
) html_message=template.render(context)
)
except:
pass
return return
def reset_passwd_mail(self, request): def reset_passwd_mail(self, request):
@ -718,13 +723,16 @@ class User(AbstractBaseUser):
'asso_email': assooptions.contact, 'asso_email': assooptions.contact,
'pseudo': self.pseudo, 'pseudo': self.pseudo,
}) })
send_mail( try:
"Ajout automatique d'une machine / New machine autoregistered", send_mail(
'', "Ajout automatique d'une machine / New machine autoregistered",
general_options.email_from, '',
[self.email], general_options.email_from,
html_message=template.render(context) [self.email],
) 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',