Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🗃️ [#26] Added user to the Customer model #46

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/bobvance/base/migrations/0006_customer_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.21 on 2023-10-12 08:23

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('base', '0005_order_total_price'),
]

operations = [
migrations.AddField(
model_name='customer',
name='user',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]
2 changes: 2 additions & 0 deletions src/bobvance/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

from bobvance.base.choices import OrderStatusChoices

from bobvance.accounts.models import User

# Create your models here.
class Customer(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, null=True, blank=True)
firstname = models.CharField(max_length=50)
lastname = models.CharField(max_length=50)
email = models.EmailField()
Expand Down
Empty file added src/bobvance/login/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions src/bobvance/login/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 src/bobvance/login/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class LoginConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'login'
Empty file.
3 changes: 3 additions & 0 deletions src/bobvance/login/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.
3 changes: 3 additions & 0 deletions src/bobvance/login/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.
11 changes: 11 additions & 0 deletions src/bobvance/login/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.urls import path

from django.contrib.auth import views as auth_views

urlpatterns = [
path('login/', auth_views.LoginView.as_view(), name='login'),
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
path('password_reset/', auth_views.PasswordResetView.as_view(template_name='registration/password_reset.html'), name='password_reset'),
path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(template_name='registration/password_reset_confirm.html'), name='password_reset_confirm'),
path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(template_name='registration/password_reset_done.html'), name='password_reset_done'),
]
3 changes: 3 additions & 0 deletions src/bobvance/login/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
38 changes: 38 additions & 0 deletions src/bobvance/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% extends "master.html" %}

{% block content %}

{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}

{% if next %}
{% if user.is_authenticated %}
<p>Your account doesn't have access to this page. To proceed,
please login with an account that has access.</p>
{% else %}
<p>Please login to see this page.</p>
{% endif %}
{% endif %}

<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>

<input type="submit" value="login">
<input type="hidden" name="next" value="{{ next }}">
</form>

{# Assumes you set up the password_reset view in your URLconf #}
<p><a href="{% url 'password_reset' %}">Lost password?</a></p>

{% endblock %}
19 changes: 19 additions & 0 deletions src/bobvance/templates/registration/password_reset.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "master.html" %}

{% block content %}

{% if form.errors %}
<p>There was an error with the submitted form. Please correct the errors and try again.</p>
{% endif %}

<h2>Password Reset</h2>

<form method="post" action="{% url 'password_reset' %}">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Reset Password</button>
</form>

<p>Remembered your password? <a href="{% url 'login' %}">Log in</a></p>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "master.html" %}

{% block content %}

{% if valid %}
<h2>Password Reset Successful</h2>
<p>Your password has been successfully reset.</p>
<p><a href="{% url 'login' %}">Log in</a></p>
{% else %}
<h2>Password Reset Failed</h2>
<p>The password reset link is no longer valid. Please request a new one.</p>
<p><a href="{% url 'password_reset' %}">Request a new password reset</a></p>
{% endif %}

{% endblock %}
11 changes: 11 additions & 0 deletions src/bobvance/templates/registration/password_reset_done.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "master.html" %}

{% block content %}

<h2>Password Reset Email Sent</h2>
<p>We've sent you an email with instructions on how to reset your password.
If you don't receive an email within a few minutes, check your spam folder.</p>

<p><a href="{% url 'login' %}">Return to login page</a></p>

{% endblock %}
1 change: 1 addition & 0 deletions src/bobvance/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
),
path("", include("bobvance.base.urls")),
path("", include("bobvance.contact.urls")),
path("", include("bobvance.login.urls")),
]

# NOTE: The staticfiles_urlpatterns also discovers static files (ie. no need to run collectstatic). Both the static
Expand Down
Loading