Skip to content

Commit

Permalink
Added authentication app
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniDiazTech committed May 25, 2021
1 parent 9e90b26 commit 881b514
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 0 deletions.
Empty file added config/users/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions config/users/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions config/users/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class UsersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'users'
Empty file added config/users/forms.py
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions config/users/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions config/users/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
10 changes: 10 additions & 0 deletions config/users/urls.py
Original file line number Diff line number Diff line change
@@ -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'),
]
31 changes: 31 additions & 0 deletions config/users/views.py
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 881b514

Please sign in to comment.