Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Welcome, candidates! This project is a custom-built chatbot application that mim
- Deletion of conversations.
- Assistant message regeneration.
- User message editing.
- Model selection: currently GPT-3.5 or GPT-4.
- Model selection: currently GPT-3.5 or GPT-4. or Gemini
- Custom Django admin page for managing conversations, versions, and messages.

## Images
Expand Down
26 changes: 26 additions & 0 deletions backend/authentication/migrations/0002_role_customuser_role.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 5.2.4 on 2025-08-01 07:06

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('authentication', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Role',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
),
migrations.AddField(
model_name='customuser',
name='role',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='authentication.role'),
),
]
8 changes: 8 additions & 0 deletions backend/authentication/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin
from django.db import models

class Role(models.Model):
name = models.CharField(max_length=255)

def __str__(self):
return self.name


class CustomUserManager(BaseUserManager):
def create_user(self, email, password, **extra_fields):
Expand Down Expand Up @@ -31,6 +37,8 @@ def create_superuser(self, email, password, **extra_fields):

class CustomUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(unique=True)
role = models.ForeignKey(Role, null=True, blank=True, on_delete=models.SET_NULL)

is_active = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)

Expand Down
5 changes: 3 additions & 2 deletions backend/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ def register_view(request):
if CustomUser.objects.filter(email=email).exists():
return JsonResponse({"error": "Email is already taken"}, status=status.HTTP_400_BAD_REQUEST)

CustomUser.objects.create_user(email, password=password)
user = CustomUser.objects.create_user(email, password=password)
user.is_active = True # Set is_active to True
user.save()
return JsonResponse({"data": "User created successfully"}, status=status.HTTP_201_CREATED)


@api_view(["GET"])
def verify_session(request):
session_cookie = request.COOKIES.get("sessionid")
Expand Down
8 changes: 8 additions & 0 deletions backend/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from __future__ import absolute_import, unicode_literals
# Ensures compatibility between Python 2 and 3 for import behavior and string literals

from .celery import app as celery_app
# Imports the Celery app instance from celery.py and exposes it as celery_app

__all__ = ('celery_app',)
# Defines the public API of this module to include celery_app
14 changes: 14 additions & 0 deletions backend/backend/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
from celery import Celery

# Set default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')

# Create a new Celery app instance named 'backend'
app = Celery('backend')

# Load task modules from Django settings, using the CELERY namespace for config keys
app.config_from_object('django.conf:settings', namespace='CELERY')

# Automatically discover tasks.py in installed apps
app.autodiscover_tasks()
100 changes: 61 additions & 39 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
"""
Django settings for backend project.

Generated by 'django-admin startproject' using Django 4.2.5.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

import os
from pathlib import Path

from dotenv import load_dotenv

load_dotenv()
# Load .env file and override existing environment variables if any
load_dotenv(override=True)

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ["DJANGO_SECRET_KEY"]
FRONTEND_URL = os.environ["FRONTEND_URL"]
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
Expand All @@ -47,8 +32,25 @@
"authentication",
"chat",
"gpt",
"django_celery_beat",
]

# Celery Settings
CELERY_BROKER_URL = 'redis://localhost:6379/0'
CELERY_TASK_SERIALIZER = 'json'

# Database configuration - PostgreSQL
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'fullstackdb',
'USER': 'postgres',
'PASSWORD': 'students',
'HOST': 'localhost',
'PORT': '5432',
}
}

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
Expand Down Expand Up @@ -80,20 +82,7 @@

WSGI_APPLICATION = "backend.wsgi.application"


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}

# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
Expand All @@ -117,26 +106,19 @@
]

# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "Europe/Warsaw"
USE_TZ = True

USE_I18N = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_ROOT = BASE_DIR / "static"
STATIC_URL = "/static/"

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# CORS settings
CORS_ALLOWED_ORIGINS = [
FRONTEND_URL,
]
Expand All @@ -146,6 +128,46 @@
FRONTEND_URL,
]

# Security cookies
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
CSRF_COOKIE_SAMESITE = "None"

# DRF (Django REST Framework) settings
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
],
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
],
}

# Configure Logging
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
'file': {
'class': 'logging.FileHandler',
'filename': 'logs.log',
},
},
'loggers': {
'django': {
'handlers': ['console', 'file'],
'level': 'INFO',
},
},
}

# Configuring caching
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': 'redis://localhost:6379/1',
}
}
18 changes: 10 additions & 8 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
from django.urls import include, path
from rest_framework.decorators import api_view


# Simple root endpoint to verify the app is running
@api_view(["GET"])
def root_view(request):
return JsonResponse({"message": "App works!"})


urlpatterns = [
path("admin/", admin.site.urls),
path("chat/", include("chat.urls")),
path("gpt/", include("gpt.urls")),
path("auth/", include("authentication.urls")),
path("", root_view),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
path("admin/", admin.site.urls), # Admin site
path("chat/", include("chat.urls")), # Chat app URLs
path("gpt/", include("gpt.urls")), # GPT app URLs
path("auth/", include("authentication.urls")), # Authentication URLs
path("", root_view), # Root endpoint
]

# Serve static files during development
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Binary file added backend/basic_thermo.pdf
Binary file not shown.
Loading