Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

Commit

Permalink
Merge pull request #41 from crab85193/dev_crab
Browse files Browse the repository at this point in the history
認証メール再送機能を追加
  • Loading branch information
crab85193 authored Nov 10, 2023
2 parents 4725e26 + cd59a75 commit 01e4a13
Show file tree
Hide file tree
Showing 19 changed files with 460 additions and 16 deletions.
19 changes: 19 additions & 0 deletions main_app/forms/password_forgot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm

class PasswordForgotForm(PasswordResetForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for field in self.fields.values():
field.widget.attrs['class'] = 'form-control form-control-user'

self.fields['email'].widget.attrs['placeholder'] = 'Enter Email Address...'


class SetNewPasswordForm(SetPasswordForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for field in self.fields.values():
field.widget.attrs['class'] = 'form-control form-control-user'

self.fields['new_password1'].widget.attrs['placeholder'] = 'Enter New password...'
self.fields['new_password2'].widget.attrs['placeholder'] = 'Enter New password confirmation...'
9 changes: 8 additions & 1 deletion main_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .views.login import LoginView
from .views.logout import Logout
from .views.register import RegisterRequestView, RegisterDoneView, RegisterCompleteView, RegisterErrorView
from .views.password_forgot import PasswordForgotView, PasswordForgotDoneView, PasswordResetConfirmView, PasswordResetCompleteView
from .views.top import TopView
from .views.password_change import PasswordChangeView, PasswordChangeDoneView

Expand All @@ -39,10 +40,16 @@
path("logout/", Logout.as_view() , name="logout"),

path("register/" , RegisterRequestView.as_view() , name="register_request" ),
path("register/done/" , RegisterDoneView.as_view() , name="register_done" ),
path("register/done/<uuid:user_id>/" , RegisterDoneView.as_view() , name="register_done" ),
path('register/check/<uuid:activate_token>/' , RegisterCompleteView.as_view(), name='register_complete'),
path('register/check/error/<int:error_code>/', RegisterErrorView.as_view() , name='register_error' ),

# forgot-password
path('password/forgot/' , PasswordForgotView.as_view() , name='password_forgot' ),
path('password/forgot/done/' , PasswordForgotDoneView.as_view() , name='password_forgot_done' ),
path('password/reset/confirm/<uidb64>/<token>/', PasswordResetConfirmView.as_view() , name='password_reset_confirm' ),
path('password/reset/complete/' , PasswordResetCompleteView.as_view(), name='password_reset_complete'),

path("top/", TopView.as_view(), name="top"),

path("settings/password/change/" , PasswordChangeView.as_view() , name="password_change" ),
Expand Down
23 changes: 23 additions & 0 deletions main_app/views/password_forgot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.contrib.auth.views import PasswordResetView, PasswordResetDoneView, PasswordResetConfirmView, PasswordResetCompleteView
from django.urls import reverse_lazy
from ..forms.password_forgot import PasswordForgotForm, SetNewPasswordForm

class PasswordForgotView(PasswordResetView):
template_name = 'main_app/password_forgot/password_forgot.html'
subject_template_name = 'main_app/mail_templates/password_reset/subject.txt'
email_template_name = 'main_app/mail_templates/password_reset/message.txt'
form_class = PasswordForgotForm
success_url = reverse_lazy('main_app:password_forgot_done')


class PasswordForgotDoneView(PasswordResetDoneView):
template_name = 'main_app/password_forgot/password_forgot_done.html'


class PasswordResetConfirmView(PasswordResetConfirmView):
template_name = 'main_app/password_forgot/password_reset_confirm.html'
form_class = SetNewPasswordForm
success_url = reverse_lazy('main_app:password_reset_complete')

class PasswordResetCompleteView(PasswordResetCompleteView):
template_name = 'main_app/password_forgot/password_reset_complete.html'
27 changes: 25 additions & 2 deletions main_app/views/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..models.user import User
from ..models.user_activate_tokens import UserActivateTokens
from ..forms.register import Register
from django.contrib import messages

class RegisterRequestView(CreateView):
form_class = Register
Expand Down Expand Up @@ -37,11 +38,33 @@ def form_valid(self, form):

send_mail(subject, message, from_email, recipient_list)

return HttpResponseRedirect(reverse('main_app:register_done'))
return HttpResponseRedirect(reverse('main_app:register_done', args=[user_activate_token.user.id]))


class RegisterDoneView(TemplateView):
template_name = 'main_app/register/register-done.html'
template_name = 'main_app/register/register-done.html'
user_id = None

def get(self, request, user_id):
self.user_id = user_id
return super().get(request)

def post(self, request, user_id):
instance = User.objects.get(id=str(user_id))
user_activate_token = UserActivateTokens.objects.get(user=instance)
subject = '【Tely】アカウントの認証'
message = f"こんにちは {instance.username} さん\n\nご登録いただきありがとうございます。アカウントを有効化するためには、以下のリンクをクリックしてください。\n\n{'{0}://{1}'.format(self.request.scheme, self.request.get_host())}{reverse('main_app:register_complete', args=[user_activate_token.activate_token])}\n\nもしこのメールが誤って届いた場合や、アカウント登録を行っていない場合は、このメールを無視していただいて結構です。\n\nご質問やお困りごとがあれば、お気軽にご連絡ください。\n\n[Tely] サポートチーム\n"

from_email = settings.DEFAULT_FROM_EMAIL
recipient_list = [
instance.email,
]

send_mail(subject, message, from_email, recipient_list)

messages.success(request, 'メールを再送しました。ご確認ください。')

return super().get(request)


class RegisterCompleteView(TemplateView):
Expand Down
7 changes: 5 additions & 2 deletions templates/main_app/login/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
{% load static %}

{% block title %}
Login
ログイン
{% endblock%}

{% block main %}
<div class="container">

<section class="section register min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
<section class="section login min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-4 col-md-6 d-flex flex-column align-items-center justify-content-center">
Expand Down Expand Up @@ -56,6 +56,9 @@ <h5 class="card-title text-center pb-0 fs-4">ログイン</h5>
<div class="col-12">
<p class="small mb-0"><a href="{% url 'main_app:register_request' %}">新規アカウントを作成する</a></p>
</div>
<div class="col-12">
<p class="small mb-0"><a href="{% url 'main_app:password_forgot' %}">パスワードを忘れた場合</a></p>
</div>
</form>

</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/main_app/login/logout.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
{% load static %}

{% block title %}
Logout
ログアウト
{% endblock%}

{% block main %}
<div class="container">

<section class="section register min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
<section class="section logout min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-4 col-md-6 d-flex flex-column align-items-center justify-content-center">
Expand Down
11 changes: 11 additions & 0 deletions templates/main_app/mail_templates/password_reset/message.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
こんにちは {{ user.username }} さん

パスワードを再設定するためには、以下のリンクをクリックしてください。

{{ protocol}}://{{ domain }}{% url 'main_app:password_reset_confirm' uid token %}

もしこのメールが誤って届いた場合や、アカウント登録を行っていない場合は、このメールを無視していただいて結構です。

ご質問やお困りごとがあれば、お気軽にご連絡ください。

[Tely] サポートチーム
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
【Tely】パスワードの再設定
2 changes: 1 addition & 1 deletion templates/main_app/password_change/password_change.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% block main %}
<div class="container">

<section class="section register min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
<section class="section password-change min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-4 col-md-6 d-flex flex-column align-items-center justify-content-center">
Expand Down
4 changes: 2 additions & 2 deletions templates/main_app/password_change/password_change_done.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
{% load static %}

{% block title %}
パスワード変更 完了
パスワード変更 - 完了
{% endblock%}

{% block main %}
<div class="container">

<section class="section register min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
<section class="section password-change min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-4 col-md-6 d-flex flex-column align-items-center justify-content-center">
Expand Down
69 changes: 69 additions & 0 deletions templates/main_app/password_forgot/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% load static %}
<!DOCTYPE html>
<html lang="ja">

