mirror of
https://github.com/kristoferssolo/FOSSDB.git
synced 2025-10-21 17:50:35 +00:00
commit
18a09e2eb2
0
FOSSDB_web/apps/account/__init__.py
Normal file
0
FOSSDB_web/apps/account/__init__.py
Normal file
0
FOSSDB_web/apps/account/admin.py
Normal file
0
FOSSDB_web/apps/account/admin.py
Normal file
6
FOSSDB_web/apps/account/apps.py
Normal file
6
FOSSDB_web/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_web/apps/account/forms.py
Normal file
11
FOSSDB_web/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_web/apps/account/tests.py
Normal file
0
FOSSDB_web/apps/account/tests.py
Normal file
9
FOSSDB_web/apps/account/urls.py
Normal file
9
FOSSDB_web/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_web/apps/account/views.py
Normal file
20
FOSSDB_web/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"})
|
||||
@ -10,16 +10,16 @@ def index(request):
|
||||
return render(request, "fossdb/index.html", {"title": "FOSSDB", "projects": projects})
|
||||
|
||||
|
||||
@login_required(login_url="account/login/")
|
||||
@permission_required("fossdb.add_post)", login_url="account/login/", raise_exception=True)
|
||||
@login_required(login_url="login/")
|
||||
@permission_required("fossdb.add_post)", login_url="login/", raise_exception=True)
|
||||
def add_project(request):
|
||||
if request.method == "POST":
|
||||
project = ProjectForm(request.POST)
|
||||
if project.is_valid():
|
||||
post = project.save(commit=False)
|
||||
form = ProjectForm(request.POST)
|
||||
if form.is_valid():
|
||||
post = form.save(commit=False)
|
||||
post.author = request.user
|
||||
post.save()
|
||||
return redirect("")
|
||||
return redirect("/")
|
||||
else:
|
||||
project = ProjectForm()
|
||||
return render(request, "main/create_project.html", {"title": "Add project", "form": project})
|
||||
form = ProjectForm()
|
||||
return render(request, "fossdb/add_project.html", {"title": "Add project", "form": form})
|
||||
|
||||
@ -24,7 +24,6 @@ DEBUG = BASE_PATH.joinpath("debug").is_file()
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
||||
|
||||
with open(BASE_PATH.joinpath("config.json"), "r", encoding="UTF-8") as config_file:
|
||||
config = json.load(config_file)
|
||||
|
||||
@ -38,6 +37,7 @@ ALLOWED_HOSTS = config["ALLOWED_HOSTS"]
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"fossdb",
|
||||
"account",
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
@ -116,7 +116,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
|
||||
LANGUAGE_CODE = "en-us"
|
||||
|
||||
TIME_ZONE = "Europe/Riga"
|
||||
TIME_ZONE = "UTC"
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
@ -134,3 +134,5 @@ 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_REDIRECT_URL = "/"
|
||||
LOGOUT_REDIRECT_URL = "/"
|
||||
|
||||
@ -20,8 +20,9 @@ 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")),
|
||||
]
|
||||
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
|
||||
10
templates/fossdb/add_project.html
Normal file
10
templates/fossdb/add_project.html
Normal file
@ -0,0 +1,10 @@
|
||||
{% extends "layout.html" %}
|
||||
{% load static %}
|
||||
{% block title %}{{ title }}{% endblock %}
|
||||
{% block meta %}{% endblock %}
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{% csrf_token %}{{ form }}
|
||||
<button type="submit">Post</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
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