Reworking account handling
* allowing role management * allowing user change without the need to update the password
This commit is contained in:
parent
69941166a1
commit
1e720228be
@ -13,12 +13,19 @@ class PersonForm(forms.ModelForm):
|
|||||||
|
|
||||||
|
|
||||||
class AccountForm(forms.ModelForm):
|
class AccountForm(forms.ModelForm):
|
||||||
password=forms.CharField(widget=forms.PasswordInput())
|
password=forms.CharField(widget=forms.PasswordInput(), required=False)
|
||||||
confirm_password=forms.CharField(widget=forms.PasswordInput())
|
confirm_password=forms.CharField(widget=forms.PasswordInput(), required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UserAccount
|
model = UserAccount
|
||||||
fields = ['username', 'password']
|
fields = ['username', 'password', 'role']
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
if self.instance.pk is None:
|
||||||
|
self.fields['password'].required=True
|
||||||
|
self.fields['confirm_password'].required=True
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
cleaned_data = super(AccountForm, self).clean()
|
cleaned_data = super(AccountForm, self).clean()
|
||||||
@ -27,4 +34,14 @@ class AccountForm(forms.ModelForm):
|
|||||||
|
|
||||||
if passwordStr != confirm_passwordStr:
|
if passwordStr != confirm_passwordStr:
|
||||||
raise forms.ValidateError("password and confirm_password does not match")
|
raise forms.ValidateError("password and confirm_password does not match")
|
||||||
|
|
||||||
|
def save(self, commit=True):
|
||||||
|
user = super().save(commit=False)
|
||||||
|
pw = self.cleaned_data.get("password")
|
||||||
|
if pw:
|
||||||
|
user.set_password(pw)
|
||||||
|
if commit:
|
||||||
|
user.save()
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
18
member/migrations/0003_alter_useraccount_role.py
Normal file
18
member/migrations/0003_alter_useraccount_role.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.2.1 on 2025-07-18 15:12
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('member', '0002_alter_useraccount_options_alter_useraccount_managers_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='useraccount',
|
||||||
|
name='role',
|
||||||
|
field=models.CharField(choices=[('mitglied', 'Mitglied'), ('geraetewart', 'Gerätewart'), ('kommandant', 'Kommandant'), ('admin', 'Administrator'), ('superadmin', 'Superadministrator')], default='mitglied', max_length=50),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -11,7 +11,9 @@ class UserAccount(AbstractUser):
|
|||||||
('geraetewart', 'Gerätewart'),
|
('geraetewart', 'Gerätewart'),
|
||||||
('kommandant', 'Kommandant'),
|
('kommandant', 'Kommandant'),
|
||||||
('admin', 'Administrator'),
|
('admin', 'Administrator'),
|
||||||
])
|
('superadmin', 'Superadministrator'),
|
||||||
|
], default='mitglied')
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.benutzername} ({self.rolle})"
|
return f"{self.benutzername} ({self.rolle})"
|
||||||
|
|||||||
@ -16,6 +16,10 @@
|
|||||||
<label for="{{form.password.id_for_label}}">Password (confirmation)</label>
|
<label for="{{form.password.id_for_label}}">Password (confirmation)</label>
|
||||||
{{form.confirm_password}}
|
{{form.confirm_password}}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="{{form.role.id_for_label}}">Rolle</label>
|
||||||
|
{{form.role}}
|
||||||
|
</div>
|
||||||
<button class="button" type="submit">Speichern</button>
|
<button class="button" type="submit">Speichern</button>
|
||||||
<a href="{% url 'details' id %}" class="button" style="background:#444;">Abbrechen</a>
|
<a href="{% url 'details' id %}" class="button" style="background:#444;">Abbrechen</a>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user