Skip to content

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

Change password

Mira Szewczyk64240ad24859
diff --git a/saleor/settings.py b/saleor/settings.py
index 90cc6ebba6..b3fb0c9df0 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -336,17 +336,7 @@ WEBPACK_LOADER = {
r'.+\.map']}}
-ACCOUNT_AUTHENTICATION_METHOD = 'email'
-ACCOUNT_EMAIL_REQUIRED = True
-ACCOUNT_USER_MODEL_USERNAME_FIELD = None
-ACCOUNT_EMAIL_VERIFICATION = 'none'
-ACCOUNT_USERNAME_REQUIRED = False
-ACCOUNT_LOGOUT_ON_GET = True
-ACCOUNT_SESSION_REMEMBER = False
-ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = False
-ACCOUNT_FORMS = {
- 'reset_password_from_key': 'saleor.userprofile.forms.SetPasswordForm'
-}
+LOGOUT_ON_PASSWORD_CHANGE = False
ELASTICSEARCH_URL = os.environ.get('ELASTICSEARCH_URL')
diff --git a/saleor/userprofile/forms.py b/saleor/userprofile/forms.py
index fb185e5246..c88aaa8bfa 100644
--- a/saleor/userprofile/forms.py
+++ b/saleor/userprofile/forms.py
@@ -1,10 +1,8 @@
# encoding: utf-8
from __future__ import unicode_literals
-from allauth.account.adapter import get_adapter
-from allauth.account.forms import SetPasswordField, UserForm, PasswordField
-from django import forms
-from django.utils.translation import pgettext
+from django.conf import settings
+from django.contrib.auth import forms as django_forms, update_session_auth_hash
from .i18n import AddressMetaForm, get_address_form_class
@@ -36,40 +34,16 @@ def get_address_form(data, country_code, initial=None, instance=None, **kwargs):
return address_form, preview
-class SetPasswordForm(forms.Form):
- password1 = SetPasswordField(
- label=pgettext('Set password form label', 'New Password'))
-
- def __init__(self, *args, **kwargs):
- self.user = kwargs.pop('user', None)
- self.temp_key = kwargs.pop("temp_key", None)
- super(SetPasswordForm, self).__init__(*args, **kwargs)
- self.fields['password1'].user = self.user
-
- def save(self):
- get_adapter().set_password(self.user, self.cleaned_data['password1'])
-
-
-class ChangePasswordForm(UserForm):
-
- oldpassword = PasswordField(
- label=pgettext('Change password form label', 'Current Password'))
- password1 = SetPasswordField(
- label=pgettext('Change password form label', 'New Password'))
-
+class ChangePasswordForm(django_forms.PasswordChangeForm):
def __init__(self, *args, **kwargs):
super(ChangePasswordForm, self).__init__(*args, **kwargs)
- self.fields['password1'].user = self.user
- self.fields['oldpassword'].widget.attrs['placeholder'] = ''
- self.fields['password1'].widget.attrs['placeholder'] = ''
+ self.fields['new_password1'].user = self.user
+ self.fields['old_password'].widget.attrs['placeholder'] = ''
+ self.fields['new_password1'].widget.attrs['placeholder'] = ''
+ del self.fields['new_password2']
- def clean_oldpassword(self):
- if not self.user.check_password(self.cleaned_data.get('oldpassword')):
- raise forms.ValidationError(
- pgettext(
- 'Change password form error',
- 'Please type your current password.'))
- return self.cleaned_data['oldpassword']
- def save(self):
- get_adapter().set_password(self.user, self.cleaned_data['password1'])
+def logout_on_password_change(request, user):
+ if (update_session_auth_hash is not None and
+ not settings.LOGOUT_ON_PASSWORD_CHANGE):
+ update_session_auth_hash(request, user)
diff --git a/saleor/userprofile/views.py b/saleor/userprofile/views.py
index 6879e84f30..3357bc1daf 100755
--- a/saleor/userprofile/views.py
+++ b/saleor/userprofile/views.py
@@ -1,7 +1,3 @@
-from allauth.account.adapter import get_adapter
-from allauth.account.views import login as allauth_login
-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
from django.core.urlresolvers import reverse
@@ -9,8 +5,8 @@ from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
from django.utils.translation import pgettext
-from ..cart.utils import find_and_assign_anonymous_cart
-from .forms import ChangePasswordForm, get_address_form
+from .forms import (ChangePasswordForm, get_address_form,
+ logout_on_password_change)
@login_required
@@ -28,10 +24,8 @@ def get_or_process_password_form(request):
if form.is_valid():
form.save()
logout_on_password_change(request, form.user)
- get_adapter(request).add_message(
- request,
- messages.SUCCESS,
- 'account/messages/password_changed.txt')
+ messages.success(request, pgettext(
+ 'Storefront message', 'Password successfully changed.'))
return form
@@ -62,6 +56,3 @@ def address_delete(request, pk):
return HttpResponseRedirect(reverse('profile:details') + '#addresses')
return TemplateResponse(
request, 'userprofile/address-delete.html', {'address': address})
-
-
-login = find_and_assign_anonymous_cart()(allauth_login)