phase2: add modular apps, auth scaffolding, and base template routing
This commit is contained in:
0
apps/users/__init__.py
Normal file
0
apps/users/__init__.py
Normal file
6
apps/users/apps.py
Normal file
6
apps/users/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UsersConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "apps.users"
|
||||
18
apps/users/forms.py
Normal file
18
apps/users/forms.py
Normal file
@ -0,0 +1,18 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class SignupForm(UserCreationForm):
|
||||
email = forms.EmailField(required=True)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ("username", "email", "password1", "password2")
|
||||
|
||||
def save(self, commit=True):
|
||||
user = super().save(commit=False)
|
||||
user.email = self.cleaned_data["email"]
|
||||
if commit:
|
||||
user.save()
|
||||
return user
|
||||
0
apps/users/migrations/__init__.py
Normal file
0
apps/users/migrations/__init__.py
Normal file
12
apps/users/urls.py
Normal file
12
apps/users/urls.py
Normal file
@ -0,0 +1,12 @@
|
||||
from django.urls import path
|
||||
|
||||
from .views import ProfileView, SignupView, UserLoginView, UserLogoutView
|
||||
|
||||
app_name = "users"
|
||||
|
||||
urlpatterns = [
|
||||
path("signup/", SignupView.as_view(), name="signup"),
|
||||
path("login/", UserLoginView.as_view(), name="login"),
|
||||
path("logout/", UserLogoutView.as_view(), name="logout"),
|
||||
path("profile/", ProfileView.as_view(), name="profile"),
|
||||
]
|
||||
31
apps/users/views.py
Normal file
31
apps/users/views.py
Normal file
@ -0,0 +1,31 @@
|
||||
from django.contrib.auth import login
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.views import LoginView, LogoutView
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import CreateView, TemplateView
|
||||
|
||||
from .forms import SignupForm
|
||||
|
||||
|
||||
class SignupView(CreateView):
|
||||
form_class = SignupForm
|
||||
template_name = "users/signup.html"
|
||||
success_url = reverse_lazy("core:dashboard")
|
||||
|
||||
def form_valid(self, form):
|
||||
response = super().form_valid(form)
|
||||
login(self.request, self.object)
|
||||
return response
|
||||
|
||||
|
||||
class UserLoginView(LoginView):
|
||||
template_name = "users/login.html"
|
||||
redirect_authenticated_user = True
|
||||
|
||||
|
||||
class UserLogoutView(LogoutView):
|
||||
next_page = reverse_lazy("core:home")
|
||||
|
||||
|
||||
class ProfileView(LoginRequiredMixin, TemplateView):
|
||||
template_name = "users/profile.html"
|
||||
Reference in New Issue
Block a user