mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2025-08-26 13:21:14 +00:00
feat: add public VPN invite view and template
This commit is contained in:
@@ -1,3 +1,33 @@
|
||||
from django.http import Http404
|
||||
from django.shortcuts import render
|
||||
from django.utils import timezone
|
||||
|
||||
# Create your views here.
|
||||
from vpn_invite.models import PeerInvite, InviteSettings
|
||||
|
||||
|
||||
def view_public_vpn_invite(request):
|
||||
PeerInvite.objects.filter(invite_expiration__lt=timezone.now()).delete()
|
||||
try:
|
||||
peer_invite = PeerInvite.objects.get(uuid=request.GET.get('token'))
|
||||
invite_settings = InviteSettings.objects.get(name='default_settings')
|
||||
except:
|
||||
raise Http404
|
||||
|
||||
# Initialize context with default values
|
||||
context = {
|
||||
'peer_invite': peer_invite,
|
||||
'invite_settings': invite_settings,
|
||||
'authenticated': False,
|
||||
'error': ''
|
||||
}
|
||||
|
||||
if request.method == 'POST':
|
||||
password = request.POST.get('password', '')
|
||||
# Check if the provided password matches the invite password
|
||||
if password and password == peer_invite.invite_password:
|
||||
context['authenticated'] = True
|
||||
context['password'] = password
|
||||
else:
|
||||
context['error'] = "Invalid password. Please try again."
|
||||
|
||||
return render(request, 'vpn_invite/public_vpn_invite.html', context=context)
|
||||
|
Reference in New Issue
Block a user