From 8110371a947d24621e5ac06cdff924ff25e657fd Mon Sep 17 00:00:00 2001 From: Alejandro Diaz Date: Mon, 11 Sep 2023 01:59:25 -0600 Subject: [PATCH] add login page --- ui/homemanager/settings.py | 4 ++++ ui/homemanager/urls.py | 4 +++- ui/main/templates/home.html | 13 +++++++++---- ui/main/urls.py | 7 +++++++ ui/main/views.py | 4 ++++ ui/templates/base.html | 16 ++++++---------- ui/templates/registration/login.html | 11 +++++++++++ 7 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 ui/main/urls.py create mode 100644 ui/templates/registration/login.html diff --git a/ui/homemanager/settings.py b/ui/homemanager/settings.py index b1aca9c..be0edb0 100644 --- a/ui/homemanager/settings.py +++ b/ui/homemanager/settings.py @@ -37,6 +37,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'main' ] MIDDLEWARE = [ @@ -121,3 +122,6 @@ STATIC_URL = 'static/' # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +LOGIN_REDIRECT_URL = "/" +LOGOUT_REDIRECT_URL = "/accounts/login" diff --git a/ui/homemanager/urls.py b/ui/homemanager/urls.py index 486e012..13a4200 100644 --- a/ui/homemanager/urls.py +++ b/ui/homemanager/urls.py @@ -15,8 +15,10 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), + path('', include('main.urls')), + path("accounts/", include("django.contrib.auth.urls")), ] diff --git a/ui/main/templates/home.html b/ui/main/templates/home.html index 848f875..308a126 100644 --- a/ui/main/templates/home.html +++ b/ui/main/templates/home.html @@ -1,8 +1,13 @@ {% extends "base.html" %} -{% block title %} Scholar Clubs {% endblock title%} +{% block title %} Home Manager {% endblock title%} {% block content %} -
-

Welcome

-
+ {% if user.is_authenticated %} +
+

Welcome {{ user.username }}

+
+ {% else %} +

You are not logged in

+ Log In + {% endif %} {% endblock content %} \ No newline at end of file diff --git a/ui/main/urls.py b/ui/main/urls.py new file mode 100644 index 0000000..3d14910 --- /dev/null +++ b/ui/main/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from .views import home + +urlpatterns = [ + path('', home, name='home'), +] diff --git a/ui/main/views.py b/ui/main/views.py index 91ea44a..81ecc7d 100644 --- a/ui/main/views.py +++ b/ui/main/views.py @@ -1,3 +1,7 @@ from django.shortcuts import render # Create your views here. + +def home(request): + return render(request, 'home.html') + diff --git a/ui/templates/base.html b/ui/templates/base.html index c06b3c2..9a04e81 100644 --- a/ui/templates/base.html +++ b/ui/templates/base.html @@ -20,16 +20,12 @@
{% if messages %} diff --git a/ui/templates/registration/login.html b/ui/templates/registration/login.html new file mode 100644 index 0000000..058b209 --- /dev/null +++ b/ui/templates/registration/login.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% block title %} Home Manager {% endblock title%} +{% block content %} +
+
+ {% csrf_token %} + {{ form.as_p }} + +
+
+{% endblock content %} \ No newline at end of file