diff --git a/orchestra/contrib/musician/forms.py b/orchestra/contrib/musician/forms.py index 67dec100..791f3699 100644 --- a/orchestra/contrib/musician/forms.py +++ b/orchestra/contrib/musician/forms.py @@ -3,8 +3,11 @@ from django.contrib.auth.forms import AuthenticationForm from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ +from django.contrib.auth.hashers import make_password + from orchestra.contrib.domains.models import Domain, Record from orchestra.contrib.mailboxes.models import Address, Mailbox +from orchestra.contrib.systemusers.models import WebappUsers, SystemUser from orchestra.contrib.musician.validators import ValidateZoneMixin from . import api @@ -27,6 +30,42 @@ class LoginForm(AuthenticationForm): return self.cleaned_data +class ChangePasswordForm(forms.ModelForm): + error_messages = { + 'password_mismatch': _('The two password fields didn’t match.'), + } + password = forms.CharField( + label=_("Password"), + strip=False, + widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}), + ) + password2 = forms.CharField( + label=_("Password confirmation"), + widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}), + strip=False, + help_text=_("Enter the same password as before, for verification."), + ) + + class Meta: + fields = ("password",) + model = WebappUsers + + def clean_password2(self): + password = self.cleaned_data.get("password") + password2 = self.cleaned_data.get("password2") + if password and password2 and password != password2: + raise ValidationError( + self.error_messages['password_mismatch'], + code='password_mismatch', + ) + return password2 + + def clean(self): + cleaned_data = super().clean() + password = cleaned_data.get("password") + cleaned_data['password'] = make_password(password) + return cleaned_data + class MailForm(forms.ModelForm): class Meta: @@ -53,37 +92,13 @@ class MailForm(forms.ModelForm): return instance -class MailboxChangePasswordForm(forms.ModelForm): - error_messages = { - 'password_mismatch': _('The two password fields didn’t match.'), - } - password = forms.CharField( - label=_("Password"), - strip=False, - widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}), - ) - password2 = forms.CharField( - label=_("Password confirmation"), - widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}), - strip=False, - help_text=_("Enter the same password as before, for verification."), - ) - +class MailboxChangePasswordForm(ChangePasswordForm): + class Meta: fields = ("password",) model = Mailbox - def clean_password2(self): - password = self.cleaned_data.get("password") - password2 = self.cleaned_data.get("password2") - if password and password2 and password != password2: - raise ValidationError( - self.error_messages['password_mismatch'], - code='password_mismatch', - ) - return password2 - - + class MailboxCreateForm(forms.ModelForm): error_messages = { 'password_mismatch': _('The two password fields didn’t match.'), @@ -120,7 +135,7 @@ class MailboxCreateForm(forms.ModelForm): self.error_messages['password_mismatch'], code='password_mismatch', ) - return password2 + return password def save(self, commit=True): instance = super().save(commit=False) @@ -169,3 +184,14 @@ class RecordUpdateForm(ValidateZoneMixin, forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.domain = self.instance.domain + + +class WebappUsersChangePasswordForm(ChangePasswordForm): + class Meta: + fields = ("password",) + model = WebappUsers + +class SystemUsersChangePasswordForm(ChangePasswordForm): + class Meta: + fields = ("password",) + model = SystemUser diff --git a/orchestra/contrib/musician/templates/musician/systemuser_change_password.html b/orchestra/contrib/musician/templates/musician/systemuser_change_password.html new file mode 100644 index 00000000..c2e7b933 --- /dev/null +++ b/orchestra/contrib/musician/templates/musician/systemuser_change_password.html @@ -0,0 +1,15 @@ +{% extends "musician/base.html" %} +{% load bootstrap4 i18n %} + +{% block content %} +
{% trans "The main user is your system's main user on each server. You'll be able to view the logs of your websites at (/home/account/logs) and all web content, but you'll never be able to edit content on a website." %}
+{% trans "This user only has write permissions in their own directory." %}
+ + +{% trans "Username" %} | +{% trans "Path" %} | ++ |
---|---|---|
{{ systemuser.username }} | +{{ systemuser.home }}/{{ systemuser.username }} | ++ + | +
{{ service.description }}
+ +{% with request.resolver_match.url_name as url_name %} + +{% endwith %} + +{% trans "Username" %} | +{% trans "Path" %} | +{% trans "Server" %} | ++ |
---|---|---|---|
{{ webappuser.username }} | +/home/{{ webappuser.account }}/webapps/{{ webappuser.home }} | +{{ webappuser.target_server }} | ++ + {% trans "Update password" %} + | +