-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,28 @@ | ||
from django.contrib.auth.decorators import login_required | ||
from django.http import HttpResponse | ||
from django.shortcuts import render | ||
from django.http import HttpResponse, HttpResponseForbidden | ||
from django.shortcuts import get_object_or_404, render | ||
|
||
from .models import UserPasskey | ||
|
||
|
||
@login_required | ||
def index(request, enroll=False): # noqa | ||
keys = UserPasskey.objects.filter(user=request.user) # pragma: no cover | ||
return render(request, 'PassKeys.html', {"keys": keys, "enroll": enroll}) # pragma: no cover | ||
return render(request, "PassKeys.html", {"keys": keys, "enroll": enroll}) # pragma: no cover | ||
|
||
|
||
@login_required | ||
def delKey(request): | ||
key=UserPasskey.objects.get(id=request.GET["id"]) | ||
if key.user.pk == request.user.pk: | ||
key.delete() | ||
return HttpResponse("Deleted Successfully") | ||
return HttpResponse("Error: You own this token so you can't delete it", status=403) | ||
key = get_object_or_404(UserPasskey, id=request.GET["id"], user=request.user) | ||
key.delete() | ||
return HttpResponse("Deleted Successfully") | ||
|
||
|
||
@login_required | ||
def toggleKey(request): | ||
id=request.GET["id"] | ||
q=UserPasskey.objects.filter(user=request.user, id=id) | ||
if q.count()==1: | ||
key=q[0] | ||
key.enabled=not key.enabled | ||
key.save() | ||
key = UserPasskey.objects.filter(id=request.GET["id"], user=request.user).first() | ||
if key is not None: | ||
key.enabled = not key.enabled | ||
key.save(update_fields=["enabled"]) | ||
return HttpResponse("OK") | ||
return HttpResponse("Error: You own this token so you can't toggle it", status=403) | ||
return HttpResponseForbidden("Error: You own this token so you can't toggle it") |