diff --git a/server/balancer_backend/views/listMeds/urls.py b/server/api/__init__.py similarity index 100% rename from server/balancer_backend/views/listMeds/urls.py rename to server/api/__init__.py diff --git a/server/api/admin.py b/server/api/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/server/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/server/api/apps.py b/server/api/apps.py new file mode 100644 index 00000000..66656fd2 --- /dev/null +++ b/server/api/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'api' diff --git a/server/balancer_backend/views/listMeds/views.py b/server/api/migrations/__init__.py similarity index 100% rename from server/balancer_backend/views/listMeds/views.py rename to server/api/migrations/__init__.py diff --git a/server/api/models.py b/server/api/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/server/api/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/server/api/tests.py b/server/api/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/server/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/server/balancer_backend/views/chatgpt/urls.py b/server/api/views/chatgpt/urls.py similarity index 83% rename from server/balancer_backend/views/chatgpt/urls.py rename to server/api/views/chatgpt/urls.py index 6a2d2e4c..8aba0c7b 100644 --- a/server/balancer_backend/views/chatgpt/urls.py +++ b/server/api/views/chatgpt/urls.py @@ -1,5 +1,5 @@ from django.urls import path -from balancer_backend.views.chatgpt import views +from api.views.chatgpt import views urlpatterns = [ path("chatgpt/extract_text/", views.extract_text, name="post_web_text"), diff --git a/server/balancer_backend/views/chatgpt/views.py b/server/api/views/chatgpt/views.py similarity index 100% rename from server/balancer_backend/views/chatgpt/views.py rename to server/api/views/chatgpt/views.py diff --git a/server/balancer_backend/views/jira/urls.py b/server/api/views/jira/urls.py similarity index 89% rename from server/balancer_backend/views/jira/urls.py rename to server/api/views/jira/urls.py index cbb49de7..068b50e2 100644 --- a/server/balancer_backend/views/jira/urls.py +++ b/server/api/views/jira/urls.py @@ -1,5 +1,5 @@ from django.urls import path -from balancer_backend.views.jira import views +from api.views.jira import views urlpatterns = [ path("jira/create_new_feedback/", views.create_new_feedback, name="create_new_feedback"), diff --git a/server/balancer_backend/views/jira/views.py b/server/api/views/jira/views.py similarity index 100% rename from server/balancer_backend/views/jira/views.py rename to server/api/views/jira/views.py diff --git a/server/balancer_backend/views/listDrugs/urls.py b/server/api/views/listDrugs/urls.py similarity index 69% rename from server/balancer_backend/views/listDrugs/urls.py rename to server/api/views/listDrugs/urls.py index 7f29aab8..593c276b 100644 --- a/server/balancer_backend/views/listDrugs/urls.py +++ b/server/api/views/listDrugs/urls.py @@ -1,5 +1,5 @@ from django.urls import path -from balancer_backend.views.listDrugs import views +from api.views.listDrugs import views urlpatterns = [ path("chatgpt/list_drugs", views.medication, name="listDrugs") diff --git a/server/balancer_backend/views/listDrugs/views.py b/server/api/views/listDrugs/views.py similarity index 100% rename from server/balancer_backend/views/listDrugs/views.py rename to server/api/views/listDrugs/views.py diff --git a/server/api/views/listMeds/urls.py b/server/api/views/listMeds/urls.py new file mode 100644 index 00000000..e69de29b diff --git a/server/api/views/listMeds/views.py b/server/api/views/listMeds/views.py new file mode 100644 index 00000000..e69de29b diff --git a/server/balancer_backend/views/risk/urls.py b/server/api/views/risk/urls.py similarity index 69% rename from server/balancer_backend/views/risk/urls.py rename to server/api/views/risk/urls.py index 8d16e94e..30e53424 100644 --- a/server/balancer_backend/views/risk/urls.py +++ b/server/api/views/risk/urls.py @@ -1,5 +1,5 @@ from django.urls import path -from balancer_backend.views.risk import views +from api.views.risk import views urlpatterns = [ path("chatgpt/risk", views.medication, name="risk") diff --git a/server/balancer_backend/views/risk/views.py b/server/api/views/risk/views.py similarity index 100% rename from server/balancer_backend/views/risk/views.py rename to server/api/views/risk/views.py diff --git a/server/balancer_backend/models/users/RegistrationProfile.py b/server/balancer_backend/models/users/RegistrationProfile.py deleted file mode 100644 index 1fff39e0..00000000 --- a/server/balancer_backend/models/users/RegistrationProfile.py +++ /dev/null @@ -1,18 +0,0 @@ -from django.db import models -from django.contrib.auth.models import User - -class RegistrationProfile(models.Model): - user = models.OneToOneField(User, on_delete=models.CASCADE) - activation_key = models.CharField(max_length=40) - - def save(self, *args, **kwargs): - # Generate a unique activation key when saving the model - if not self.activation_key: - self.activation_key = self.generate_activation_key() - super(RegistrationProfile, self).save(*args, **kwargs) - - def generate_activation_key(self): - # Implement a function to generate a unique activation key (you may use a library like uuid) - # This is a simple example, you may want to customize this based on your requirements - import uuid - return str(uuid.uuid4()) diff --git a/server/balancer_backend/settings.py b/server/balancer_backend/settings.py index cab9e3e8..45d3e3f8 100644 --- a/server/balancer_backend/settings.py +++ b/server/balancer_backend/settings.py @@ -39,7 +39,9 @@ 'django.contrib.messages', 'django.contrib.staticfiles', 'registration', - 'balancer_backend' + 'balancer_backend', + 'user_management', + 'api' ] MIDDLEWARE = [ diff --git a/server/balancer_backend/urls.py b/server/balancer_backend/urls.py index d6351be5..10d7553d 100644 --- a/server/balancer_backend/urls.py +++ b/server/balancer_backend/urls.py @@ -1,13 +1,15 @@ from django.contrib import admin +from user_management import urls as user_management_urls from django.urls import path, include import importlib -subfolders = ['auth', 'chatgpt', 'jira', 'listDrugs', 'listMeds', 'risk'] +urls = ['chatgpt', 'jira', 'listDrugs', 'listMeds', 'risk'] urlpatterns = [ path("admin/", admin.site.urls), + path("api/", include(user_management_urls)), ] -for subfolder in subfolders: - url_module = importlib.import_module(f'balancer_backend.views.{subfolder}.urls') - urlpatterns += getattr(url_module, 'urlpatterns', []) \ No newline at end of file +for url in urls: + url_module = importlib.import_module(f'api.views.{url}.urls') + urlpatterns += getattr(url_module, 'urlpatterns', []) diff --git a/server/user_management/__init__.py b/server/user_management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/server/user_management/admin.py b/server/user_management/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/server/user_management/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/server/user_management/apps.py b/server/user_management/apps.py new file mode 100644 index 00000000..85c9c8e3 --- /dev/null +++ b/server/user_management/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UserManagementConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'user_management' diff --git a/server/user_management/migrations/__init__.py b/server/user_management/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/server/user_management/models.py b/server/user_management/models.py new file mode 100644 index 00000000..77a5143a --- /dev/null +++ b/server/user_management/models.py @@ -0,0 +1,16 @@ +from django.db import models +from registration.models import RegistrationProfile as BaseRegistrationProfile + +class RegistrationProfile(BaseRegistrationProfile): + email = models.EmailField(unique=True) + password = models.CharField(max_length=40) + # Other fields relevant for user registration and email verification + + def save(self, *args, **kwargs): + if not self.activation_key: + self.activation_key = self.generate_activation_key() + super(RegistrationProfile, self).save(*args, **kwargs) + + def generate_activation_key(self): + import uuid + return str(uuid.uuid4()) \ No newline at end of file diff --git a/server/balancer_backend/templates/email/verification_email.html b/server/user_management/templates/email/verification_email.html similarity index 100% rename from server/balancer_backend/templates/email/verification_email.html rename to server/user_management/templates/email/verification_email.html diff --git a/server/user_management/tests.py b/server/user_management/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/server/user_management/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/server/balancer_backend/views/auth/urls.py b/server/user_management/urls.py similarity index 82% rename from server/balancer_backend/views/auth/urls.py rename to server/user_management/urls.py index 64f1245b..b5001cb1 100644 --- a/server/balancer_backend/views/auth/urls.py +++ b/server/user_management/urls.py @@ -1,5 +1,5 @@ from django.urls import path -from balancer_backend.views.auth import views +from user_management import views urlpatterns = [ path("auth/register_user/", views.register_user, name="register_user"), diff --git a/server/balancer_backend/views/auth/views.py b/server/user_management/views.py similarity index 79% rename from server/balancer_backend/views/auth/views.py rename to server/user_management/views.py index cfb62560..82d1d35f 100644 --- a/server/balancer_backend/views/auth/views.py +++ b/server/user_management/views.py @@ -4,7 +4,8 @@ from rest_framework import status from rest_framework.decorators import api_view from django.http import JsonResponse -from balancer_backend.models.users import RegistrationProfile +from django.contrib.auth.models import User +from .models import RegistrationProfile import requests import json import os @@ -31,14 +32,17 @@ def register_user(request: str) -> JsonResponse: if not email or not password: return JsonResponse({"error": "Email and password are required."}) - if RegistrationProfile.objects.filter(user__email=email).exists(): - return JsonResponse({"error": "Email is already registred."}) + if User.objects.filter(email=email).exists(): + return JsonResponse({"error": "Email is already registered."}) user = User.objects.create_user(email, email, password) user.is_active = False user.save() - send_verification_email(user) + # Create the RegistrationProfile for the user + registration_profile = RegistrationProfile.objects.create(user=user) + + send_verification_email(user) # Make sure this function sends the verification email return JsonResponse({"message": "Registration successful. Check your email for verification."})