Skip to content

Commit

Permalink
Merge pull request #8 from Django-Projects-Ls/feature/auth
Browse files Browse the repository at this point in the history
Feature/auth
  • Loading branch information
LopesLs authored Dec 31, 2023
2 parents b3816d4 + 89325ed commit 2e82062
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 182 deletions.
10 changes: 10 additions & 0 deletions scheduleManagement/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User

class CustomUserCreationForm(UserCreationForm):
email = forms.EmailField(required=True)

class Meta:
model = User
fields = ("username", "email", "password1", "password2")
10 changes: 10 additions & 0 deletions scheduleManagement/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
{% block title %} <title>Home page</title> {% endblock %}
</head>
<body>
{% block navbar %}
<nav>
<ul>
<li><a href="">Schools Schedules</a></li>
<li><a href="">{{ user.username }}</a></li>
<li><a href="/logout">Logout</a></li>
</ul>
</nav>
{% endblock %}

{% block content%}
<a href="list-courses"><p>Courses</p></a>
<a href="list-disciplines"><p>Disciplines</p></a>
Expand Down
5 changes: 4 additions & 1 deletion scheduleManagement/templates/list-object.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ <h1>{{ object_type | title }} | List</h1>

{% for object in objects %}
<a href="{{ object.get_absolute_url }}"><p>{{ object }}</p></a>

{% empty %}
<p>No {{ object_type | title }} yet</p>
{% endfor %}

<button onclick="location.href = 'create'">Adicionar {{ object_type }}</button>
<a href="/">Back</a>
{% endblock %}
15 changes: 15 additions & 0 deletions scheduleManagement/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends 'home.html' %}

{% block navbar %} {% endblock %}

{% block title %} <title> Login Page </title> {% endblock %}

{% block content %}
<h1>Login Page</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<p> Don't have any account? Create one <a href="/sign-up">here</a>!</p>
<button type="submit">Login</button>
</form>
{% endblock %}
15 changes: 15 additions & 0 deletions scheduleManagement/templates/registration/sign_up.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends 'home.html' %}

{% block navbar %} {% endblock %}

{% block title %} <title> Sign Up Page </title> {% endblock %}

{% block content %}
<h1>Sign Up Page</h1>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<p> Have an account? Login <a href="/login">here</a>!</p>
<button type="submit">Register</button>
</form>
{% endblock %}
4 changes: 2 additions & 2 deletions scheduleManagement/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.urls import path
from . import views
from django.views.generic import TemplateView

urlpatterns = [
path("", TemplateView.as_view(template_name="home.html"), name="home"),
path("", views.HomeRequestHandler.as_view(), name="home"),
path("sign-up/", views.UserCreateRequestHandler.as_view(), name="sign_up"),
path(
"list-courses/", views.CourseListRequestHandler.as_view(), name="list_courses"
),
Expand Down
169 changes: 0 additions & 169 deletions scheduleManagement/views.py

This file was deleted.

3 changes: 3 additions & 0 deletions scheduleManagement/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from .home import HomeRequestHandler # noqa: F401

from .create import (
UserCreateRequestHandler, # noqa: F401
CourseCreateRequestHandler, # noqa: F401
DisciplineCreateRequestHandler, # noqa: F401
ScheduleCreateRequestHandler, # noqa: F401
Expand Down
23 changes: 19 additions & 4 deletions scheduleManagement/views/create.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic.edit import CreateView
from django.contrib.auth import login
from django.urls import reverse_lazy

from ..models import Curso, Disciplina, Horario
from ..forms import CustomUserCreationForm


class CourseCreateRequestHandler(CreateView):
class UserCreateRequestHandler(CreateView):
form_class = CustomUserCreationForm
template_name = "registration/sign_up.html"
success_url = reverse_lazy("login")

def form_valid(self, form):
user = form.save()
login(self.request, user)
return super().form_valid(form)


class CourseCreateRequestHandler(LoginRequiredMixin, CreateView):
model = Curso
fields = ["nome", "codigo", "disciplinas", "horario"]
template_name = "form.html"
success_url = reverse_lazy("list_courses")


class DisciplineCreateRequestHandler(CreateView):
class DisciplineCreateRequestHandler(LoginRequiredMixin, CreateView):
model = Disciplina
fields = ["nome", "codigo", "horario"]
template_name = "form.html"
success_url = reverse_lazy("list_disciplines")

class ScheduleCreateRequestHandler(CreateView):

class ScheduleCreateRequestHandler(LoginRequiredMixin,CreateView):
model = Horario
fields = ["dia", "hora_inicio", "hora_fim"]
template_name = "form.html"
success_url = reverse_lazy("list_schedules")
success_url = reverse_lazy("list_schedules")
7 changes: 4 additions & 3 deletions scheduleManagement/views/details.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import DetailView

from ..models import Curso, Disciplina, Horario
from ..extras import get_field_values


class CourseDetailsRequestHandler(DetailView):
class CourseDetailsRequestHandler(LoginRequiredMixin, DetailView):
model = Curso
template_name = "object-details.html"

Expand All @@ -15,7 +16,7 @@ def get_context_data(self, **kwargs):
return context


class DisciplineDetailsRequestHandler(DetailView):
class DisciplineDetailsRequestHandler(LoginRequiredMixin, DetailView):
model = Disciplina
template_name = "object-details.html"

Expand All @@ -26,7 +27,7 @@ def get_context_data(self, **kwargs):
return context


class ScheduleDetailsRequestHandler(DetailView):
class ScheduleDetailsRequestHandler(LoginRequiredMixin, DetailView):
model = Horario
template_name = "object-details.html"

Expand Down
6 changes: 6 additions & 0 deletions scheduleManagement/views/home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import TemplateView


class HomeRequestHandler(LoginRequiredMixin, TemplateView):
template_name = "home.html"
7 changes: 4 additions & 3 deletions scheduleManagement/views/list.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import ListView
from django.shortcuts import render

from ..models import Curso, Disciplina, Horario


class CourseListRequestHandler(ListView):
class CourseListRequestHandler(LoginRequiredMixin, ListView):
model = Curso

def get(self, request):
Expand All @@ -15,7 +16,7 @@ def get(self, request):
)


class DisciplineListRequestHandler(ListView):
class DisciplineListRequestHandler(LoginRequiredMixin, ListView):
model = Curso

def get(self, request):
Expand All @@ -26,7 +27,7 @@ def get(self, request):
)


class ScheduleListRequestHandler(ListView):
class ScheduleListRequestHandler(LoginRequiredMixin, ListView):
model = Horario

def get(self, request):
Expand Down
1 change: 1 addition & 0 deletions schoolschedules/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@

urlpatterns = [
path('', include('scheduleManagement.urls')),
path('', include('django.contrib.auth.urls')),
path('admin/', admin.site.urls),
]

0 comments on commit 2e82062

Please sign in to comment.