1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #1955: Require a plaintext value when creating a new secret

This commit is contained in:
Jeremy Stretch
2018-03-07 11:20:10 -05:00
parent f5bb072f28
commit 8ae13e29f5

View File

@ -58,17 +58,34 @@ class SecretRoleCSVForm(forms.ModelForm):
#
class SecretForm(BootstrapMixin, forms.ModelForm):
plaintext = forms.CharField(max_length=65535, required=False, label='Plaintext',
widget=forms.PasswordInput(attrs={'class': 'requires-session-key'}))
plaintext2 = forms.CharField(max_length=65535, required=False, label='Plaintext (verify)',
widget=forms.PasswordInput())
plaintext = forms.CharField(
max_length=65535,
required=False,
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:
model = Secret
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):
# Verify that the provided plaintext values match
if self.cleaned_data['plaintext'] != self.cleaned_data['plaintext2']:
raise forms.ValidationError({
'plaintext2': "The two given plaintext values do not match. Please check your input."