diff --git a/FOSSDB/apps/account/__init__.py b/FOSSDB/apps/account/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/FOSSDB/apps/account/admin.py b/FOSSDB/apps/account/admin.py new file mode 100644 index 0000000..e69de29 diff --git a/FOSSDB/apps/account/apps.py b/FOSSDB/apps/account/apps.py new file mode 100644 index 0000000..2c684a9 --- /dev/null +++ b/FOSSDB/apps/account/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AccountConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "account" diff --git a/FOSSDB/apps/account/forms.py b/FOSSDB/apps/account/forms.py new file mode 100644 index 0000000..1b47e64 --- /dev/null +++ b/FOSSDB/apps/account/forms.py @@ -0,0 +1,11 @@ +from django import forms +from django.contrib.auth.forms import UserCreationForm +from django.contrib.auth.models import User + + +class RegisterForm(UserCreationForm): + email = forms.EmailField(required=True) + + class Meta: + model = User + fields = ["username", "email", "password1", "password2"] diff --git a/FOSSDB/apps/account/tests.py b/FOSSDB/apps/account/tests.py new file mode 100644 index 0000000..e69de29 diff --git a/FOSSDB/apps/account/urls.py b/FOSSDB/apps/account/urls.py new file mode 100644 index 0000000..8fa14e8 --- /dev/null +++ b/FOSSDB/apps/account/urls.py @@ -0,0 +1,9 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path("", views.sign_up, name="singup"), + path("signup", views.sign_up, name="signup"), + path("login", views.login_, name="login"), +] diff --git a/FOSSDB/apps/account/views.py b/FOSSDB/apps/account/views.py new file mode 100644 index 0000000..4bf3238 --- /dev/null +++ b/FOSSDB/apps/account/views.py @@ -0,0 +1,20 @@ +from django.contrib.auth import login +from django.shortcuts import redirect, render + +from .forms import RegisterForm + + +def sign_up(request): + if request.method == "POST": + form = RegisterForm(request.POST) + if form.is_valid(): + user = form.save() + login(request, user) + return redirect("") + else: + form = RegisterForm() + return render(request, "registration/sign_up.html", {"title": "Sign Up", "form": form}) + + +def login_(request): + return render(request, "registration/login.html", {"title": "Login"}) diff --git a/FOSSDB/apps/fossdb/models.py b/FOSSDB/apps/fossdb/models.py index d615307..4a2e73a 100644 --- a/FOSSDB/apps/fossdb/models.py +++ b/FOSSDB/apps/fossdb/models.py @@ -1,16 +1,18 @@ import uuid -from django.contrib.auth.models import User +from django.conf import settings from django.db import models from .license.models import License from .operating_system.models import OperatingSystemVersion from .tag.models import Tag +User = settings.AUTH_USER_MODEL + class Project(models.Model): uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, verbose_name="ID") - owner = models.ForeignKey(User, on_delete=models.CASCADE) + owner = models.ForeignKey(User, on_delete=models.CASCADE, db_index=True) name = models.CharField(max_length=255) description = models.TextField(blank=True, default="") license = models.ManyToManyField(License, blank=True) @@ -27,3 +29,8 @@ class Project(models.Model): def __str__(self): return f"{self.owner} | {self.name}" + + def save(self, *args, **kwargs): + if not self.uuid: + self.uuid = uuid.uuid3(uuid.uuid4(), f"{self.owner.username}-{self.name}") + super().save(*args, **kwargs) diff --git a/FOSSDB/settings.py b/FOSSDB/settings.py index c846f5e..8d9989d 100644 --- a/FOSSDB/settings.py +++ b/FOSSDB/settings.py @@ -35,6 +35,7 @@ DEBUG = config["DEBUG"] # Application definition INSTALLED_APPS = [ + "account", "fossdb", "django.contrib.admin", "django.contrib.auth", @@ -133,7 +134,6 @@ MEDIA_ROOT = BASE_PATH.joinpath("media") # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" -# LOGIN_URL = "login/" LOGIN_REDIRECT_URL = "/" LOGOUT_REDIRECT_URL = "/" diff --git a/FOSSDB/urls.py b/FOSSDB/urls.py index 1bb535d..6618184 100644 --- a/FOSSDB/urls.py +++ b/FOSSDB/urls.py @@ -20,6 +20,7 @@ from django.urls import include, path urlpatterns = [ path("", include("fossdb.urls")), + path("", include("account.urls")), path("admin/", admin.site.urls), path("", include("django.contrib.auth.urls")), ] diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 0000000..e1ca078 --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,13 @@ +{% extends "layout.html" %} +{% load static %} +{% block title %}{{ title }}{% endblock %} +{% block meta %}{% endblock %} +{% block content %} +
+ {% csrf_token %}{{ form }} +

+ Don't have an account? Create one Here! +

+ +
+{% endblock %} diff --git a/templates/registration/sign_up.html b/templates/registration/sign_up.html new file mode 100644 index 0000000..40b7bad --- /dev/null +++ b/templates/registration/sign_up.html @@ -0,0 +1,11 @@ +{% extends "layout.html" %} +{% block title %}Sign Up{% endblock %} +{% block content %} +
+ {% csrf_token %}{{ form }} +

+ Have an account? Login Here! +

+ +
+{% endblock %}