mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-19 09:53:34 -06:00
Fixes #1955: Require a plaintext value when creating a new secret
This commit is contained in:
parent
f5bb072f28
commit
8ae13e29f5
@ -58,17 +58,34 @@ class SecretRoleCSVForm(forms.ModelForm):
|
|||||||
#
|
#
|
||||||
|
|
||||||
class SecretForm(BootstrapMixin, forms.ModelForm):
|
class SecretForm(BootstrapMixin, forms.ModelForm):
|
||||||
plaintext = forms.CharField(max_length=65535, required=False, label='Plaintext',
|
plaintext = forms.CharField(
|
||||||
widget=forms.PasswordInput(attrs={'class': 'requires-session-key'}))
|
max_length=65535,
|
||||||
plaintext2 = forms.CharField(max_length=65535, required=False, label='Plaintext (verify)',
|
required=False,
|
||||||
widget=forms.PasswordInput())
|
label='Plaintext',
|
||||||
|
widget=forms.PasswordInput(attrs={'class': 'requires-session-key'})
|
||||||
|
)
|
||||||
|
plaintext2 = forms.CharField(
|
||||||
|
max_length=65535,
|
||||||
|
required=False,
|
||||||
|
label='Plaintext (verify)',
|
||||||
|
widget=forms.PasswordInput()
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Secret
|
model = Secret
|
||||||
fields = ['role', 'name', 'plaintext', 'plaintext2']
|
fields = ['role', 'name', 'plaintext', 'plaintext2']
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
||||||
|
super(SecretForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
# A plaintext value is required when creating a new Secret
|
||||||
|
if not self.instance.pk:
|
||||||
|
self.fields['plaintext'].required = True
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
||||||
|
# Verify that the provided plaintext values match
|
||||||
if self.cleaned_data['plaintext'] != self.cleaned_data['plaintext2']:
|
if self.cleaned_data['plaintext'] != self.cleaned_data['plaintext2']:
|
||||||
raise forms.ValidationError({
|
raise forms.ValidationError({
|
||||||
'plaintext2': "The two given plaintext values do not match. Please check your input."
|
'plaintext2': "The two given plaintext values do not match. Please check your input."
|
||||||
|
Loading…
Reference in New Issue
Block a user