From c9bccec1a5861e46557e2a44cccd6e194f287e3a Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Thu, 27 Jan 2022 11:37:38 +0100 Subject: [PATCH] #31 API Frontend token generating * adds frontend settings for users to create API tokens on their user settings --- api/urls/urls.py | 3 + api/views/method_views.py | 35 +++++++ api/views/views.py | 2 +- compensation/views/compensation.py | 2 +- compensation/views/eco_account.py | 2 +- ema/views.py | 2 +- intervention/views.py | 2 +- .../widgets/generate-content-input.html | 6 +- locale/de/LC_MESSAGES/django.mo | Bin 34703 -> 35548 bytes locale/de/LC_MESSAGES/django.po | 89 ++++++++++++++---- user/forms.py | 48 +++++++++- user/models/user.py | 17 ++++ user/templates/user/index.html | 8 ++ user/templates/user/token.html | 31 ++++++ user/urls.py | 1 + user/views.py | 36 ++++++- 16 files changed, 255 insertions(+), 29 deletions(-) create mode 100644 api/views/method_views.py create mode 100644 user/templates/user/token.html diff --git a/api/urls/urls.py b/api/urls/urls.py index fe0ddbbc..abe9eacf 100644 --- a/api/urls/urls.py +++ b/api/urls/urls.py @@ -7,8 +7,11 @@ Created on: 21.01.22 """ from django.urls import path, include +from api.views.method_views import generate_new_token_view + app_name = "api" urlpatterns = [ path("v1/", include("api.urls.v1.urls", namespace="v1")), + path("token/generate", generate_new_token_view, name="generate-new-token"), ] \ No newline at end of file diff --git a/api/views/method_views.py b/api/views/method_views.py new file mode 100644 index 00000000..7c6904a5 --- /dev/null +++ b/api/views/method_views.py @@ -0,0 +1,35 @@ +""" +Author: Michel Peltriaux +Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany +Contact: michel.peltriaux@sgdnord.rlp.de +Created on: 27.01.22 + +""" +from django.contrib.auth.decorators import login_required +from django.http import HttpRequest, JsonResponse + +from api.models import APIUserToken + + +@login_required +def generate_new_token_view(request: HttpRequest): + """ Handles request for fetching + + Args: + request (HttpRequest): The incoming request + + Returns: + + """ + + if request.method == "GET": + token = APIUserToken() + while APIUserToken.objects.filter(token=token.token).exists(): + token = APIUserToken() + return JsonResponse( + data={ + "gen_data": token.token + } + ) + else: + raise NotImplementedError \ No newline at end of file diff --git a/api/views/views.py b/api/views/views.py index 32b0e500..8cbdc1ec 100644 --- a/api/views/views.py +++ b/api/views/views.py @@ -253,4 +253,4 @@ class EcoAccountAPIShareView(AbstractModelShareAPIView): class EmaAPIShareView(AbstractModelShareAPIView): - model = Ema \ No newline at end of file + model = Ema diff --git a/compensation/views/compensation.py b/compensation/views/compensation.py index 323921e4..009eaf82 100644 --- a/compensation/views/compensation.py +++ b/compensation/views/compensation.py @@ -108,7 +108,7 @@ def new_id_view(request: HttpRequest): identifier = tmp.generate_new_identifier() return JsonResponse( data={ - "identifier": identifier + "gen_data": identifier } ) diff --git a/compensation/views/eco_account.py b/compensation/views/eco_account.py index 5c061b96..59b82a7b 100644 --- a/compensation/views/eco_account.py +++ b/compensation/views/eco_account.py @@ -118,7 +118,7 @@ def new_id_view(request: HttpRequest): identifier = tmp.generate_new_identifier() return JsonResponse( data={ - "identifier": identifier + "gen_data": identifier } ) diff --git a/ema/views.py b/ema/views.py index 1e8b089c..8a3454e3 100644 --- a/ema/views.py +++ b/ema/views.py @@ -108,7 +108,7 @@ def new_id_view(request: HttpRequest): identifier = tmp.generate_new_identifier() return JsonResponse( data={ - "identifier": identifier + "gen_data": identifier } ) diff --git a/intervention/views.py b/intervention/views.py index 50856dfb..3d65b7df 100644 --- a/intervention/views.py +++ b/intervention/views.py @@ -108,7 +108,7 @@ def new_id_view(request: HttpRequest): identifier = tmp_intervention.generate_new_identifier() return JsonResponse( data={ - "identifier": identifier + "gen_data": identifier } ) diff --git a/konova/templates/konova/widgets/generate-content-input.html b/konova/templates/konova/widgets/generate-content-input.html index 66c91988..9d2f9837 100644 --- a/konova/templates/konova/widgets/generate-content-input.html +++ b/konova/templates/konova/widgets/generate-content-input.html @@ -1,9 +1,9 @@ {% load i18n fontawesome_5 %}
- +
- {% fa5_icon 'dice' %} + {% fa5_icon 'dice' %}