<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">

<title>{% block title %}{% endblock %} - Tely</title>
<meta content="" name="description">
<meta content="" name="keywords">

<!-- Favicons -->
<link href="{% static 'img/favicon.png' %}" rel="icon">
<link href="{% static 'img/apple-touch-icon.png' %}" rel="apple-touch-icon">

<!-- Google Fonts -->
<link href="https://fonts.gstatic.com" rel="preconnect">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">

<!-- Vendor CSS Files -->
<link href="{% static 'vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
<link href="{% static 'vendor/bootstrap-icons/bootstrap-icons.css' %}" rel="stylesheet">
<link href="{% static 'vendor/boxicons/css/boxicons.min.css' %}" rel="stylesheet">
<link href="{% static 'vendor/quill/quill.snow.css' %}" rel="stylesheet">
<link href="{% static 'vendor/quill/quill.bubble.css' %}" rel="stylesheet">
<link href="{% static 'vendor/remixicon/remixicon.css' %}" rel="stylesheet">
<link href="{% static 'vendor/simple-datatables/style.css' %}" rel="stylesheet">

<!-- Template Main CSS File -->
<link href="{% static 'css/style.css' %}" rel="stylesheet">

{% block head %}{% endblock %}

<!-- =======================================================
* Template Name: NiceAdmin
* Updated: Sep 18 2023 with Bootstrap v5.3.2
* Template URL: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/
* Author: BootstrapMade.com
* License: https://bootstrapmade.com/license/
======================================================== -->
</head>

