From 881b51461cae85cf60b62f6d8480eb4574f913d6 Mon Sep 17 00:00:00 2001 From: Daniel Diaz Date: Mon, 24 May 2021 23:28:53 -0500 Subject: [PATCH] Added authentication app --- config/users/__init__.py | 0 config/users/admin.py | 3 +++ config/users/apps.py | 6 +++++ config/users/forms.py | 0 config/users/migrations/__init__.py | 0 config/users/models.py | 3 +++ config/users/templates/users/login.html | 0 config/users/templates/users/signup.html | 0 config/users/tests.py | 3 +++ config/users/urls.py | 10 ++++++++ config/users/views.py | 31 ++++++++++++++++++++++++ 11 files changed, 56 insertions(+) create mode 100644 config/users/__init__.py create mode 100644 config/users/admin.py create mode 100644 config/users/apps.py create mode 100644 config/users/forms.py create mode 100644 config/users/migrations/__init__.py create mode 100644 config/users/models.py create mode 100644 config/users/templates/users/login.html create mode 100644 config/users/templates/users/signup.html create mode 100644 config/users/tests.py create mode 100644 config/users/urls.py create mode 100644 config/users/views.py diff --git a/config/users/__init__.py b/config/users/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/users/admin.py b/config/users/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/config/users/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/config/users/apps.py b/config/users/apps.py new file mode 100644 index 0000000..72b1401 --- /dev/null +++ b/config/users/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UsersConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'users' diff --git a/config/users/forms.py b/config/users/forms.py new file mode 100644 index 0000000..e69de29 diff --git a/config/users/migrations/__init__.py b/config/users/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/users/models.py b/config/users/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/config/users/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/config/users/templates/users/login.html b/config/users/templates/users/login.html new file mode 100644 index 0000000..e69de29 diff --git a/config/users/templates/users/signup.html b/config/users/templates/users/signup.html new file mode 100644 index 0000000..e69de29 diff --git a/config/users/tests.py b/config/users/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/config/users/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/config/users/urls.py b/config/users/urls.py new file mode 100644 index 0000000..1d5c8d0 --- /dev/null +++ b/config/users/urls.py @@ -0,0 +1,10 @@ +from django.urls import path + +from .views import SignUpView, CustomLoginView + +app_name = 'user' + +urlpatterns = [ + path('signup/', SignUpView.as_view(), name='signup'), + path('login/', CustomLoginView.as_view(), name='login'), +] \ No newline at end of file diff --git a/config/users/views.py b/config/users/views.py new file mode 100644 index 0000000..dab3294 --- /dev/null +++ b/config/users/views.py @@ -0,0 +1,31 @@ +from django.contrib import auth +from django.views.generic import CreateView + +from django.contrib.auth import views, authenticate, login + +from django.contrib.auth.forms import UserCreationForm + +from django.urls import reverse_lazy + +class SignUpView(CreateView): + + template_name = 'users/signup.html' + + form = UserCreationForm + + success_url = reverse_lazy('photo:list') + + def form_valid(self, form): + + user = authenticate( + username=form.cleaned_data["username"], + password=form.cleaned_data["password1"], + ) + + login(self.request, user) + + return super().form_valid(form) + +class CustomLoginView(views.LoginView): + + template_name = 'users/login.html' \ No newline at end of file