diff --git a/myproject/myapp/UserTokenModel.py b/myproject/myapp/UserTokenModel.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/myproject/myapp/models.py b/myproject/myapp/models.py index 9d728a7ef58e7ef556b7b06dd4b245fbe7ef2a6f..edc97afd52e944d8c8d7dc32fffdd873dc0c94a7 100644 --- a/myproject/myapp/models.py +++ b/myproject/myapp/models.py @@ -3,6 +3,8 @@ from django.contrib.auth import get_user_model from django.contrib.auth.models import User, Group, Permission from django.contrib.contenttypes.models import ContentType from enum import Enum +from django.dispatch import receiver +from django.db.models.signals import post_save # class UserTypes(User): # USER_TYPE_CHOICES = ( @@ -47,6 +49,24 @@ class Profile(models.Model): return f'{self.user.username} Profile' +# Model to hold the user token count +class UserTokenCount(models.Model): + # User + user = models.OneToOneField(User, on_delete=models.CASCADE) + # Token count + token_count = models.IntegerField(default=0) + + def __str__(self): + return f'{self.user.username}\'s token count: {self.token_count}' + +# Automatically create a UserTokenCount entry for each user on user creation +@receiver(post_save, sender=User) +def create_or_update_user_profile(sender, instance, created, **kwargs): + if created: + UserTokenCount.objects.get_or_create(user=instance) + Profile.objects.get_or_create(user=instance) + # instance.profile.save() + class Action(Enum): UPLOAD_FILE = "The user has successfully uploaded a file." LOGIN = "The user has logged in to their account." diff --git a/myproject/myapp/payments.py b/myproject/myapp/payments.py new file mode 100644 index 0000000000000000000000000000000000000000..6cf511b5127dd2725d420ecc4d6cc9a32dd8adf2 --- /dev/null +++ b/myproject/myapp/payments.py @@ -0,0 +1,115 @@ +import paypalrestsdk +from django.conf import settings +from django.http import JsonResponse +from django.shortcuts import redirect, render +from django.urls import reverse +from django.shortcuts import redirect, render +from django.urls import reverse +from .models import UserTokenCount + +# Create a payment that can be made via the PayPal API +# Create a payment that can be made via the PayPal API +def create_payment(request): + # Configure PayPal SDK + paypalrestsdk.configure({ + "mode": settings.PAYPAL_MODE, + "client_id": settings.PAYPAL_CLIENT_ID, + "client_secret": settings.PAYPAL_CLIENT_SECRET + }) + + # Create payment object + payment = paypalrestsdk.Payment({ + "intent": "sale", + "payer": { + "payment_method": "paypal", + }, + "redirect_urls": { + "return_url": request.build_absolute_uri(reverse('execute_payment')), + "cancel_url": request.build_absolute_uri(reverse('payment_cancelled')), + }, + "transactions" : [{ + "item_list" : { + "items" : [{ + "name": "Test item", + "sku": "test item", + "price": "9.99", + "currency": "GBP", + "quantity": 1, + }] + }, + "amount" : { + "total": "9.99", + "currency": "GBP" + }, + "description": "Test payment description" + }] + }) + + # Successfully communicated with API + if payment.create(): + print("Payment created successfully!") + # get url for payment approval + for link in payment.links: + if link.rel == "approval_url": + # turn link into text + approval_url = str(link.href) + # send on merry way + return redirect(approval_url) + else: + print(payment.error) + + +# Execute a successful payment +def execute_payment(request): + # Get payment id and payer id + payment_id = request.GET.get('paymentId') + payer_id = request.GET.get('PayerID') + + #If neither ID, error, restart + if not payment_id or not payer_id: + print("no payment") + #TODO: Change this to a more appropriate path, maybe a generic error page that takes a string:Error to display in a template + return redirect('handler404') + + # configure API + paypalrestsdk.configure({ + "mode": settings.PAYPAL_MODE, + "client_id": settings.PAYPAL_CLIENT_ID, + "client_secret": settings.PAYPAL_CLIENT_SECRET + }) + + # Check we've got a successful payment + payment = paypalrestsdk.Payment.find(payment_id) + + # If it we do an the payer IDs match + if payment.execute({"payer_id": payer_id}): + print("Payment executed successfully!") + + # Allocate some tokens + user = request.user + tokens_purchased = 1 + + # increment user_tokens + # commit changes + # TODO: Change something here such that the token amount added depends on a detail of the transaction, + # i.e. £9.99 payment for one token or £24.99 for + # + add_tokens(user, tokens_purchased) + + return redirect('success') + else: + #TODO: Change this to a more appropriate error message + print("exiting at the end of execute_payment()") + return redirect('handler404') + + +def add_tokens(user, tokens): + token_count_instance, created = UserTokenCount.objects.get_or_create(user=user) + token_count_instance.token_count += tokens + token_count_instance.save() + +def payment_cancelled(request): + return render(request, 'payment_cancelled.html') + +def payment_success(request): + return render(request,'payment_success.html') diff --git a/myproject/myapp/templates/index1.html b/myproject/myapp/templates/index1.html index b521f12d4f606c73627d57b41695b13eb593f422..fda1160729533a50f503412da44b80ca7fd4f15c 100644 --- a/myproject/myapp/templates/index1.html +++ b/myproject/myapp/templates/index1.html @@ -19,6 +19,7 @@ </div> </div> + {% if token_count > 0 %} <div class="gap-16 items-center py-8 px-4 mx-auto max-w-screen-xl lg:grid lg:grid-cols-2"> <form enctype="multipart/form-data" method="post" id="uploadForm"> {% csrf_token %} @@ -30,6 +31,17 @@ </button> </form> </div> + {% else %} + <div class="gap-16 items-center py-8 px-4 mx-auto max-w-screen-xl lg:grid lg:grid-cols-2"> + <div class="font-light text-gray-500 sm:text-lg dark:text-gray-400"> + <h2 class="mb-4 text-4xl tracking-tight font-extrabold text-gray-900 dark:text-white">Tokens required</h2> + <p class="mb-4">You require more tokens to use this service</p> + <button class="text-white bg-gray-800 hover:bg-gray-900 focus:outline-none focus:ring-4 focus:ring-gray-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-gray-800 dark:hover:bg-gray-700 dark:focus:ring-gray-700 dark:border-gray-700"> + <a href="{% url 'pricing' %}">Buy Tokens</a> + </button> + </div> + </div> + {% endif %} <div id="player" class="py-8 px-4 mx-auto max-w-screen-xl lg:py-8 hidden"> diff --git a/myproject/myapp/templates/payment_cancelled.html b/myproject/myapp/templates/payment_cancelled.html new file mode 100644 index 0000000000000000000000000000000000000000..e5240f5c7d78f8ee68bd51d9b23e29bdf8823973 --- /dev/null +++ b/myproject/myapp/templates/payment_cancelled.html @@ -0,0 +1,10 @@ +{% extends "_base.html" %}{% block content %} +<div class="grid grid-cols-1 gap-16 items-center py-8 px-4 mx-auto w-70 lg:grid"> + <div class="font-light text-gray-500 sm:text-lg dark:text-gray-400"> + <h2 class="mb-4 text-4xl tracking-tight font-extrabold text-gray-900 dark:text-white">Payment Cancelled</h2> + <p class="mb-4">Your payment has been cancelled.</p> + </div> +</div> + +<button class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-200 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-900 font-medium rounded-lg text-sm px-5 py-2.5 inline-flex justify-center text-center"><a href="{% url 'pricing' %}">Return</a></button> +{% endblock content%} diff --git a/myproject/myapp/templates/payment_success.html b/myproject/myapp/templates/payment_success.html new file mode 100644 index 0000000000000000000000000000000000000000..8496abe27218036de5f59812760e16c1b43ba7c9 --- /dev/null +++ b/myproject/myapp/templates/payment_success.html @@ -0,0 +1,10 @@ +{% extends "_base.html" %}{% block content %} +<div class="grid grid-cols-1 gap-16 items-center py-8 px-4 mx-auto w-70 lg:grid"> + <div class="font-light text-gray-500 sm:text-lg dark:text-gray-400"> + <h2 class="mb-4 text-4xl tracking-tight font-extrabold text-gray-900 dark:text-white">Success!</h2> + <p class="mb-4">Your payment was successful and you have been credited with 1 token.</p> + </div> +</div> + +<button class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-200 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-900 font-medium rounded-lg text-sm px-5 py-2.5 inline-flex justify-center text-center"><a href="{% url 'users' %}">Return</a></button> +{% endblock content%} diff --git a/myproject/myapp/templates/pricing.html b/myproject/myapp/templates/pricing.html index 42ff5a92c6da60fb20f22eac6dae6ee0b5765998..78b60c2de6bfdf0b8bc7348ba8439a66e76fbcc0 100644 --- a/myproject/myapp/templates/pricing.html +++ b/myproject/myapp/templates/pricing.html @@ -1,68 +1,48 @@ {% extends "_base.html" %}{% block content %} -<div class="grid content-start"> - <div class="my-5"> - <h1>Purchase Tokens</h1> - <p>We operate through a token model. To use our service, you must purchase tokens that can be redeemed for model runs.</p> +<div class="grid grid-cols-1 gap-16 items-center py-8 px-4 mx-auto w-70 lg:grid"> + <div class="font-light text-gray-500 sm:text-lg dark:text-gray-400"> + <h2 class="mb-4 text-4xl tracking-tight font-extrabold text-gray-900 dark:text-white">An Intelligent System for Instrument Detection</h2> + <p class="mb-4">*placeholder input* We present to you a intelligent system for instrument detection. Using audio processing techinques and a convolutionsal + neural network we are able to classify instruments used in a song. other exciting words that might catch peoples attention and make them use our product. + To use our service upload an mp3 file below. + *placeholder input* + </p> </div> + </div> <div class="grid grid-cols-2 content-start"> - <div class="w-full mx-auto max-w-sm p-4 bg-white border border-gray-200 rounded-lg shadow sm:p-8 dark:bg-gray-800 dark:border-gray-700"> - <h5 class="mb-4 text-xl font-medium text-gray-500 dark:text-gray-400">Trial plan</h5> + <div class="w-full h-80 mx-auto max-w-sm p-4 bg-white border border-gray-200 rounded-lg shadow sm:p-8 dark:bg-gray-800 dark:border-gray-700"> + <h5 class="mb-4 text-xl font-medium text-gray-500 dark:text-gray-400">Single Purchase</h5> <div class="flex items-baseline text-gray-900 dark:text-white"> - <span class="text-5xl font-extrabold tracking-tight">Free</span> + <span class="text-5xl font-extrabold tracking-tight">£9.99</span> </div> <ul role="list" class="space-y-5 my-7"> <li class="flex items-center"> <svg class="flex-shrink-0 w-4 h-4 text-blue-700 dark:text-blue-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20"> <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/> </svg> - <span class="text-base font-normal leading-tight text-gray-500 dark:text-gray-400 ms-3">1 team member</span> - </li> - <li class="flex"> - <svg class="flex-shrink-0 w-4 h-4 text-blue-700 dark:text-blue-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20"> - <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/> - </svg> - <span class="text-base font-normal leading-tight text-gray-500 dark:text-gray-400 ms-3">0GB Cloud storage</span> - </li> - <li class="flex decoration-gray-500"> - <svg class="flex-shrink-0 w-4 h-4 text-blue-700 dark:text-gray-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20"> - <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/> - </svg> - <span class="text-base font-normal leading-tight text-gray-500 ms-3">1 File upload</span> - <span class="ms-1 text-sm font-normal text-gray-500 dark:text-gray-400">/month</span> - </li> - <li class="flex line-through decoration-gray-500"> - <svg class="flex-shrink-0 w-4 h-4 text-gray-400 dark:text-blue-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20"> - <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/> - </svg> - <span class="text-base font-normal leading-tight text-gray-500 dark:text-gray-400 ms-3">Integration help</span> + <span class="text-base font-normal leading-tight text-gray-500 dark:text-gray-400 ms-3">1 token</span> </li> - <li class="flex line-through decoration-gray-500"> + <li class="flex decoration-gray-500"> <svg class="flex-shrink-0 w-4 h-4 text-gray-400 dark:text-gray-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20"> <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/> </svg> <span class="text-base font-normal leading-tight text-gray-500 ms-3">API Access</span> </li> - <li class="flex line-through decoration-gray-500"> + <li class="flex decoration-gray-500"> <svg class="flex-shrink-0 w-4 h-4 text-gray-400 dark:text-gray-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20"> <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/> </svg> - <span class="text-base font-normal leading-tight text-gray-500 ms-3">Complete documentation</span> - </li> - <li class="flex line-through decoration-gray-500"> - <svg class="flex-shrink-0 w-4 h-4 text-gray-400 dark:text-gray-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20"> - <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/> - </svg> - <span class="text-base font-normal leading-tight text-gray-500 ms-3">24×7 phone & email support</span> + <span class="text-base font-normal leading-tight text-gray-500 ms-3">Email support</span> </li> </ul> - <button type="button" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-200 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-900 font-medium rounded-lg text-sm px-5 py-2.5 inline-flex justify-center w-full text-center">Choose plan</button> + <button type="button" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-200 dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-900 font-medium rounded-lg text-sm px-5 py-2.5 inline-flex justify-center w-full text-center"><a href="{% url 'create_payment' %}">Purchase via PayPal</a></button> </div> <div class="w-full mx-auto max-w-sm p-4 bg-white border border-gray-200 rounded-lg shadow sm:p-8 dark:bg-gray-800 dark:border-gray-700"> - <h5 class="mb-4 text-xl font-medium text-gray-500 dark:text-gray-400">Standard plan</h5> + <h5 class="mb-4 text-xl font-medium text-gray-500 dark:text-gray-400">Bulk Purchase</h5> <div class="flex items-baseline text-gray-900 dark:text-white"> <span class="text-3xl font-semibold">£</span> <span class="text-5xl font-extrabold tracking-tight">49</span> diff --git a/myproject/myapp/templates/user_page.html b/myproject/myapp/templates/user_page.html index 3999efc3ab6b9d657c20f4c5a83be8d2f9edca28..c6952ce5487830c6c60feb59145504edef7a5c2e 100644 --- a/myproject/myapp/templates/user_page.html +++ b/myproject/myapp/templates/user_page.html @@ -3,156 +3,31 @@ class="grid grid-cols-1 px-4 pt-6 xl:grid-cols-3 xl:gap-4 dark:bg-grey-300" > <div class="mb-4 col-span-full xl:mb-2"> - <h1 class="text-xl font-semibold text-gray-800 sm:text-2xl dark:text-white"> + <h1 class="mb-4 text-4xl tracking-tight font-extrabold text-gray-900 dark:text-white"> User settings </h1> + <h3 class="mb-4 text-xl font-semibold dark:text-white"> + User type: {{ user_profile.user_type }} + </h3> </div> <!-- Right Content --> + <div class="col-span-full xl:col-auto"> + <div class="p-4 mb-4 bg-white border boder-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800"> + <h3 class="mb-4 text-xl font-semibold dark:text-white">Tokens:</h3> + <p class="mb-4 text-xl font-semibold dark:text-white">{{ token_count }}</p> + </div> <div class="p-4 mb-4 bg-white border boder-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800"> <h3 class="mb-4 text-xl font-semibold dark:text-white">Change your password</h3> <a href="{% url 'password_change' %}" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Change Password</a> </div> - <!-- <div - class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800" - > - <h3 class="mb-4 text-xl font-semibold dark:text-white"> - Password information - </h3> - <form action="#"> - <div class="grid grid-cols-6 gap-6"> - <div class="col-span-6 sm:col-span-3"> - <label - for="current-password" - class="block mb-2 text-sm font-medium text-gray-900 dark:text-white" - >Current password</label - > - <input - type="text" - name="current-password" - id="current-password" - class="shadow-sm bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" - placeholder="••••••••" - required - /> - </div> - <div class="col-span-6 sm:col-span-3"> - <label - for="password" - class="block mb-2 text-sm font-medium text-gray-900 dark:text-white" - >New password</label - > - <input - data-popover-target="popover-password" - data-popover-placement="bottom" - type="password" - id="password" - class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" - placeholder="••••••••" - required - /> - <div - data-popover - id="popover-password" - role="tooltip" - class="absolute z-10 invisible inline-block text-sm font-light text-gray-500 transition-opacity duration-300 bg-white border border-gray-200 rounded-lg shadow-sm opacity-0 w-72 dark:bg-gray-800 dark:border-gray-600 dark:text-gray-400" - > - <div class="p-3 space-y-2"> - <h3 class="font-semibold text-gray-900 dark:text-white"> - Must have at least 6 characters - </h3> - <div class="grid grid-cols-4 gap-2"> - <div class="h-1 bg-orange-300 dark:bg-orange-400"></div> - <div class="h-1 bg-orange-300 dark:bg-orange-400"></div> - <div class="h-1 bg-gray-200 dark:bg-gray-600"></div> - <div class="h-1 bg-gray-200 dark:bg-gray-600"></div> - </div> - <p>It’s better to have:</p> - <ul> - <li class="flex items-center mb-1"> - <svg - class="w-4 h-4 mr-2 text-green-400 dark:text-green-500" - aria-hidden="true" - fill="currentColor" - viewBox="0 0 20 20" - xmlns="http://www.w3.org/2000/svg" - > - <path - fill-rule="evenodd" - d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" - clip-rule="evenodd" - ></path> - </svg> - Upper & lower case letters - </li> - <li class="flex items-center mb-1"> - <svg - class="w-4 h-4 mr-2 text-gray-300 dark:text-gray-400" - aria-hidden="true" - fill="currentColor" - viewBox="0 0 20 20" - xmlns="http://www.w3.org/2000/svg" - > - <path - fill-rule="evenodd" - d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" - clip-rule="evenodd" - ></path> - </svg> - A symbol (#$&) - </li> - <li class="flex items-center"> - <svg - class="w-4 h-4 mr-2 text-gray-300 dark:text-gray-400" - aria-hidden="true" - fill="currentColor" - viewBox="0 0 20 20" - xmlns="http://www.w3.org/2000/svg" - > - <path - fill-rule="evenodd" - d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" - clip-rule="evenodd" - ></path> - </svg> - A longer password (min. 12 chars.) - </li> - </ul> - </div> - <div data-popper-arrow></div> - </div> - </div> - <div class="col-span-6 sm:col-span-3"> - <label - for="confirm-password" - class="block mb-2 text-sm font-medium text-gray-900 dark:text-white" - >Confirm password</label - > - <input - type="text" - name="confirm-password" - id="confirm-password" - class="shadow-sm bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" - placeholder="••••••••" - required - /> - </div> - <div class="col-span-6 sm:col-full"> - <button - class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800" - type="submit" - > - Save all - </button> - </div> - </div> - </form> - {% comment %} REPLACE WITH LOGIC TO CHECK PROPER USER {% endcomment %} - </div> --> - {% if 1 %} + + + {% if user_profile.user_type == 3 %} <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800" > + <h3 class="mb-4 text-xl font-semibold dark:text-white"> Generate Financial Statement </h3> @@ -200,7 +75,8 @@ </form> {% comment %} REPLACE WITH LOGIC TO CHECK PROPER USER {% endcomment %} </div> - {% endif %} {% if 1 %} + {% endif %} + {% if 1 %} <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800" @@ -261,7 +137,7 @@ class="shadow-sm bg-gray-50 border border-gray-300 text-grey-300 sm:text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="example@gmail.com" required - >example@gmail.com</span + >{{ user.email }}</span > </div> <div class="col-span-6 sm:col-span-3"> @@ -277,7 +153,7 @@ class="shadow-sm bg-gray-50 border border-gray-300 text-grey-300 sm:text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" placeholder="Green" required - >LoginExample</span + >{{ user.username }}</span > </div> </div> @@ -324,7 +200,7 @@ </div> {% if 1 %} {% comment %} REPLACE WITH LOGIC TO CHECK PROPER USER {%endcomment %} - + {% if user_profile.user_type == 2 %} <div class="p-4 mb-4 bg-white border border-gray-200 rounded-lg shadow-sm 2xl:col-span-2 dark:border-gray-700 sm:p-6 dark:bg-gray-800" > @@ -369,6 +245,7 @@ </tbody> </table> </div> + {% endif %} {% endif %} {% comment %} Admin page functionality end {% endcomment %} </div> </div> diff --git a/myproject/myapp/urls.py b/myproject/myapp/urls.py index ff5404ea65fe5b9ef049ff1cecbaf14eb91f29c6..f7c169ca586946c0e567e5743886c6cf0d40c6c3 100644 --- a/myproject/myapp/urls.py +++ b/myproject/myapp/urls.py @@ -1,6 +1,6 @@ from django.urls import path - -from .views import InstrumentDetectionView, index, log_fileupload, users, maintenance, handler404, handler500, terms_conditions, privacy_policy, handling_music_file, pricing, generate_pdf, admin_table +from .views import InstrumentDetectionView, index, users, maintenance, handler404, handler500, terms_conditions, privacy_policy, handling_music_file, pricing, generate_pdf, admin_table +from .payments import create_payment, execute_payment, payment_cancelled, payment_success from django.contrib.auth import views as auth_views # Authentication @@ -10,7 +10,7 @@ from django.contrib.auth.views import LoginView, LogoutView urlpatterns = [ path('', index, name='index'), path('user/', users, name='users'), - path('404/', handler404), + path('404/', handler404, name='handler404'), path('500/', handler500), path('maintenance/', maintenance), # path('register/', register, name='register'), @@ -26,11 +26,20 @@ urlpatterns = [ path('instrument_detection/', InstrumentDetectionView.as_view(), name='instrument_detection'), path('password_change/', auth_views.PasswordChangeView.as_view(template_name='password_change_form.html'), name='password_change'), path('password_change/done/', auth_views.PasswordChangeDoneView.as_view(template_name='password_change_done.html'), name='password_change_done'), - # path('user_logout/', auth_views.LogoutView.as_view(next_page='index'), name='user_logout') - path('log_fileupload', log_fileupload, name='log_fileupload'), + # path('user_logout/', auth_views.LogoutView.as_view(next_page='index'), name='user_logout'), + path('payment/create/', create_payment, name='create_payment'), + path('payment/execute/', execute_payment, name='execute_payment'), + path('payment/cancel/', payment_cancelled, name='payment_cancelled'), + path('payment_success/', payment_success, name='success'), # Authentication path('login/', CustomLoginView.as_view(), name='login'), path('logout/', LogoutView.as_view(), name='logout'), path('register/', RegisterView.as_view(), name='register'), + path('user_logout/', auth_views.LogoutView.as_view(next_page='index'), name='user_logout'), + # Payment + path('payment/create/', create_payment, name='create_payment'), + path('payment/execute/', execute_payment, name='execute_payment'), + path('payment/cancel/', payment_cancelled, name='payment_cancelled'), + path('payment_success/', payment_success, name='success') ] diff --git a/myproject/myapp/views.py b/myproject/myapp/views.py index 17fd4ac84776d6b30d9d9d31fc6727a314679e23..3aab0b85ae4a7ae0220e8dadf6c6656f6e5b3542 100644 --- a/myproject/myapp/views.py +++ b/myproject/myapp/views.py @@ -12,7 +12,7 @@ import json from datetime import datetime from .forms import InstrumentDetectionForm -from .models import Log, Action, User +from .models import Log, Action, User, UserTokenCount from django.http import JsonResponse from django.db import connection @@ -128,6 +128,8 @@ def index(request): # Handle authenticated users if request.user.is_authenticated: + token_count = UserTokenCount.objects.get(user=request.user).token_count + context['token_count'] = token_count if request.method == 'POST': form = InstrumentDetectionForm(request.POST, request.FILES) if form.is_valid() and 'audio_file' in request.FILES: @@ -171,10 +173,16 @@ def users(request): data_user = user_table(request) admin_dict = json.loads(data_admin.content) user_dict = json.loads(data_user.content) + token_count = UserTokenCount.objects.get(user=request.user).token_count + user_profile = request.user.profile + user = request.user # Pass the data as a context variable to the template # !!! ADMIN DATA ONLY DISPLAYED AND GET IF USER IS ADMIN !!! context['admin_data'] = admin_dict['data'] context['user_data'] = user_dict['data'] + context['token_count'] = token_count + context['user_profile'] = user_profile + context['user'] = user return render(request, 'user_page.html', context) diff --git a/myproject/myproject/settings.py b/myproject/myproject/settings.py index f4f4170d35aea11fc55f2c37a39cc94fb5e10b4c..5bb1e5500b386eb2343bb0efe23931a689bb39ce 100644 --- a/myproject/myproject/settings.py +++ b/myproject/myproject/settings.py @@ -173,4 +173,10 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' IMAGE_URL = 'static/src/images/' LOGIN_REDIRECT_URL = '/' -LOGOUT_REDIRECT_URL = '/' + + +#PayPal API settings +PAYPAL_MODE = 'sandbox' +PAYPAL_CLIENT_ID = 'AYpHxonrFMrgnqmjii46SeNsQidn2PjJtEoIgVK0Nrda1iQFUbX28zyuMvUiJk67o_cHII3c8vCMWY-y' +PAYPAL_CLIENT_SECRET = 'EPXXK3Z7xDr4Gy_kt4OkPLbJRXd9tP62q1Dpbmj5QiwaFh7twcSUalHDRBbFRwxdX_rmHk_F6YStXa95' + diff --git a/myproject/requirements.txt b/myproject/requirements.txt index 287a93c4c764530b81983644f4a67744f38e5009..488687a1d85db374593a186e1c96f96cc4fe3e7c 100644 --- a/myproject/requirements.txt +++ b/myproject/requirements.txt @@ -37,4 +37,5 @@ urllib3==2.2.1 reportlab==4.1.0 chardet==5.2.0 charset-normalizer==3.3.2 -pillow==10.2.0 \ No newline at end of file +pillow==10.2.0 +paypalrestsdk==1.13.3 \ No newline at end of file