Skip to content

Commit

Permalink
Merge pull request #53 from CodeForPhilly/basic_auth
Browse files Browse the repository at this point in the history
Basic auth
  • Loading branch information
ryanrrogers authored Nov 14, 2023
2 parents 5475f4d + 2158d24 commit 7beda93
Show file tree
Hide file tree
Showing 28 changed files with 65 additions and 32 deletions.
File renamed without changes.
3 changes: 3 additions & 0 deletions server/api/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions server/api/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api'
File renamed without changes.
3 changes: 3 additions & 0 deletions server/api/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions server/api/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
File renamed without changes.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
File renamed without changes.
18 changes: 0 additions & 18 deletions server/balancer_backend/models/users/RegistrationProfile.py

This file was deleted.

4 changes: 3 additions & 1 deletion server/balancer_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'registration',
'balancer_backend'
'balancer_backend',
'user_management',
'api'
]

MIDDLEWARE = [
Expand Down
10 changes: 6 additions & 4 deletions server/balancer_backend/urls.py
Original file line number Diff line number Diff line change
@@ -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', [])
for url in urls:
url_module = importlib.import_module(f'api.views.{url}.urls')
urlpatterns += getattr(url_module, 'urlpatterns', [])
Empty file.
3 changes: 3 additions & 0 deletions server/user_management/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions server/user_management/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class UserManagementConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'user_management'
Empty file.
16 changes: 16 additions & 0 deletions server/user_management/models.py
Original file line number Diff line number Diff line change
@@ -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())
3 changes: 3 additions & 0 deletions server/user_management/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."})

Expand Down

0 comments on commit 7beda93

Please sign in to comment.