refactor: Refactor djeveric code
This commit is contained in:
parent
aa7ebb3f0a
commit
ab1981f1bc
7 changed files with 131 additions and 81 deletions
|
@ -1,8 +1,11 @@
|
|||
from djeveric import Confirmation
|
||||
from userausfall.emails import ConfidantConfirmationEmail
|
||||
from userausfall.models import User
|
||||
|
||||
|
||||
class ConfidantConfirmation(Confirmation):
|
||||
email_class = ConfidantConfirmationEmail
|
||||
|
||||
def has_permission(self, user: User, resource: User):
|
||||
return user == resource.confidant_unconfirmed
|
||||
|
8
userausfall/emails.py
Normal file
8
userausfall/emails.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from djeveric import Email
|
||||
|
||||
|
||||
class ConfidantConfirmationEmail(Email):
|
||||
subject = "TODO"
|
||||
|
||||
def get_message(self, context):
|
||||
return '"token": "{token}", "uid": "{uid}", "rtid": "{rtid}", "rid": "{rid}"'.format(**context)
|
|
@ -1,14 +1,13 @@
|
|||
from django.urls import path
|
||||
from rest_framework import routers
|
||||
|
||||
from djeveric.rest_api import ConfirmationView
|
||||
from userausfall.rest_api.views import UserViewSet
|
||||
from userausfall.rest_api.views import UserViewSet, ConfidantConfirmationView
|
||||
|
||||
router = routers.DefaultRouter(trailing_slash=True)
|
||||
router.register(r'users', UserViewSet, basename="user")
|
||||
|
||||
urlpatterns = [
|
||||
path("confirm", ConfirmationView.as_view())
|
||||
path("confirm/confidant/", ConfidantConfirmationView.as_view())
|
||||
]
|
||||
|
||||
urlpatterns += router.urls
|
||||
|
|
|
@ -2,10 +2,16 @@ from rest_framework import viewsets, status
|
|||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
|
||||
from djeveric import ConfirmationView
|
||||
from userausfall.models import User, MissingUserAttribute, PasswordMismatch
|
||||
from userausfall.confirmations import ConfidantConfirmation
|
||||
from userausfall.rest_api.serializers import UserSerializer, UserActivationSerializer
|
||||
|
||||
|
||||
class ConfidantConfirmationView(ConfirmationView):
|
||||
confirmation_class = ConfidantConfirmation
|
||||
|
||||
|
||||
class UserViewSet(viewsets.ModelViewSet):
|
||||
queryset = User.objects.all()
|
||||
serializer_class = UserSerializer
|
||||
|
|
|
@ -2,7 +2,7 @@ from django.db.models.signals import post_save
|
|||
from django.dispatch import receiver
|
||||
|
||||
from userausfall.models import User
|
||||
from userausfall.rest_api.confirmations import ConfidantConfirmation
|
||||
from userausfall.confirmations import ConfidantConfirmation
|
||||
|
||||
|
||||
@receiver(post_save, sender=User)
|
||||
|
|
Reference in a new issue