diff --git a/account/views.py b/account/views.py index 7bc9ab5..95b4694 100644 --- a/account/views.py +++ b/account/views.py @@ -1,4 +1,6 @@ """Account view """ +from notifications.utils import remove_fcm_token + """Django import""" from datetime import datetime, timedelta from rest_framework import viewsets, status, views @@ -531,6 +533,10 @@ class LogoutAPIView(views.APIView): permission_classes = (IsAuthenticated,) def post(self, request): + remove_fcm_token( + request.auth.payload['user_id'], + request.META['HTTP_AUTHORIZATION'].split(" ")[1], + request.data.get('registration_id', "")) logout(request) request.session.flush() return custom_response(SUCCESS_CODE['3020'], response_status=status.HTTP_200_OK) diff --git a/notifications/utils.py b/notifications/utils.py index b3a0ede..d68756c 100644 --- a/notifications/utils.py +++ b/notifications/utils.py @@ -15,3 +15,13 @@ def register_fcm_token(user_id, registration_id, device_id, device_type): 'registration_id': registration_id}) return device + +def remove_fcm_token(user_id: int, access_token: str, registration_id) -> None: + """ + remove access_token and registration_token + """ + try: + # remove fcm token for this device + FCMDevice.objects.filter(user_id=user_id).delete() + except Exception as e: + print(e) diff --git a/web_admin/urls.py b/web_admin/urls.py index fa272f4..95bc7d9 100644 --- a/web_admin/urls.py +++ b/web_admin/urls.py @@ -11,7 +11,7 @@ from web_admin.views import ArticleViewSet # initiate router router = routers.SimpleRouter() -router.register('articles', ArticleViewSet, basename='articles') +router.register('article', ArticleViewSet, basename='article') urlpatterns = [ path('api/v1/', include(router.urls)), diff --git a/zod_bank/settings.py b/zod_bank/settings.py index 39ddbd2..8bbd82a 100644 --- a/zod_bank/settings.py +++ b/zod_bank/settings.py @@ -33,6 +33,10 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = os.getenv('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.getenv('DEBUG') + +# cors allow setting +CORS_ORIGIN_ALLOW_ALL = True + # allow all host ALLOWED_HOSTS = ['*'] @@ -185,8 +189,6 @@ USE_TZ = True # cors header settings SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') -# cors allow setting -CORS_ORIGIN_ALLOW_ALL = True # cors allow method CORS_ALLOW_METHODS = (