From 4b07a89adf87e45b4a2a5d795d8f9770728b4a53 Mon Sep 17 00:00:00 2001 From: AlphaDarkmoon Date: Sun, 3 Sep 2023 09:51:57 +0530 Subject: [PATCH 1/2] added Login & Register form --- blog/models.py | 3 +- blog/urls.py | 2 + mysite/settings.py | 6 +++ mysite/urls.py | 4 ++ templates/base.html | 35 ++++++++++++---- templates/registration/login.html | 22 ++++++++++ templates/signup.html | 22 ++++++++++ users/__init__.py | 0 users/admin.py | 40 ++++++++++++++++++ users/apps.py | 6 +++ users/forms.py | 36 ++++++++++++++++ users/managers.py | 42 +++++++++++++++++++ users/migrations/0001_initial.py | 38 +++++++++++++++++ users/migrations/0002_customuser_country.py | 18 ++++++++ ...dress_alter_customuser_country_and_more.py | 38 +++++++++++++++++ users/migrations/0004_auto_20230903_0341.py | 25 +++++++++++ users/migrations/__init__.py | 0 users/models.py | 27 ++++++++++++ users/tests.py | 42 +++++++++++++++++++ users/urls.py | 15 +++++++ users/views.py | 24 +++++++++++ 21 files changed, 436 insertions(+), 9 deletions(-) create mode 100755 templates/registration/login.html create mode 100755 templates/signup.html create mode 100644 users/__init__.py create mode 100644 users/admin.py create mode 100644 users/apps.py create mode 100644 users/forms.py create mode 100644 users/managers.py create mode 100644 users/migrations/0001_initial.py create mode 100644 users/migrations/0002_customuser_country.py create mode 100644 users/migrations/0003_alter_customuser_address_alter_customuser_country_and_more.py create mode 100644 users/migrations/0004_auto_20230903_0341.py create mode 100644 users/migrations/__init__.py create mode 100644 users/models.py create mode 100644 users/tests.py create mode 100644 users/urls.py create mode 100644 users/views.py diff --git a/blog/models.py b/blog/models.py index bd5695d..a9ac8f7 100755 --- a/blog/models.py +++ b/blog/models.py @@ -1,5 +1,6 @@ from django.contrib.auth.models import User from django.db import models +from django.conf import settings STATUS = ((0, "Draft"), (1, "Publish")) @@ -8,7 +9,7 @@ class Post(models.Model): title = models.CharField(max_length=200, unique=True) slug = models.SlugField(max_length=200, unique=True) author = models.ForeignKey( - User, on_delete=models.CASCADE, related_name="blog_posts" + settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="blog_posts" ) updated_on = models.DateTimeField(auto_now=True) content = models.TextField() diff --git a/blog/urls.py b/blog/urls.py index 9bc4613..d19ea0f 100755 --- a/blog/urls.py +++ b/blog/urls.py @@ -3,6 +3,8 @@ from . import views from .feeds import AtomSiteNewsFeed, LatestPostsFeed +app_name = 'blog' + urlpatterns = [ path("feed/rss", LatestPostsFeed(), name="post_feed"), path("feed/atom", AtomSiteNewsFeed()), diff --git a/mysite/settings.py b/mysite/settings.py index 7e6330e..92a0a61 100755 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -43,6 +43,7 @@ "blog", "crispy_forms", "django_summernote", + 'users', ] @@ -158,3 +159,8 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" X_FRAME_OPTIONS = "SAMEORIGIN" + +AUTH_USER_MODEL = "users.CustomUser" + +LOGIN_REDIRECT_URL = "blog:home" +LOGOUT_REDIRECT_URL = "blog:home" \ No newline at end of file diff --git a/mysite/urls.py b/mysite/urls.py index 4c3bd0e..13f88ba 100755 --- a/mysite/urls.py +++ b/mysite/urls.py @@ -32,6 +32,10 @@ path("summernote/", include("django_summernote.urls")), path('__debug__/', include(debug_toolbar.urls)), path("sitemap.xml", sitemap, {"sitemaps": sitemaps}, name="sitemap"), + + #redirect user to logins system + path("users/", include("users.urls")), + path("users/", include("django.contrib.auth.urls")), ] if settings.DEBUG: diff --git a/templates/base.html b/templates/base.html index 1213d83..b7e05c1 100755 --- a/templates/base.html +++ b/templates/base.html @@ -24,7 +24,7 @@