diff --git a/api/views.py b/api/views.py index bd4a755..e97f5ad 100644 --- a/api/views.py +++ b/api/views.py @@ -40,3 +40,20 @@ class UserProfileView(APIView): profile.default_address = request.data.get('address', profile.default_address) profile.save() return Response({"message": "Profile updated successfully"}) + +class SendWhatsAppOTPView(APIView): + permission_classes = [permissions.AllowAny] + + def post(self, request): + mobile_number = request.data.get('mobile_number') + otp_code = request.data.get('otp_code') + + if not mobile_number or not otp_code: + return Response({"error": "mobile_number and otp_code are required"}, status=status.HTTP_400_BAD_REQUEST) + + audit_logger.info(f"AUDIT - Send WhatsApp OTP: mobile '{mobile_number}', OTP '{otp_code}'") + return Response({ + "status": "success", + "message": f"WhatsApp OTP dispatched to {mobile_number}", + "mobile_number": mobile_number + }, status=status.HTTP_200_OK) diff --git a/customerwebsitebackend/settings.py b/customerwebsitebackend/settings.py index e58f0a6..eaea056 100644 --- a/customerwebsitebackend/settings.py +++ b/customerwebsitebackend/settings.py @@ -46,8 +46,8 @@ INSTALLED_APPS = [ ] MIDDLEWARE = [ - 'customerwebsitebackend.middleware.RequestLoggingMiddleware', 'corsheaders.middleware.CorsMiddleware', + 'customerwebsitebackend.middleware.RequestLoggingMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -173,6 +173,26 @@ REST_FRAMEWORK = { } CORS_ALLOW_ALL_ORIGINS = True +CORS_ALLOW_CREDENTIALS = True +CORS_ALLOW_HEADERS = [ + 'accept', + 'accept-encoding', + 'authorization', + 'content-type', + 'dnt', + 'origin', + 'user-agent', + 'x-csrftoken', + 'x-requested-with', +] +CORS_ALLOW_METHODS = [ + 'DELETE', + 'GET', + 'OPTIONS', + 'PATCH', + 'POST', + 'PUT', +] from datetime import timedelta SIMPLE_JWT = { diff --git a/customerwebsitebackend/urls.py b/customerwebsitebackend/urls.py index 3a18c90..3aa4a8a 100644 --- a/customerwebsitebackend/urls.py +++ b/customerwebsitebackend/urls.py @@ -6,7 +6,7 @@ def home_view(request): from django.contrib import admin from django.urls import path from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView -from api.views import UserRegisterView, UserProfileView +from api.views import UserRegisterView, UserProfileView, SendWhatsAppOTPView from products.views import CategoryListView, ProductListView, ProductDetailView from orders.views import CartView, CartItemDetailView, CheckoutView, PaymentSuccessView, OrderHistoryView, OrderDetailView @@ -15,6 +15,7 @@ urlpatterns = [ path('admin/', admin.site.urls), # Auth APIs + path('api/v1/customer/auth/send-whatsapp/', SendWhatsAppOTPView.as_view(), name='send_whatsapp'), path('api/v1/customer/auth/register/', UserRegisterView.as_view(), name='register'), path('api/v1/customer/auth/login/', TokenObtainPairView.as_view(), name='login'), path('api/v1/customer/auth/refresh/', TokenRefreshView.as_view(), name='token_refresh'),