From d63b5f45a7a494a62ca2f0f5af1a22db8b2cc3a3 Mon Sep 17 00:00:00 2001 From: rizwanisready Date: Thu, 14 Mar 2024 16:31:08 +0530 Subject: [PATCH] notifications 14-03-2024 13:48 new stripe html --- manage_notifications/utils.py | 14 +-- manage_notifications/views.py | 4 +- manage_subscriptions/urls.py | 1 + manage_subscriptions/views.py | 37 ++++++- .../payment => static}/images/1 inner.png | Bin {templates/payment => static}/images/1.png | Bin .../payment => static}/images/2 inner.png | Bin {templates/payment => static}/images/2.png | Bin .../payment => static}/images/3 inner.png | Bin {templates/payment => static}/images/3.png | Bin .../images/About Us Banner.png | Bin .../payment => static}/images/Adventure.png | Bin .../payment => static}/images/Star 1.png | Bin {templates/payment => static}/images/ab.png | Bin .../payment => static}/images/about1.png | Bin .../payment => static}/images/about2.png | Bin {templates/payment => static}/images/at.png | Bin .../payment => static}/images/baner.jpg | Bin .../images/banner-mobile-cut.png | Bin .../images/banner-mobile.png | Bin .../payment => static}/images/group.png | Bin {templates/payment => static}/images/ham.png | Bin .../images/iPhone 14 Pro Max.png | Bin {templates/payment => static}/images/icon.png | Bin .../payment => static}/images/key mini.png | Bin .../payment => static}/images/key nini 2.png | Bin .../payment => static}/images/key-main.png | Bin {templates/payment => static}/images/logo.png | Bin .../images/menu-left-btn.png | Bin .../images/menu-right-btn.png | Bin .../payment => static}/images/terms.png | Bin templates/{payment => stripe_html}/index.html | 96 ++++++++++++------ 32 files changed, 110 insertions(+), 42 deletions(-) rename {templates/payment => static}/images/1 inner.png (100%) rename {templates/payment => static}/images/1.png (100%) rename {templates/payment => static}/images/2 inner.png (100%) rename {templates/payment => static}/images/2.png (100%) rename {templates/payment => static}/images/3 inner.png (100%) rename {templates/payment => static}/images/3.png (100%) rename {templates/payment => static}/images/About Us Banner.png (100%) rename {templates/payment => static}/images/Adventure.png (100%) rename {templates/payment => static}/images/Star 1.png (100%) rename {templates/payment => static}/images/ab.png (100%) rename {templates/payment => static}/images/about1.png (100%) rename {templates/payment => static}/images/about2.png (100%) rename {templates/payment => static}/images/at.png (100%) rename {templates/payment => static}/images/baner.jpg (100%) rename {templates/payment => static}/images/banner-mobile-cut.png (100%) rename {templates/payment => static}/images/banner-mobile.png (100%) rename {templates/payment => static}/images/group.png (100%) rename {templates/payment => static}/images/ham.png (100%) rename {templates/payment => static}/images/iPhone 14 Pro Max.png (100%) rename {templates/payment => static}/images/icon.png (100%) rename {templates/payment => static}/images/key mini.png (100%) rename {templates/payment => static}/images/key nini 2.png (100%) rename {templates/payment => static}/images/key-main.png (100%) rename {templates/payment => static}/images/logo.png (100%) rename {templates/payment => static}/images/menu-left-btn.png (100%) rename {templates/payment => static}/images/menu-right-btn.png (100%) rename {templates/payment => static}/images/terms.png (100%) rename templates/{payment => stripe_html}/index.html (80%) diff --git a/manage_notifications/utils.py b/manage_notifications/utils.py index 90b52b3..2fa6a08 100644 --- a/manage_notifications/utils.py +++ b/manage_notifications/utils.py @@ -6,7 +6,7 @@ from .models import IAmPrincipalNotificationSettings, IAmPrincipal, PrincipalTyp def onesignal_send_notification( - title, message, image_url="http://127.0.0.1:8000/", eligible_principals=None + title, message, image_url=None, eligible_principals=None ): onesignal_app_id = settings.ONE_SIGNAL_APP_ID onesignal_rest_api_key = settings.ONE_SIGNAL_API_KEY @@ -33,9 +33,7 @@ def onesignal_send_notification( if image_url: # Include image URL if provided (requires additional OneSignal configuration) - data["large_icon"] = ( - str(image_url.url) - ) + data["large_icon"] = str(image_url.url) # data = json.dumps(data) print("Data: ", data) @@ -63,17 +61,19 @@ def send_notification(title, message, image_url=None, eligible_principals=None): return None # Or handle this scenario as needed # Extract OneSignal player IDs - player_ids = eligible_principals.values_list("player_id", flat=True) + # player_ids = eligible_principals.values_list("player_id", flat=True) # Prepare notification payload notification_payload = { "headings": {"en": title}, "contents": {"en": message}, - "include_player_ids": list(player_ids), + "include_player_ids": eligible_principals, + "big_picture": image_url.url, } if image_url: - notification_payload["big_picture"] = image_url + image_url_str = image_url.url + notification_payload["big_picture"] = image_url_str # Send notification response = onesignal_client.send_notification(notification_payload) diff --git a/manage_notifications/views.py b/manage_notifications/views.py index 618fb88..6244b44 100644 --- a/manage_notifications/views.py +++ b/manage_notifications/views.py @@ -12,6 +12,7 @@ from manage_notifications.models import PushNotification from manage_notifications.utils import ( get_eligible_principals_for_notification, onesignal_send_notification, + send_notification, ) # Create your views here. @@ -87,7 +88,8 @@ class PushNotificationsCreateOrUpdateView(LoginRequiredMixin, generic.View): title = push_notification.title message = push_notification.message image_url = push_notification.banner_image - onesignal_send_notification(title, message, image_url, player_ids) + # onesignal_send_notification(title, message, image_url, player_ids) + send_notification(title, message, image_url, player_ids) print(onesignal_send_notification) # if onesignal_send_notification( # push_notification.title, diff --git a/manage_subscriptions/urls.py b/manage_subscriptions/urls.py index cbd6198..8deff4e 100644 --- a/manage_subscriptions/urls.py +++ b/manage_subscriptions/urls.py @@ -73,4 +73,5 @@ urlpatterns = [ path("stripe/", views.SubscriptionPageView.as_view(), name="stripe"), path("success/", views.SuccessView.as_view(), name="success"), path("cancel/", views.CancelView.as_view(), name="cancel"), + path("join-now/", views.IndexView.as_view(), name="index"), ] diff --git a/manage_subscriptions/views.py b/manage_subscriptions/views.py index 40b58d6..8110929 100644 --- a/manage_subscriptions/views.py +++ b/manage_subscriptions/views.py @@ -342,7 +342,7 @@ class PrincipalSubscriptionDeleteView(LoginRequiredMixin, generic.View): class SubscriptionPageView(TemplateView): - template_name = "stripe_html/subscribe.html" + template_name = "stripe_html/index.html" def get(self, request, *args, **kwargs): # Example of extracting the token from a query parameter or cookie @@ -483,3 +483,38 @@ class SuccessView(TemplateView): class CancelView(TemplateView): template_name = "stripe_html/cancel.html" + + +class IndexView(TemplateView): + template_name = "stripe_html/index.html" + + def get(self, request, *args, **kwargs): + # Example of extracting the token from a query parameter or cookie + token = request.GET.get("token") + # token = request.GET.get("token") or request.COOKIES.get("jwt") + print("token: ", token) + if token: + try: + # Decode and validate token + payload = jwt.decode(token, settings.SECRET_KEY, algorithms=["HS256"]) + print("payload: ", payload) + try: + UserModel = get_user_model() + user = UserModel.objects.get(id=payload["user_id"]) + # Manually specify the authentication backend + user.backend = "django.contrib.auth.backends.ModelBackend" + # Log the user in + login(request, user) + print("Logged in user: ", user) + + except IAmPrincipal.DoesNotExist: + # Handle expired token + return HttpResponseBadRequest("No Principal Found") + + except jwt.ExpiredSignatureError: + # Handle expired token + return HttpResponseBadRequest("Expired Signature Error") + except jwt.InvalidTokenError: + return HttpResponseBadRequest("Invalid Token Error") + + return super().get(request, *args, **kwargs) diff --git a/templates/payment/images/1 inner.png b/static/images/1 inner.png similarity index 100% rename from templates/payment/images/1 inner.png rename to static/images/1 inner.png diff --git a/templates/payment/images/1.png b/static/images/1.png similarity index 100% rename from templates/payment/images/1.png rename to static/images/1.png diff --git a/templates/payment/images/2 inner.png b/static/images/2 inner.png similarity index 100% rename from templates/payment/images/2 inner.png rename to static/images/2 inner.png diff --git a/templates/payment/images/2.png b/static/images/2.png similarity index 100% rename from templates/payment/images/2.png rename to static/images/2.png diff --git a/templates/payment/images/3 inner.png b/static/images/3 inner.png similarity index 100% rename from templates/payment/images/3 inner.png rename to static/images/3 inner.png diff --git a/templates/payment/images/3.png b/static/images/3.png similarity index 100% rename from templates/payment/images/3.png rename to static/images/3.png diff --git a/templates/payment/images/About Us Banner.png b/static/images/About Us Banner.png similarity index 100% rename from templates/payment/images/About Us Banner.png rename to static/images/About Us Banner.png diff --git a/templates/payment/images/Adventure.png b/static/images/Adventure.png similarity index 100% rename from templates/payment/images/Adventure.png rename to static/images/Adventure.png diff --git a/templates/payment/images/Star 1.png b/static/images/Star 1.png similarity index 100% rename from templates/payment/images/Star 1.png rename to static/images/Star 1.png diff --git a/templates/payment/images/ab.png b/static/images/ab.png similarity index 100% rename from templates/payment/images/ab.png rename to static/images/ab.png diff --git a/templates/payment/images/about1.png b/static/images/about1.png similarity index 100% rename from templates/payment/images/about1.png rename to static/images/about1.png diff --git a/templates/payment/images/about2.png b/static/images/about2.png similarity index 100% rename from templates/payment/images/about2.png rename to static/images/about2.png diff --git a/templates/payment/images/at.png b/static/images/at.png similarity index 100% rename from templates/payment/images/at.png rename to static/images/at.png diff --git a/templates/payment/images/baner.jpg b/static/images/baner.jpg similarity index 100% rename from templates/payment/images/baner.jpg rename to static/images/baner.jpg diff --git a/templates/payment/images/banner-mobile-cut.png b/static/images/banner-mobile-cut.png similarity index 100% rename from templates/payment/images/banner-mobile-cut.png rename to static/images/banner-mobile-cut.png diff --git a/templates/payment/images/banner-mobile.png b/static/images/banner-mobile.png similarity index 100% rename from templates/payment/images/banner-mobile.png rename to static/images/banner-mobile.png diff --git a/templates/payment/images/group.png b/static/images/group.png similarity index 100% rename from templates/payment/images/group.png rename to static/images/group.png diff --git a/templates/payment/images/ham.png b/static/images/ham.png similarity index 100% rename from templates/payment/images/ham.png rename to static/images/ham.png diff --git a/templates/payment/images/iPhone 14 Pro Max.png b/static/images/iPhone 14 Pro Max.png similarity index 100% rename from templates/payment/images/iPhone 14 Pro Max.png rename to static/images/iPhone 14 Pro Max.png diff --git a/templates/payment/images/icon.png b/static/images/icon.png similarity index 100% rename from templates/payment/images/icon.png rename to static/images/icon.png diff --git a/templates/payment/images/key mini.png b/static/images/key mini.png similarity index 100% rename from templates/payment/images/key mini.png rename to static/images/key mini.png diff --git a/templates/payment/images/key nini 2.png b/static/images/key nini 2.png similarity index 100% rename from templates/payment/images/key nini 2.png rename to static/images/key nini 2.png diff --git a/templates/payment/images/key-main.png b/static/images/key-main.png similarity index 100% rename from templates/payment/images/key-main.png rename to static/images/key-main.png diff --git a/templates/payment/images/logo.png b/static/images/logo.png similarity index 100% rename from templates/payment/images/logo.png rename to static/images/logo.png diff --git a/templates/payment/images/menu-left-btn.png b/static/images/menu-left-btn.png similarity index 100% rename from templates/payment/images/menu-left-btn.png rename to static/images/menu-left-btn.png diff --git a/templates/payment/images/menu-right-btn.png b/static/images/menu-right-btn.png similarity index 100% rename from templates/payment/images/menu-right-btn.png rename to static/images/menu-right-btn.png diff --git a/templates/payment/images/terms.png b/static/images/terms.png similarity index 100% rename from templates/payment/images/terms.png rename to static/images/terms.png diff --git a/templates/payment/index.html b/templates/stripe_html/index.html similarity index 80% rename from templates/payment/index.html rename to templates/stripe_html/index.html index 6251b6d..eebf833 100644 --- a/templates/payment/index.html +++ b/templates/stripe_html/index.html @@ -1,15 +1,17 @@ +{% load static %} - + - - + + Good times + @@ -20,10 +22,10 @@
-
@@ -61,21 +63,21 @@
- + - +
- +
- +
@@ -90,13 +92,13 @@
- +
- +

Comprehensive Event Listings

@@ -107,7 +109,7 @@
- +

Personalized Recommendations

@@ -133,30 +135,30 @@

- +

Sign Up

Create your account using your email
or social media account.

- +
- +

Subscribe

Subscribe, pick your city, and share
your interests with us.

- +
- +

Start Exploring

Discover your city’s best experiences
and events.

- +
@@ -175,29 +177,29 @@
- +
Stay Informed
- +
Curated Recommendations
- +
Social Sharing
@@ -207,7 +209,7 @@
- +
@@ -347,16 +349,16 @@