<body>

<main>
{% block main %}{% endblock %}
</main><!-- End #main -->

<a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>

<!-- Vendor JS Files -->
<script src="{% static 'vendor/apexcharts/apexcharts.min.js' %}"></script>
<script src="{% static 'vendor/bootstrap/js/bootstrap.bundle.min.js' %}"></script>
<script src="{% static 'vendor/chart.js/chart.umd.js' %}"></script>
<script src="{% static 'vendor/echarts/echarts.min.js' %}"></script>
<script src="{% static 'vendor/quill/quill.min.js' %}"></script>
<script src="{% static 'vendor/simple-datatables/simple-datatables.js' %}"></script>
<script src="{% static 'vendor/tinymce/tinymce.min.js' %}"></script>
<script src="{% static 'vendor/php-email-form/validate.js' %}"></script>

<!-- Template Main JS File -->
<script src="{% static 'js/main.js' %}"></script>

{% block script %}{% endblock %}

</body>

</html>
75 changes: 75 additions & 0 deletions templates/main_app/password_forgot/password_forgot.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{% extends 'main_app/password_forgot/base.html' %}
{% load static %}

{% block title %}
パスワード再設定
{% endblock%}

{% block main %}
<div class="container">

<section class="section password-forgot min-vh-100 d-flex flex-column align-items-center justify-content-center py-4">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-4 col-md-6 d-flex flex-column align-items-center justify-content-center">

<div class="d-flex justify-content-center py-4">
<a href="{% url 'main_app:login' %}" class="logo d-flex align-items-center w-auto">
<img src="{% static 'img/logo.png' %}" alt="">
<span class="d-none d-lg-block">Tely</span>
</a>
</div><!-- End Logo -->

<div class="card mb-3">

<div class="card-body">

<div class="pt-4 pb-2">
<h5 class="card-title text-center pb-0 fs-4">パスワード再設定</h5>
<p class="text-center small">アカウント登録時に使用したメールアドレスを入力してください</p>
</div>

<form class="row g-3 needs-validation" method="POST">
{% csrf_token %}
{% for field in form %}
<div class="col-12">
<label for="id_{{ field.name }}" class="form-label">{{ field.label }}</label>
<div class="input-group has-validation">
{{ field }}
</div>

{% if field.errors %}
<div class="alert alert-danger" role="alert">
{% for error in field.errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}
</div>
{% endfor %}
<div class="col-12">
<button class="btn btn-primary w-100" type="submit">パスワード再設定メールを送信する</button>
</div>
<div class="col-12">
<p class="small mb-0"><a href="{% url 'main_app:login' %}">ログインページへ</a></p>
</div>
</form>
</div>
</div>

<div class="credits">
<!-- All the links in the footer should remain intact. -->
<!-- You can delete the links only if you purchased the pro version. -->
<!-- Licensing information: https://bootstrapmade.com/license/ -->
<!-- Purchase the pro version with working PHP/AJAX contact form: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/ -->
Designed by <a href="https://bootstrapmade.com/">BootstrapMade</a>
</div>

</div>
</div>
</div>

</section>

</div>
{% endblock %}
Loading

0 comments on commit 01e4a13

Please sign in to comment.