musician saas create next fix crash with username _
This commit is contained in:
parent
456a193d10
commit
6f93a6eb94
|
@ -5,6 +5,7 @@ from django.utils.safestring import mark_safe
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
from orchestra.utils.python import random_ascii
|
||||
from django.core.exceptions import ValidationError
|
||||
from orchestra.core.validators import validate_user_nextcloud
|
||||
|
||||
from django.forms.widgets import HiddenInput
|
||||
|
||||
|
@ -124,20 +125,16 @@ class NextcloudCreateForm(forms.ModelForm):
|
|||
self.fields['service'].choices = [("nextcloud","nextCloud")]
|
||||
self.fields['password'].help_text = _("Suggestion: %s") % random_ascii(20)
|
||||
|
||||
|
||||
|
||||
def clean_password2(self):
|
||||
password = self.cleaned_data.get("password")
|
||||
password2 = self.cleaned_data.get("password2")
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
password = cleaned_data.get("password")
|
||||
password2 = cleaned_data.get("password2")
|
||||
validate_user_nextcloud(cleaned_data.get("name"))
|
||||
if password and password2 and password != password2:
|
||||
raise ValidationError(
|
||||
self.error_messages['password_mismatch'],
|
||||
code='password_mismatch',
|
||||
)
|
||||
return password
|
||||
|
||||
def clean_password(self):
|
||||
password = self.cleaned_data.get("password")
|
||||
self.fields['password'] = password
|
||||
self.instance.set_password(password)
|
||||
|
||||
return cleaned_data
|
||||
|
|
|
@ -118,6 +118,14 @@ def validate_hostname(hostname):
|
|||
raise ValidationError(_("Not a valid hostname (%s).") % name)
|
||||
|
||||
|
||||
def validate_user_nextcloud(value):
|
||||
if len(value) > 64:
|
||||
raise ValidationError(_("Too long for a username."))
|
||||
if len(value) < 3:
|
||||
raise ValidationError(_("Too short for a username."))
|
||||
validators.RegexValidator(r'^[a-zA-Z\d.-]+$', _(f"Enter a valid username ({value})."))(value)
|
||||
|
||||
|
||||
def validate_username(value):
|
||||
validators.RegexValidator(r'^[\w.-]+$', _("Enter a valid username."))(value)
|
||||
|
||||
|
|
Loading…
Reference in a new issue