0.12.50 subscribe page w dynamically load
This commit is contained in:
@@ -59,12 +59,13 @@ def get_profile_subscribe_page_content_html(request):
|
||||
|
||||
subscribe_for_user = None
|
||||
|
||||
orders = None
|
||||
if request.user and request.user.is_authenticated:
|
||||
from BillingApp.funcs import get_orders_for_user, get_order_status
|
||||
orders = get_orders_for_user(request.user)
|
||||
for order in orders:
|
||||
res = get_order_status(order)
|
||||
subscribe_for_user = check_n_enable_subscribe_by_order(order)
|
||||
# for order in orders:
|
||||
# res = get_order_status(order)
|
||||
# subscribe_for_user = check_n_enable_subscribe_by_order(order)
|
||||
|
||||
if not subscribe_for_user:
|
||||
subscribe_for_user = SubscribeForUser.objects.filter(user=request.user)
|
||||
@@ -84,7 +85,8 @@ def get_profile_subscribe_page_content_html(request):
|
||||
|
||||
Dict = {
|
||||
'subscribe_for_user': subscribe_for_user,
|
||||
'subscribes': subscribes
|
||||
'subscribes': subscribes,
|
||||
'active_orders': orders,
|
||||
}
|
||||
|
||||
html = render_to_string(tpl_name, Dict, request=request)
|
||||
|
||||
@@ -34,35 +34,43 @@ const showNotAllowed = (message) => {
|
||||
|
||||
// urlB64ToUint8Array is a magic function that will encode the base64 public key
|
||||
// to Array buffer which is needed by the subscription option
|
||||
function urlB64ToUint8Array2(base64String) {
|
||||
const padding = '='.repeat((4 - (base64String.length % 4)) % 4)
|
||||
const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/')
|
||||
const rawData = atob(base64)
|
||||
const outputArray = new Uint8Array(rawData.length)
|
||||
for (let i = 0; i < rawData.length; ++i) {
|
||||
outputArray[i] = rawData.charCodeAt(i)
|
||||
}
|
||||
return outputArray
|
||||
}
|
||||
// function urlB64ToUint8Array2(base64String) {
|
||||
// const padding = '='.repeat((4 - (base64String.length % 4)) % 4)
|
||||
// const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/')
|
||||
// const rawData = atob(base64)
|
||||
// const outputArray = new Uint8Array(rawData.length)
|
||||
// for (let i = 0; i < rawData.length; ++i) {
|
||||
// outputArray[i] = rawData.charCodeAt(i)
|
||||
// }
|
||||
// return outputArray
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function urlB64ToUint8Array(base64String) {
|
||||
function urlBase64ToUint8Array(base64String) {
|
||||
const padding = '='.repeat((4 - base64String.length % 4) % 4);
|
||||
const base64 = (base64String + padding)
|
||||
.replace(/\-/g, '+')
|
||||
.replace(/_/g, '/');
|
||||
|
||||
.replace(/_/g, '/')
|
||||
;
|
||||
const rawData = window.atob(base64);
|
||||
const outputArray = new Uint8Array(rawData.length);
|
||||
const outputData = outputArray.map((output, index) => rawData.charCodeAt(index));
|
||||
|
||||
return outputData;
|
||||
return Uint8Array.from([...rawData].map((char) => char.charCodeAt(0)));
|
||||
}
|
||||
|
||||
|
||||
// function urlB64ToUint8Array(base64String) {
|
||||
// const padding = '='.repeat((4 - base64String.length % 4) % 4);
|
||||
// const base64 = (base64String + padding)
|
||||
// .replace(/\-/g, '+')
|
||||
// .replace(/_/g, '/');
|
||||
//
|
||||
// const rawData = window.atob(base64);
|
||||
// const outputArray = new Uint8Array(rawData.length);
|
||||
// const outputData = outputArray.map((output, index) => rawData.charCodeAt(index));
|
||||
//
|
||||
// return outputData;
|
||||
// }
|
||||
|
||||
const subscribe = async (reg) => {
|
||||
const subscription = await reg.pushManager.getSubscription();
|
||||
if (subscription) {
|
||||
@@ -75,7 +83,7 @@ const subscribe = async (reg) => {
|
||||
const options = {
|
||||
userVisibleOnly: true,
|
||||
// if key exists, create applicationServerKey property
|
||||
...(key && {applicationServerKey: urlB64ToUint8Array2(key)})
|
||||
...(key && {applicationServerKey: urlBase64ToUint8Array(key)})
|
||||
};
|
||||
|
||||
const sub = await reg.pushManager.subscribe(options);
|
||||
|
||||
Reference in New Issue
Block a user