This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(registerView): add register view
- Loading branch information
1 parent
e50cbe4
commit 5afac5e
Showing
7 changed files
with
51 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.contrib.auth.forms import UserCreationForm | ||
|
||
from apps.users.models import User | ||
|
||
|
||
class CreateUserForm(UserCreationForm[User]): | ||
class Meta: | ||
model = User | ||
fields = ["username", "email", "password1", "password2"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.urls import path | ||
|
||
from apps.users.views import RegisterView | ||
|
||
app_name = "users" | ||
|
||
urlpatterns = [ | ||
path("register/", RegisterView.as_view(), name="register"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.http import HttpRequest, HttpResponse | ||
from django.shortcuts import redirect, render | ||
from django.views import View | ||
|
||
from apps.users.forms import CreateUserForm | ||
|
||
|
||
class RegisterView(View): | ||
template_name = "registration/register.html" | ||
|
||
def get(self, request: HttpRequest) -> HttpResponse | None: | ||
form = CreateUserForm() | ||
return render(request, self.template_name, {"form": form}) | ||
|
||
def post(self, request: HttpRequest) -> HttpResponse | None: | ||
form = CreateUserForm(self.request.POST) | ||
if form.is_valid(): | ||
form.save() | ||
return redirect("login") | ||
|
||
return render(request, self.template_name, {"form": form}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters