Add registration form

Prepare for closed registrations (will be default probably)
This commit is contained in:
Kumi 2020-12-31 22:17:02 +01:00
parent e7a0ff4a64
commit 4e4d47a9ad
6 changed files with 116 additions and 58 deletions

View file

@ -0,0 +1,33 @@
{% include "frontend/header.html" %}
<body class="bg-gradient-primary">
<div class="container">
<!-- Outer Row -->
<div class="row justify-content-center">
<div class="col-xl-10 col-lg-12 col-md-9">
<div class="card o-hidden border-0 shadow-lg my-5">
<div class="card-body p-0">
<!-- Nested Row within Card Body -->
<div class="row">
<div class="col-lg-6 d-none d-lg-block bg-login-image"></div>
<div class="col-lg-6">
{% block content %}
{% endblock %}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% include "frontend/footer.html" %}

View file

@ -1,20 +1,6 @@
{% include "frontend/header.html" %} {% extends "registration/base.html" %}
<body class="bg-gradient-primary"> {% block content %}
<div class="container">
<!-- Outer Row -->
<div class="row justify-content-center">
<div class="col-xl-10 col-lg-12 col-md-9">
<div class="card o-hidden border-0 shadow-lg my-5">
<div class="card-body p-0">
<!-- Nested Row within Card Body -->
<div class="row">
<div class="col-lg-6 d-none d-lg-block bg-login-image"></div>
<div class="col-lg-6">
<div class="p-5"> <div class="p-5">
<div class="text-center"> <div class="text-center">
<h1 class="h4 text-gray-900 mb-4">Welcome Back!</h1> <h1 class="h4 text-gray-900 mb-4">Welcome Back!</h1>
@ -37,21 +23,10 @@
</form> </form>
<hr> <hr>
<div class="text-center"> <div class="text-center">
<a class="small" href="forgot-password.html">Forgot Password?</a> <a class="small" href="#">Forgot Password?</a>
</div> </div>
<div class="text-center"> <div class="text-center">
<a class="small" href="register.html">Create an Account!</a> <a class="small" href="{% url "frontend:register" %}">Create an Account!</a>
</div> </div>
</div> </div>
</div> {% endblock %}
</div>
</div>
</div>
</div>
</div>
</div>
{% include "frontend/footer.html" %}

View file

@ -0,0 +1,32 @@
{% extends "registration/base.html" %}
{% block content %}
<div class="p-5">
<div class="text-center">
<h1 class="h4 text-gray-900 mb-4">Let's get started!</h1>
</div>
<form class="user" action="" method="post">
{% csrf_token %}
<div class="form-group">
<input class="form-control form-control-user"
id="id_username" aria-describedby="emailHelp" name="username"
placeholder="Username">
</div>
<div class="form-group">
<input type="password" class="form-control form-control-user"
id="id_password1" name="password1" placeholder="Password">
</div>
<div class="form-group">
<input type="password" class="form-control form-control-user"
id="id_password2" name="password2" placeholder="Repeat Password">
</div>
<button type="submit" class="btn btn-primary btn-user btn-block">
Login
</button>
<hr>
</form>
<div class="text-center">
<a class="small" href="{% url "login" %}">Already have an account? Sign in!</a>
</div>
</div>
{% endblock %}

View file

@ -1,4 +1,4 @@
from .views import DashboardView from .views import DashboardView, UserRegistrationView
from django.urls import path, include from django.urls import path, include
@ -6,4 +6,5 @@ app_name = "frontend"
urlpatterns = [ urlpatterns = [
path('', DashboardView.as_view(), name="dashboard"), path('', DashboardView.as_view(), name="dashboard"),
path('accounts/register/', UserRegistrationView.as_view(), name="register"),
] ]

View file

@ -1,5 +1,8 @@
from django.views.generic import TemplateView, ListView, UpdateView, DetailView, CreateView, DeleteView from django.views.generic import TemplateView, CreateView
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import get_user_model, login
from django.urls import reverse_lazy
class DashboardView(LoginRequiredMixin, TemplateView): class DashboardView(LoginRequiredMixin, TemplateView):
@ -10,3 +13,17 @@ class DashboardView(LoginRequiredMixin, TemplateView):
context["title"] = "Dashboard" context["title"] = "Dashboard"
context["subtitle"] = "An overview of everything going on in your Kumify account." context["subtitle"] = "An overview of everything going on in your Kumify account."
return context return context
class UserRegistrationView(CreateView):
form_class = UserCreationForm
model = get_user_model()
template_name = "registration/registration_form.html"
def form_valid(self, form):
ret = super().form_valid(form)
login(self.request, self.object)
return ret
def get_success_url(self):
return reverse_lazy("frontend:dashboard")