mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-03-17 22:36:17 +00:00
update QR code generation by implementing POST request handling and validating input fields in the authentication method forms
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import ipaddress
|
||||
import re
|
||||
|
||||
import pyotp
|
||||
@@ -317,6 +318,25 @@ class GatekeeperIPAddressForm(forms.ModelForm):
|
||||
'description': _('Description'),
|
||||
}
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
address = cleaned_data.get('address')
|
||||
prefix_length = cleaned_data.get('prefix_length')
|
||||
if address and prefix_length is not None:
|
||||
try:
|
||||
ip = ipaddress.ip_address(address)
|
||||
max_prefix = 32 if ip.version == 4 else 128
|
||||
if prefix_length > max_prefix:
|
||||
self.add_error(
|
||||
'prefix_length',
|
||||
_('Prefix length for IPv%(version)d must be between 0 and %(max)d.') % {
|
||||
'version': ip.version, 'max': max_prefix,
|
||||
},
|
||||
)
|
||||
except ValueError:
|
||||
pass # address field validation handles invalid IPs
|
||||
return cleaned_data
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
cancel_url = kwargs.pop('cancel_url', '#')
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user