added in this stuff https://git.startinblox.com/djangoldp-packages/djangoldp-notification/merge_requests/43#note_59310
This commit is contained in:
parent
a4f4a1daa2
commit
9d19e0e73c
24
admin.py
Normal file
24
admin.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from djangoldp.admin import DjangoLDPAdmin
|
||||||
|
from djangoldp.models import Model
|
||||||
|
from .models import Notification, NotificationSetting, Subscription, VAPIDKeyset
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class NotificationSettingAdmin(DjangoLDPAdmin):
|
||||||
|
ordering = ['urlid']
|
||||||
|
|
||||||
|
|
||||||
|
class VAPIDKeysetAdmin(DjangoLDPAdmin):
|
||||||
|
readonly_fields = ('public_key_view', 'private_key_view')
|
||||||
|
|
||||||
|
def public_key_view(self, obj):
|
||||||
|
return obj.public_key.tobytes()
|
||||||
|
|
||||||
|
def private_key_view(self, obj):
|
||||||
|
return obj.private_key.tobytes()
|
||||||
|
|
||||||
|
admin.site.register(Notification, NotificationAdmin)
|
||||||
|
admin.site.register(Subscription, SubscriptionAdmin)
|
||||||
|
admin.site.register(NotificationSetting, NotificationSettingAdmin)
|
||||||
|
admin.site.register(VAPIDKeyset, VAPIDKeysetAdmin)
|
23
management/commands/gen_vapid_keys.py
Normal file
23
management/commands/gen_vapid_keys.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import ecdsa
|
||||||
|
from ecdsa import SigningKey
|
||||||
|
from base64 import urlsafe_b64encode
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from djangoldp_notification.models import VAPIDKeyset
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = "Generate VAPID key pair"
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
priv_key = SigningKey.generate(curve=ecdsa.NIST256p)
|
||||||
|
pub_key = priv_key.get_verifying_key()
|
||||||
|
|
||||||
|
VAPIDKeyset.objects.create(
|
||||||
|
public_key=urlsafe_b64encode(b"\x04" + pub_key.to_string()).strip(b"="),
|
||||||
|
private_key=urlsafe_b64encode(priv_key.to_string()).strip(b"=")
|
||||||
|
)
|
||||||
|
|
||||||
|
self.stdout.write("VAPID Keyset succesfully generated")
|
||||||
|
|
||||||
|
exit(0)
|
19
migrations/0012_vapidkeyset.py
Normal file
19
migrations/0012_vapidkeyset.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('djangoldp_notification', '0011_auto_20210218_1145'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='VAPIDKeyset',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('public_key', models.BinaryField(max_length=87)),
|
||||||
|
('private_key', models.BinaryField(max_length=43)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
17
models.py
Normal file
17
models.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
def send_request(target, object_iri, instance, created):
|
||||||
|
}
|
||||||
|
ActivityQueueService.send_activity(target, json)
|
||||||
|
|
||||||
|
class VAPIDKeyset(models.Model):
|
||||||
|
public_key = models.BinaryField(max_length=87)
|
||||||
|
private_key = models.BinaryField(max_length=43)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "public_key:{}... private_key:{}...".format(
|
||||||
|
self.public_key.tobytes()[:10],
|
||||||
|
self.private_key.tobytes()[:10]
|
||||||
|
)
|
||||||
|
|
||||||
|
@receiver(post_save, sender=Notification)
|
||||||
|
def send_email_on_notification(sender, instance, created, **kwargs):
|
||||||
|
if created and instance.summary and getattr(settings,'JABBER_DEFAULT_HOST',False) and instance.user.email:
|
@ -10,9 +10,12 @@ license = MIT
|
|||||||
[options]
|
[options]
|
||||||
packages = find:
|
packages = find:
|
||||||
install_requires =
|
install_requires =
|
||||||
djangoldp~=0.5
|
djangoldp~=2.1.0
|
||||||
|
djangoldp_account~=2.1
|
||||||
|
ecdsa~=0.16.1
|
||||||
|
|
||||||
[options.extras_require]
|
[options.extras_require]
|
||||||
|
include_package_data = True
|
||||||
dev =
|
dev =
|
||||||
factory_boy>=2.11.0
|
factory_boy>=2.11.0
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user