Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add send_set_password_email
michald104f721a720
diff --git a/saleor/dashboard/staff/emails.py b/saleor/dashboard/staff/emails.pynew file mode 100644index 0000000000..4cbe681e81--- /dev/null+++ b/saleor/dashboard/staff/emails.py@@ -0,0 +1,26 @@+from django.contrib.auth.tokens import default_token_generator+from django.core.mail import send_mail+from django.template import loader+from django.utils.encoding import force_bytes+from django.utils.http import urlsafe_base64_encode++from ...settings import DEFAULT_FROM_EMAIL, get_host+++def send_set_password_email(staff):+ ctx = {+ 'email': staff.email,+ 'domain': get_host(),+ 'site_name': 'saleor',+ 'uid': urlsafe_base64_encode(force_bytes(staff.pk)),+ 'user': staff,+ 'token': default_token_generator.make_token(staff),+ 'protocol': 'http',+ }+ subject_template_name = 'account/email/password_reset_subject.txt'+ email_template_name = 'account/email/password_reset_message.txt'+ subject = loader.render_to_string(subject_template_name, ctx)+ subject = ''.join(subject.splitlines())+ email = loader.render_to_string(email_template_name, ctx)+ send_mail(subject, email, DEFAULT_FROM_EMAIL, [staff.email],+ fail_silently=False)diff --git a/saleor/dashboard/staff/forms.py b/saleor/dashboard/staff/forms.pyindex 5d55c9ba80..e9082d2e4a 100644--- a/saleor/dashboard/staff/forms.py+++ b/saleor/dashboard/staff/forms.py@@ -14,6 +14,3 @@ class StaffForm(forms.ModelForm):model = Userfields = ['email', 'groups', 'is_superuser', 'is_staff','is_active']-- def is_valid(self):- return self.is_bound and not self.errorsdiff --git a/saleor/dashboard/staff/views.py b/saleor/dashboard/staff/views.pyindex 4b977ffd50..694131d4fc 100644--- a/saleor/dashboard/staff/views.py+++ b/saleor/dashboard/staff/views.py@@ -5,11 +5,12 @@ from django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponsefrom django.utils.translation import pgettext_lazy+from saleor.dashboard.staff.emails import send_set_password_emailfrom .forms import StaffFormfrom ..views import superuser_requiredfrom ...core.utils import get_paginator_items-from ...userprofile.models import Userfrom ...settings import DASHBOARD_PAGINATE_BY+from ...userprofile.models import User@superuser_required@@ -38,14 +39,15 @@ def staff_details(request, pk):@superuser_requireddef staff_create(request):staff = User()- staff_form = StaffForm()- if staff_form.is_valid():- staff = staff_form.save()+ form = StaffForm(request.POST or None, instance=staff)+ if form.is_valid():+ form.save()msg = pgettext_lazy('Dashboard message', 'Added staff member %s') % staffmessages.success(request, msg)- return redirect('dashboard:staff-list', pk=staff.pk)- ctx = {'form': staff_form}+ send_set_password_email(staff)+ return redirect('dashboard:staff-list')+ ctx = {'form': form}return TemplateResponse(request, 'dashboard/staff/detail.html', ctx)diff --git a/templates/dashboard/staff/detail.html b/templates/dashboard/staff/detail.htmlindex 30ce5d7f9a..1dc1429cf8 100644--- a/templates/dashboard/staff/detail.html+++ b/templates/dashboard/staff/detail.html@@ -60,7 +60,7 @@<form class="card" method="post"><div class="card-content"><span class="card-title">- {% trans 'User details' context 'User details header' %}+ {% trans 'Staff member details' context 'Staff member details header' %}</span><div class="data">{% csrf_token %}@@ -74,7 +74,7 @@{% if staff_member %}{% trans 'Update' context 'Dashboard update action' %}{% else %}- {% trans 'Add' context 'Dashboard create action' %}+ {% trans 'Add' context 'Dashboard add action' %}{% endif %}</button></div>