Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Use one password field in all password related forms

Artur Smętbe079eedc712
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index 389cb62069..bb574e7be0 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -11,7 +11,7 @@ from django_prices.templatetags.prices_i18n import gross
from prices import Price
from ...order.models import Order, OrderedItem, OrderNote
-from ...userprofile.forms import AddressForm
+from ...userprofile.i18n import AddressForm
from ..views import (FilterByStatusMixin, StaffMemberOnlyMixin,
staff_member_required)
from .forms import (CancelItemsForm, CancelOrderForm, CapturePaymentForm,
diff --git a/saleor/settings.py b/saleor/settings.py
index f6d67d7372..f66ae080f6 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -321,6 +321,9 @@ ACCOUNT_LOGOUT_ON_GET = True
ACCOUNT_SESSION_REMEMBER = False
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = False
ACCOUNT_ADAPTER = 'saleor.userprofile.adapters.AccountAdapter'
+ACCOUNT_FORMS = {
+ 'reset_password_from_key': 'saleor.userprofile.forms.SetPasswordForm'
+}
ELASTICSEARCH_URL = os.environ.get('ELASTICSEARCH_URL')
diff --git a/saleor/userprofile/forms.py b/saleor/userprofile/forms.py
index 9a62454deb..1f25eb6bdf 100644
--- a/saleor/userprofile/forms.py
+++ b/saleor/userprofile/forms.py
@@ -1,7 +1,12 @@
# encoding: utf-8
from __future__ import unicode_literals
-from .i18n import AddressMetaForm, get_address_form_class, AddressForm
+from allauth.account.adapter import get_adapter
+from allauth.account.forms import SetPasswordField
+from django import forms
+from django.utils.translation import ugettext_lazy as _
+
+from .i18n import AddressMetaForm, get_address_form_class
def get_address_form(data, country_code, initial=None, instance=None, **kwargs):
@@ -29,3 +34,15 @@ def get_address_form(data, country_code, initial=None, instance=None, **kwargs):
initial=initial_address,
**kwargs)
return address_form, preview
+
+
+class SetPasswordForm(forms.Form):
+ password = SetPasswordField(label=_('New Password'))
+
+ def __init__(self, *args, **kwargs):
+ self.user = kwargs.pop('user', None)
+ super(SetPasswordForm, self).__init__(*args, **kwargs)
+ self.fields['password'].user = self.user
+
+ def save(self):
+ get_adapter().set_password(self.user, self.cleaned_data['password'])
diff --git a/saleor/userprofile/views.py b/saleor/userprofile/views.py
index 24d230730d..0c50bc14e1 100755
--- a/saleor/userprofile/views.py
+++ b/saleor/userprofile/views.py
@@ -1,5 +1,4 @@
from allauth.account.adapter import get_adapter
-from allauth.account.forms import ChangePasswordForm
from allauth.account.utils import logout_on_password_change
from django.contrib import messages
from django.contrib.auth.decorators import login_required
@@ -9,6 +8,8 @@ from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
from django.utils.translation import ugettext as _
+from .forms import SetPasswordForm
+
@login_required
def details(request):
@@ -21,7 +22,7 @@ def details(request):
def get_or_process_password_form(request):
- form = ChangePasswordForm(data=request.POST or None, user=request.user)
+ form = SetPasswordForm(data=request.POST or None, user=request.user)
if form.is_valid():
form.save()
logout_on_password_change(request, form.user)
diff --git a/templates/account/password_reset_from_key_done.html b/templates/account/password_reset_from_key_done.html
index e136830b8f..5988c83d46 100644
--- a/templates/account/password_reset_from_key_done.html
+++ b/templates/account/password_reset_from_key_done.html
@@ -5,7 +5,7 @@
{% block form %}
<h2 class="text-center">{% trans "Change Password" %}</h2>
- {% url "account_signin" as login_url %}
+ {% url "account_login" as login_url %}
<p>{% trans 'Your password is now changed.' %}
{% blocktrans with login_url=login_url %}You can now <a href="{{ login_url }}">sign in</a> using your new password {% endblocktrans %}</p>
{% endblock %}