# Copyright © 2022 Aravinth Manivannan # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from django.shortcuts import render from django.http import HttpResponse, Http404 from django.contrib.auth import authenticate from django.contrib.auth.decorators import login_required from django.views.decorators.csrf import csrf_protect from .models import OauthIntegration CREATE_APP_CTX = { "function": "Create new OAuth2 Application", "name": "Application Name", "redirect_uri": "Redirect URI", "privacy_policy": "Privacy Policy URI", } @login_required @csrf_protect def new_app(request): """ Create new OAuth integration APP """ if request.method == "GET": return render(request, "integrations/new.html", {"create_app": CREATE_APP_CTX}) if request.method == "POST": app = OauthIntegration( owned_by=request.user, name_text=request.POST["name"], redirect_uri=request.POST["redirect_uri"], ) if "privacy_policy" in request.POST: app.privacy_policy_uri = request.POST["privacy_policy"] print("OK") app.save() return HttpResponse("OK") return Http404("Method not supported")