Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Better login page and page titles
Patryk Zawadzki8e2b4c27d822
diff --git a/saleor/cart/templates/cart/index.html b/saleor/cart/templates/cart/index.htmlindex 9c7ec80990..6b7ec2181c 100644--- a/saleor/cart/templates/cart/index.html+++ b/saleor/cart/templates/cart/index.html@@ -3,7 +3,7 @@{% load gross from prices %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Your cart" %}{% endblock %}+{% block title %}{% trans "Your cart" %} — {{ block.super }}{% endblock %}{% block breadcrumb %}{{ block.super }}diff --git a/saleor/cart/views.py b/saleor/cart/views.pyindex d9ab1e12d5..10273df157 100755--- a/saleor/cart/views.py+++ b/saleor/cart/views.py@@ -1,5 +1,9 @@+from __future__ import unicode_literals++from django.contrib import messagesfrom django.shortcuts import redirectfrom django.template.response import TemplateResponse+from django.utils.translation import ugettext as _from . import CartPartitionerfrom .forms import ReplaceCartLineFormSet@@ -9,6 +13,8 @@ def index(request):partitioner = CartPartitioner(request.cart)formset = ReplaceCartLineFormSet(request.POST or None, cart=request.cart)if formset.is_valid():+ msg = _('Successfully updated product quantities.')+ messages.success(request, msg)formset.save()return redirect('cart:index')return TemplateResponse(diff --git a/saleor/checkout/templates/checkout/address.html b/saleor/checkout/templates/checkout/address.htmlindex 861ee4d1f6..ea4067a5d4 100644--- a/saleor/checkout/templates/checkout/address.html+++ b/saleor/checkout/templates/checkout/address.html@@ -2,8 +2,6 @@{% load as_horizontal_form from bootstrap %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Billing Address" %}{% endblock %}-{% block forms %}<form method="post" class="form-horizontal">{% csrf_token %}diff --git a/saleor/checkout/templates/checkout/details.html b/saleor/checkout/templates/checkout/details.htmlindex 6e5c407b2c..d1a1a371c1 100644--- a/saleor/checkout/templates/checkout/details.html+++ b/saleor/checkout/templates/checkout/details.html@@ -2,7 +2,7 @@{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Checkout" %}{% endblock %}+{% block title %}{% trans "Checkout" %} — {{ block.super }}{% endblock %}{% block outerbreadcrumb %}{% endblock %}diff --git a/saleor/checkout/templates/checkout/digitaldelivery.html b/saleor/checkout/templates/checkout/digitaldelivery.htmlindex 0271a1ced0..71c1c3b9a2 100644--- a/saleor/checkout/templates/checkout/digitaldelivery.html+++ b/saleor/checkout/templates/checkout/digitaldelivery.html@@ -2,8 +2,6 @@{% load i18n %}{% load as_horizontal_form from bootstrap %}-{% block title %}{{ block.super }} » {% trans "Digital delivery" %}{% endblock %}-{% block forms %}<form method="post" class="form-horizontal">{% csrf_token %}diff --git a/saleor/checkout/templates/checkout/shipping.html b/saleor/checkout/templates/checkout/shipping.htmlindex 2b311bba8b..f7d9a61799 100644--- a/saleor/checkout/templates/checkout/shipping.html+++ b/saleor/checkout/templates/checkout/shipping.html@@ -2,8 +2,6 @@{% load as_horizontal_form from bootstrap %}{% load i18n %}-{% block title %}{% trans "Checkout" %} » {% trans "Shipping" %}{% endblock %}-{% block extra_forms %}<fieldset><legend>diff --git a/saleor/checkout/templates/checkout/summary.html b/saleor/checkout/templates/checkout/summary.htmlindex 93dfb336cf..d45807f4c8 100644--- a/saleor/checkout/templates/checkout/summary.html+++ b/saleor/checkout/templates/checkout/summary.html@@ -2,8 +2,6 @@{% load gross from prices %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Summary" %}{% endblock %}-{% block forms %}<h2>{% trans "Billing address" %}</h2>diff --git a/saleor/order/templates/order/details.html b/saleor/order/templates/order/details.htmlindex 061e9339bb..dcd396fbd7 100644--- a/saleor/order/templates/order/details.html+++ b/saleor/order/templates/order/details.html@@ -3,7 +3,7 @@{% load gross from prices %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Order details" %}{% endblock %}+{% block title %}{% trans "Order" %} {{ order }} — {{ block.super }}{% endblock %}{% block outerbreadcrumb %}{% if order.user == user %}diff --git a/saleor/order/templates/order/success.html b/saleor/order/templates/order/success.htmlindex 33244c7f0f..fb96d0d45e 100644--- a/saleor/order/templates/order/success.html+++ b/saleor/order/templates/order/success.html@@ -1,12 +1,12 @@{% extends "base.html" %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Order received!" %}{% endblock %}+{% block title %}{% trans "Order complete!" %} — {{ block.super }}{% endblock %}{% load gross from prices %}{% block content %}-<h2>Your order has been received</h2>+<h2>{% trans "Your order is now complete" %}</h2><p>{% trans "Thank you for your purchase!" %}</p><p>{% trans "Your order number is" %}: <a href="{% url 'order:details' token=order.token %}">{{ order }}</a></p>diff --git a/saleor/payment/templates/payment/default.html b/saleor/payment/templates/payment/default.htmlindex 427bad7f02..3570337a41 100644--- a/saleor/payment/templates/payment/default.html+++ b/saleor/payment/templates/payment/default.html@@ -2,8 +2,6 @@{% load as_horizontal_form from bootstrap %}{% load i18n %}-{% block title %}{{ block.super }} » {{ payment.variant|title }}{% endblock %}-{% block forms %}<form method="{{ form.method }}" class="form-horizontal"{% if form.action %} action="{{ form.action }}"{% endif %}>{% csrf_token %}diff --git a/saleor/payment/templates/payment/details.html b/saleor/payment/templates/payment/details.htmlindex 5a2427a121..b833b81269 100644--- a/saleor/payment/templates/payment/details.html+++ b/saleor/payment/templates/payment/details.html@@ -2,7 +2,7 @@{% load as_horizontal_form from bootstrap %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Payment" %}{% endblock %}+{% block title %}{% trans "Checkout" %} — {{ block.super }}{% endblock %}{% block outerbreadcrumb %}{% endblock %}diff --git a/saleor/payment/templates/payment/index.html b/saleor/payment/templates/payment/index.htmlindex 912bf625f4..4f1429bdd9 100644--- a/saleor/payment/templates/payment/index.html+++ b/saleor/payment/templates/payment/index.html@@ -3,8 +3,6 @@{% load gross from prices %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Select method" %}{% endblock %}-{% block forms %}{% if waiting_payment %}<form method="post" action="{% url 'order:payment:delete' token=order.token %}">diff --git a/saleor/payment/templates/payment/paypal-card.html b/saleor/payment/templates/payment/paypal-card.htmlindex 7bd761d997..5e0ca883f2 100644--- a/saleor/payment/templates/payment/paypal-card.html+++ b/saleor/payment/templates/payment/paypal-card.html@@ -4,8 +4,6 @@{% load gross from prices %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Paypal card" %}{% endblock %}-{% block forms %}<form method="post" class="form-horizontal">{% csrf_token %}diff --git a/saleor/product/templates/category/index.html b/saleor/product/templates/category/index.htmlindex da274dd593..aea5b515a5 100644--- a/saleor/product/templates/category/index.html+++ b/saleor/product/templates/category/index.html@@ -3,7 +3,7 @@{% load at_size from images %}{% load slice from shop %}-{% block title %}{{ block.super }} » {% trans "Category" %} {{ category }}{% endblock %}+{% block title %}{{ category }} — {{ block.super }}{% endblock %}{% block breadcrumb %}{{ block.super }}diff --git a/saleor/product/templates/product/details.html b/saleor/product/templates/product/details.htmlindex ef723df22a..f069147c9a 100644--- a/saleor/product/templates/product/details.html+++ b/saleor/product/templates/product/details.html@@ -6,7 +6,7 @@{% load at_size from images %}{% load gross from prices %}-{% block title %}{{ block.super }} » {% trans "Product" %} » {{ product.name }}{% endblock %}+{% block title %}{{ product }} — {{ block.super }}{% endblock %}{% block breadcrumb %}{{ block.super }}diff --git a/saleor/product/views.py b/saleor/product/views.pyindex 51cf72d5ae..da652fdb37 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -1,6 +1,10 @@+from __future__ import unicode_literals+from django.http import HttpResponsePermanentRedirect+from django.contrib import messagesfrom django.shortcuts import get_object_or_404from django.template.response import TemplateResponse+from django.utils.translation import ugettext as _from .forms import ProductFormfrom .models import Product, Category@@ -13,6 +17,10 @@ def product_details(request, slug, product_id):form = ProductForm(cart=request.cart, product=product,data=request.POST or None)if form.is_valid():+ if form.cleaned_data['quantity']:+ msg = _('Added %(product)s to your cart.') % {+ 'product': product}+ messages.success(request, msg)form.save()return TemplateResponse(request, 'product/details.html', {'product': product,diff --git a/saleor/registration/forms.py b/saleor/registration/forms.pyindex b173c2be2a..50df3f8e60 100644--- a/saleor/registration/forms.py+++ b/saleor/registration/forms.py@@ -72,22 +72,6 @@ class RequestEmailChangeForm(RequestEmailConfirmationForm):email=self.cleaned_data['email'], user=self.user)-class RegisterOrResetPasswordForm(SetPasswordForm):-- def __init__(self, email_confirmation_request, data=None):- self.email_confirmation_request = email_confirmation_request- super(RegisterOrResetPasswordForm, self).__init__(- user=None, data=data, empty_permitted=True)-- def get_authenticated_user(self):- self.user = self.email_confirmation_request.get_or_create_user()- if self.cleaned_data.get('new_password1'):- self.save()- else:- self.user.set_unusable_password()- return authenticate(user=self.user)--class OAuth2CallbackForm(forms.Form):code = forms.CharField()diff --git a/saleor/registration/models.py b/saleor/registration/models.pyindex 11b1648fd1..0fd3ec8ef5 100644--- a/saleor/registration/models.py+++ b/saleor/registration/models.py@@ -2,7 +2,7 @@ from __future__ import unicode_literalsfrom datetime import timedeltafrom django.db import models-from django.contrib.auth import get_user_model+from django.contrib.auth import authenticate, get_user_modelfrom django.conf import settingsfrom django.core.urlresolvers import reversefrom django.utils import timezone@@ -60,10 +60,10 @@ class EmailConfirmationRequest(AbstractToken):email = models.EmailField()- def get_or_create_user(self):+ def get_authenticated_user(self):user, _created = User.objects.get_or_create(email=self.email)EmailConfirmationRequest.objects.filter(email=self.email).delete()- return user+ return authenticate(user=user)def get_confirmation_url(self):return reverse('registration:confirm_email',diff --git a/saleor/registration/templates/registration/invalid_token.html b/saleor/registration/templates/registration/invalid_token.htmlindex 8416db0ea0..f6f21f191c 100644--- a/saleor/registration/templates/registration/invalid_token.html+++ b/saleor/registration/templates/registration/invalid_token.html@@ -1,7 +1,7 @@{% extends "base.html" %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Invalid token" %}{% endblock %}+{% block title %}{% trans "Invalid token" %} — {{ block.super }}{% endblock %}{% block content %}<p>Sorry, this link is invalid. Probably it has already been used or has expired.</p>diff --git a/saleor/registration/templates/registration/login.html b/saleor/registration/templates/registration/login.htmlindex 3a5971d708..d9caf3a809 100644--- a/saleor/registration/templates/registration/login.html+++ b/saleor/registration/templates/registration/login.html@@ -2,7 +2,7 @@{% load as_horizontal_form from bootstrap %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Login" %}{% endblock %}+{% block title %}{% trans "Login" %} — {{ block.super }}{% endblock %}{% block content %}<form method="post" action="{% url 'registration:login' %}" class="form-horizontal">@@ -18,16 +18,24 @@<button class="btn btn-primary">{% trans "Log in" %}</button>+ <a class="btn btn-secondary" href="{% url 'registration:request_email_confirmation' %}">{% trans "I don't know my password" %}</a>+ </div>+ </div>+ <hr>+ <div class="form-group">+ <div class="col-sm-offset-2 col-sm-10">+ <p>{% trans "Want to use your social profile?" %}</p>+ <p>+ <a class="btn btn-default zocial-facebook" href="{{ facebook_login_url }}"> Login using Facebook</a>+ <a class="btn btn-default zocial-google" href="{{ google_login_url }}"> Login using Google</a>+ </p>+ </div>+ </div>+ <hr>+ <div class="form-group">+ <div class="col-sm-offset-2 col-sm-10">+ <p>{% trans "Don't have an account yet?" %} <a class="btn btn-secondary" href="{% url 'registration:request_email_confirmation' %}">{% trans "Register" %}</a></p></div></div></form>-<ul>- <li>- <a href="{{ facebook_login_url }}">Login via Facebook</a>- </li>- <li>- <a href="{{ google_login_url }}">Login via Google</a>- </li>- <li><a href="{% url 'registration:request_email_confirmation' %}">Create an account or reset password</a></li>-</ul>{% endblock %}diff --git a/saleor/registration/templates/registration/logout.html b/saleor/registration/templates/registration/logout.htmlindex 7812ab1862..607b17744b 100644--- a/saleor/registration/templates/registration/logout.html+++ b/saleor/registration/templates/registration/logout.html@@ -1,7 +1,7 @@{% extends "base.html" %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Logged out" %}{% endblock %}+{% block title %}{% trans "Logged out" %} — {{ block.super }}{% endblock %}{% block content %}<p>Successfully logged out!</p>diff --git a/saleor/registration/templates/registration/request_email_confirmation.html b/saleor/registration/templates/registration/request_email_confirmation.htmlindex b4708d5a69..b1600866de 100644--- a/saleor/registration/templates/registration/request_email_confirmation.html+++ b/saleor/registration/templates/registration/request_email_confirmation.html@@ -2,7 +2,7 @@{% load as_horizontal_form from bootstrap %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Request email confirmation" %}{% endblock %}+{% block title %}{% trans "Request email confirmation" %} — {{ block.super }}{% endblock %}{% block breadcrumb %}{{ block.super }}diff --git a/saleor/registration/templates/registration/set_password.html b/saleor/registration/templates/registration/set_password.htmlindex fd9e52c9cc..f3b6f8a77f 100644--- a/saleor/registration/templates/registration/set_password.html+++ b/saleor/registration/templates/registration/set_password.html@@ -2,7 +2,7 @@{% load i18n %}{% load as_horizontal_form from bootstrap %}-{% block title %}{{ block.super }} » {% trans "Set password" %}{% endblock %}+{% block title %}{% trans "Set password" %} — {{ block.super }}{% endblock %}{% block content %}<form method="post" class="form-horizontal">diff --git a/saleor/registration/tests.py b/saleor/registration/tests.pyindex 462939bbcd..e3941ab03c 100644--- a/saleor/registration/tests.py+++ b/saleor/registration/tests.py@@ -5,7 +5,7 @@ from django.core.urlresolvers import resolvefrom mock import call, Mock, MagicMock, patch, sentinelfrom purl import URL-from .forms import RegisterOrResetPasswordForm, OAuth2CallbackForm+from .forms import OAuth2CallbackFormfrom .utils import (FACEBOOK,FacebookClient,@@ -242,41 +242,6 @@ class CallbackTestCase(TestCase):patch.stopall()-class EmailConfirmationTestCase(TestCase):-- @patch('saleor.registration.forms.authenticate')- def test_password_set(self, authenticate_mock):- """Email confirmation sets new password and logs the user"""- user = Mock()- authenticate_mock.return_value = sentinel.authed_user- email_confirmation_request = Mock()- email_confirmation_request.get_or_create_user.return_value = user- form = RegisterOrResetPasswordForm(- email_confirmation_request=email_confirmation_request,- data={'new_password1': 'pass', 'new_password2': 'pass'})- self.assertTrue(form.is_valid(), form.errors)- authed_user = form.get_authenticated_user()- self.assertEquals(authed_user, sentinel.authed_user)- user.set_password.assert_called_once_with('pass')- authenticate_mock.assert_called_once_with(user=user)-- @patch('saleor.registration.forms.authenticate')- def test_password_unset(self, authenticate_mock):- """Email confirmation unsets a password and logs the user"""- user = Mock()- authenticate_mock.return_value = sentinel.authed_user- email_confirmation_request = Mock()- email_confirmation_request.get_or_create_user.return_value = user- form = RegisterOrResetPasswordForm(- email_confirmation_request=email_confirmation_request,- data={})- self.assertTrue(form.is_valid(), form.errors)- authed_user = form.get_authenticated_user()- self.assertEquals(authed_user, sentinel.authed_user)- user.set_unusable_password.assert_called_once()- authenticate_mock.assert_called_once_with(user=user)--class EmailChangeTestCase(TestCase):@patch('saleor.registration.views.now')diff --git a/saleor/registration/views.py b/saleor/registration/views.pyindex edec40b5c9..c4755f9c67 100644--- a/saleor/registration/views.py+++ b/saleor/registration/views.py@@ -5,10 +5,10 @@ except ImportError:from django.conf import settingsfrom django.contrib import messages-from django.contrib.auth import (login as auth_login,- logout as auth_logout,- get_user_model)+from django.contrib.auth import (get_user_model, login as auth_login,+ logout as auth_logout)from django.contrib.auth.decorators import login_required+from django.contrib.auth.forms import SetPasswordFormfrom django.contrib.auth.views import (login as django_login_view,password_change)from django.core.urlresolvers import reverse@@ -46,9 +46,12 @@ def oauth_callback(request, service):if form.is_valid():try:user = form.get_authenticated_user()- return _login_user(request, user)except ValueError as e:messages.error(request, unicode(e))+ else:+ auth_login(request, user=user)+ messages.success(request, _('You are now logged in.'))+ return redirect(settings.LOGIN_REDIRECT_URL)else:for _field, errors in form.errors.items():for error in errors:@@ -84,9 +87,9 @@ def request_email_change(request):messages.success(request, msg)return redirect(settings.LOGIN_REDIRECT_URL)- return TemplateResponse(request,- 'registration/request_email_confirmation.html',- {'form': form})+ return TemplateResponse(+ request, 'registration/request_email_confirmation.html',+ {'form': form})def confirm_email(request, token):@@ -96,13 +99,15 @@ def confirm_email(request, token):# TODO: cronjob (celery task) to delete stale tokensexcept EmailConfirmationRequest.DoesNotExist:return TemplateResponse(request, 'registration/invalid_token.html')+ user = email_confirmation_request.get_authenticated_user()+ email_confirmation_request.delete()+ auth_login(request, user)+ messages.success(request, _('You are now logged in.'))- form = forms.RegisterOrResetPasswordForm(- email_confirmation_request=email_confirmation_request,- data=request.POST or None)+ form = SetPasswordForm(user=user, data=request.POST or None)if form.is_valid():- user = form.get_authenticated_user()- return _login_user(request, user)+ form.save()+ return redirect(settings.LOGIN_REDIRECT_URL)return TemplateResponse(request, 'registration/set_password.html', {'form': form})@@ -118,7 +123,8 @@ def change_email(request, token):# if another user is logged in, we need to log him out, to allow the email# owner confirm his identity- if request.user != email_change_request.user:+ if (request.user.is_authenticated() and+ request.user != email_change_request.user):auth_logout(request)if not request.user.is_authenticated():query = urlencode({@@ -135,13 +141,6 @@ def change_email(request, token):return redirect(settings.LOGIN_REDIRECT_URL)-def _login_user(request, user):- auth_login(request, user)- msg = _('You have been successfully logged in.')- messages.success(request, msg)- return redirect(settings.LOGIN_REDIRECT_URL)--def change_password(request):return password_change(request, template_name='registration/change_password.html',diff --git a/saleor/settings.py b/saleor/settings.pyindex 17f1c57697..538247fc39 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -57,8 +57,8 @@ TEMPLATE_LOADERS = [SECRET_KEY = '{{ secret_key }}'MIDDLEWARE_CLASSES = [- 'django.middleware.common.CommonMiddleware','django.contrib.sessions.middleware.SessionMiddleware',+ 'django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware',diff --git a/saleor/static/css/zocial.css b/saleor/static/css/zocial.cssnew file mode 100644index 0000000000..1ee44b4284--- /dev/null+++ b/saleor/static/css/zocial.css@@ -0,0 +1,5 @@+@import url(http://weloveiconfonts.com/api/?family=zocial);++[class*="zocial-"]:before {+ font-family: 'zocial', sans-serif;+}diff --git a/saleor/userprofile/templates/userprofile/address-delete.html b/saleor/userprofile/templates/userprofile/address-delete.htmlindex b2410690ea..b969490b9a 100644--- a/saleor/userprofile/templates/userprofile/address-delete.html+++ b/saleor/userprofile/templates/userprofile/address-delete.html@@ -1,7 +1,7 @@{% extends "base.html" %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Delete Address" %}{% endblock %}+{% block title %}{% trans "Delete address" %} — {{ block.super }}{% endblock %}{% block content %}<h2>{% trans "Are you sure you want to delete the following address?" %}</h2>diff --git a/saleor/userprofile/templates/userprofile/address-edit.html b/saleor/userprofile/templates/userprofile/address-edit.htmlindex dead56da9d..ebfad2ad24 100644--- a/saleor/userprofile/templates/userprofile/address-edit.html+++ b/saleor/userprofile/templates/userprofile/address-edit.html@@ -3,7 +3,7 @@{% load as_horizontal_form from bootstrap %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "Edit Address" %}{% endblock %}+{% block title %}{% trans "Edit Address" %} — {{ block.super }}{% endblock %}{% block breadcrumb %}{{ block.super }}diff --git a/saleor/userprofile/templates/userprofile/details.html b/saleor/userprofile/templates/userprofile/details.htmlindex eda57c06a7..0d831664f5 100644--- a/saleor/userprofile/templates/userprofile/details.html+++ b/saleor/userprofile/templates/userprofile/details.html@@ -1,7 +1,7 @@{% extends "base.html" %}{% load i18n %}-{% block title %}{{ block.super }} » {% trans "User profile" %}{% endblock %}+{% block title %}{% trans "Your profile" %} — {{ block.super }}{% endblock %}{% block breadcrumb %}{{ block.super }}diff --git a/templates/base.html b/templates/base.htmlindex c63ffcfdc2..7696397626 100644--- a/templates/base.html+++ b/templates/base.html@@ -1,7 +1,7 @@+<!DOCTYPE html>{% load i18n %}{% load categories_list from category %}{% load lorem from webdesign %}-<!DOCTYPE html><html lang="en"><head><title>{% block title %}Saleor{% endblock %}</title>@@ -18,6 +18,7 @@{% else %}<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/style.css">{% endif %}+ <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/zocial.css">{% block stylesheet %}{% endblock stylesheet %}