diff --git a/openslides/participant/api.py b/openslides/participant/api.py index ed154ec45..d953e56b9 100644 --- a/openslides/participant/api.py +++ b/openslides/participant/api.py @@ -9,10 +9,20 @@ :copyright: 2011 by the OpenSlides team, see AUTHORS. :license: GNU GPL, see LICENSE for more details. """ +from random import choice +import string from django.contrib.auth.models import User +def gen_password(): + chars = string.letters + string.digits + newpassword = '' + for i in range(8): + newpassword += choice(chars) + return newpassword + + def gen_username(first_name, last_name): testname = "%s%s" % (first_name, last_name) try: diff --git a/openslides/participant/forms.py b/openslides/participant/forms.py index 9b8007d5d..faca757ab 100644 --- a/openslides/participant/forms.py +++ b/openslides/participant/forms.py @@ -12,24 +12,25 @@ from django.forms import Form, ModelForm, CharField, EmailField, FileField, FileInput, MultipleChoiceField from django.contrib.auth.models import User, Group +from django.contrib.auth.forms import AdminPasswordChangeForm from django.utils.translation import ugettext as _ from participant.models import Profile class UserForm(ModelForm): error_css_class = 'error' required_css_class = 'required' - + first_name = CharField(label=_("First name")) last_name = CharField(label=_("Last name")) - + class Meta: model = User - exclude = ('username', 'password', 'is_staff', 'last_login', 'date_joined', 'user_permissions') + exclude = ('password', 'is_staff', 'last_login', 'date_joined', 'user_permissions') class UsernameForm(ModelForm): error_css_class = 'error' required_css_class = 'required' - + class Meta: model = User exclude = ('first_name', 'last_name', 'email', 'is_active','is_superuser', 'groups', 'password', 'is_staff', 'last_login', 'date_joined', 'user_permissions') @@ -60,4 +61,4 @@ class UserImportForm(Form): error_css_class = 'error' required_css_class = 'required' - csvfile = FileField(widget=FileInput(attrs={'size':'50'}), label=_("CSV File")) \ No newline at end of file + csvfile = FileField(widget=FileInput(attrs={'size':'50'}), label=_("CSV File")) diff --git a/openslides/participant/models.py b/openslides/participant/models.py index 91371cd7c..b867ff06a 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -14,6 +14,8 @@ from django.db import models from django.contrib.auth.models import User from django.utils.translation import ugettext as _ +from participant.api import gen_password + class Profile(models.Model): GENDER_CHOICES = ( ('none', _('Not specified')), @@ -32,6 +34,11 @@ class Profile(models.Model): group = models.CharField(max_length=100, null=True, blank=True, verbose_name = _("Group")) type = models.CharField(max_length=100, choices=TYPE_CHOICE, default='delegate', verbose_name = _("Typ")) committee = models.CharField(max_length=100, null=True, blank=True, verbose_name = _("Committee")) + firstpassword = models.CharField(max_length=100, null=True, blank=True, verbose_name = _("First Password")) + + + def reset_password(self): + self.user.set_password(self.firstpassword) def __unicode__(self): if self.group: @@ -44,3 +51,10 @@ class Profile(models.Model): ('can_view_participants', "Can see the list of participants"), ('can_manage_participants', "Can manage the participant list"), ) + +def set_first_user_passwords(): + for user in Profile.objects.filter(firstpassword=''): + user.firstpassword = gen_password() + user.user.set_password(user.firstpassword) + user.user.save() + user.save() diff --git a/openslides/participant/templates/participant/base_participant.html b/openslides/participant/templates/participant/base_participant.html index 0ae6a5c4c..39b63bc06 100644 --- a/openslides/participant/templates/participant/base_participant.html +++ b/openslides/participant/templates/participant/base_participant.html @@ -14,6 +14,7 @@