mirror of
https://github.com/kristoferssolo/FOSSDB.git
synced 2025-10-21 17:50:35 +00:00
parent
fa40a0acc8
commit
6398e844a6
0
FOSSDB/apps/account/__init__.py
Normal file
0
FOSSDB/apps/account/__init__.py
Normal file
0
FOSSDB/apps/account/admin.py
Normal file
0
FOSSDB/apps/account/admin.py
Normal file
6
FOSSDB/apps/account/apps.py
Normal file
6
FOSSDB/apps/account/apps.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class AccountConfig(AppConfig):
|
||||||
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
|
name = "account"
|
||||||
11
FOSSDB/apps/account/forms.py
Normal file
11
FOSSDB/apps/account/forms.py
Normal file
@ -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"]
|
||||||
0
FOSSDB/apps/account/tests.py
Normal file
0
FOSSDB/apps/account/tests.py
Normal file
9
FOSSDB/apps/account/urls.py
Normal file
9
FOSSDB/apps/account/urls.py
Normal file
@ -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"),
|
||||||
|
]
|
||||||
20
FOSSDB/apps/account/views.py
Normal file
20
FOSSDB/apps/account/views.py
Normal file
@ -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"})
|
||||||
@ -1,16 +1,18 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from .license.models import License
|
from .license.models import License
|
||||||
from .operating_system.models import OperatingSystemVersion
|
from .operating_system.models import OperatingSystemVersion
|
||||||
from .tag.models import Tag
|
from .tag.models import Tag
|
||||||
|
|
||||||
|
User = settings.AUTH_USER_MODEL
|
||||||
|
|
||||||
|
|
||||||
class Project(models.Model):
|
class Project(models.Model):
|
||||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, verbose_name="ID")
|
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)
|
name = models.CharField(max_length=255)
|
||||||
description = models.TextField(blank=True, default="")
|
description = models.TextField(blank=True, default="")
|
||||||
license = models.ManyToManyField(License, blank=True)
|
license = models.ManyToManyField(License, blank=True)
|
||||||
@ -27,3 +29,8 @@ class Project(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.owner} | {self.name}"
|
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)
|
||||||
|
|||||||
@ -35,6 +35,7 @@ DEBUG = config["DEBUG"]
|
|||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
|
"account",
|
||||||
"fossdb",
|
"fossdb",
|
||||||
"django.contrib.admin",
|
"django.contrib.admin",
|
||||||
"django.contrib.auth",
|
"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
|
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||||
# LOGIN_URL = "login/"
|
|
||||||
LOGIN_REDIRECT_URL = "/"
|
LOGIN_REDIRECT_URL = "/"
|
||||||
LOGOUT_REDIRECT_URL = "/"
|
LOGOUT_REDIRECT_URL = "/"
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,7 @@ from django.urls import include, path
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", include("fossdb.urls")),
|
path("", include("fossdb.urls")),
|
||||||
|
path("", include("account.urls")),
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
path("", include("django.contrib.auth.urls")),
|
path("", include("django.contrib.auth.urls")),
|
||||||
]
|
]
|
||||||
|
|||||||
13
templates/registration/login.html
Normal file
13
templates/registration/login.html
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{% extends "layout.html" %}
|
||||||
|
{% load static %}
|
||||||
|
{% block title %}{{ title }}{% endblock %}
|
||||||
|
{% block meta %}{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}{{ form }}
|
||||||
|
<p>
|
||||||
|
Don't have an account? Create one <a href="{% url 'signup' %}">Here</a>!
|
||||||
|
</p>
|
||||||
|
<button type="submit">Login</button>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
11
templates/registration/sign_up.html
Normal file
11
templates/registration/sign_up.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{% extends "layout.html" %}
|
||||||
|
{% block title %}Sign Up{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}{{ form }}
|
||||||
|
<p>
|
||||||
|
Have an account? Login <a href="{% url 'login' %}">Here</a>!
|
||||||
|
</p>
|
||||||
|
<button type="submit">Register</button>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
Loading…
Reference in New Issue
Block a user