We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Logging does not redirect to ?next= link
### What I'm trying to achieve

Currently Saleor has an option to redirect user to particular URL after being asked to log in - which isn't working ATM, beacuse user gets redirected to storefront main page.

### Steps to reproduce the problem

1. Go to auth-protected URL (such as `/dashboard`)
2. Log in

### What I expected to happen

To redirect user to requested page.

### What happened instead/how it failed

User gets redirected to `/`

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `saleor/registration/views.py`
Content:
```
1 from __future__ import unicode_literals
2 
3 from django.conf import settings
4 from django.contrib import auth, messages
5 from django.contrib.auth import views as django_views
6 from django.contrib.auth.decorators import login_required
7 from django.shortcuts import redirect
8 from django.template.response import TemplateResponse
9 from django.urls import reverse_lazy
10 from django.utils.translation import ugettext_lazy as _
11 
12 from saleor.cart.utils import find_and_assign_anonymous_cart
13 
14 from .forms import LoginForm, PasswordSetUpForm, SignupForm
15 
16 
17 @find_and_assign_anonymous_cart()
18 def login(request):
19     kwargs = {
20         'template_name': 'account/login.html', 'authentication_form': LoginForm}
21     return django_views.LoginView.as_view(**kwargs)(request, **kwargs)
22 
23 
24 @login_required
25 def logout(request):
26     auth.logout(request)
27     messages.success(request, _('You have been successfully logged out.'))
28     return redirect(settings.LOGIN_REDIRECT_URL)
29 
30 
31 def signup(request):
32     form = SignupForm(request.POST or None)
33     if form.is_valid():
34         form.save()
35         password = form.cleaned_data.get('password')
36         email = form.cleaned_data.get('email')
37         user = auth.authenticate(request=request, email=email,
38                                  password=password)
39         if user:
40             auth.login(request, user)
41         messages.success(request, _('User has been created'))
42         redirect_url = request.POST.get('next', '')
43         if redirect_url:
44             return redirect(redirect_url)
45         else:
46             return redirect(settings.LOGIN_REDIRECT_URL)
47     ctx = {'form': form}
48     return TemplateResponse(request, 'account/signup.html', ctx)
49 
50 
51 def password_reset(request):
52     kwargs = {
53         'template_name': 'account/password_reset.html',
54         'success_url': reverse_lazy('account_reset_password_done'),
55         'email_template_name': 'account/email/password_reset_message.txt',
56         'subject_template_name': 'account/email/password_reset_subject.txt'}
57     return django_views.PasswordResetView.as_view(**kwargs)(request, **kwargs)
58 
59 
60 class PasswordResetConfirm(django_views.PasswordResetConfirmView):
61     template_name = 'account/password_reset_from_key.html'
62     success_url = reverse_lazy('account_reset_password_complete')
63     set_password_form = PasswordSetUpForm
64     token = None
65     uidb64 = None
66 
67 
68 def password_reset_confirm(request, uidb64=None, token=None):
69     kwargs = {
70         'template_name': 'account/password_reset_from_key.html',
71         'success_url': reverse_lazy('account_reset_password_complete'),
72         'set_password_form': 'PasswordSetUpForm',
73         'token': token,
74         'uidb64': uidb64}
75     return PasswordResetConfirm.as_view(**kwargs)(
76         request, **kwargs)
77
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/saleor/registration/views.py b/saleor/registration/views.py
--- a/saleor/registration/views.py
+++ b/saleor/registration/views.py
@@ -34,16 +34,13 @@
         form.save()
         password = form.cleaned_data.get('password')
         email = form.cleaned_data.get('email')
-        user = auth.authenticate(request=request, email=email,
-                                 password=password)
+        user = auth.authenticate(
+            request=request, email=email, password=password)
         if user:
             auth.login(request, user)
         messages.success(request, _('User has been created'))
-        redirect_url = request.POST.get('next', '')
-        if redirect_url:
-            return redirect(redirect_url)
-        else:
-            return redirect(settings.LOGIN_REDIRECT_URL)
+        redirect_url = request.POST.get('next', settings.LOGIN_REDIRECT_URL)
+        return redirect(redirect_url)
     ctx = {'form': form}
     return TemplateResponse(request, 'account/signup.html', ctx)

{"golden_diff": "diff --git a/saleor/registration/views.py b/saleor/registration/views.py\n--- a/saleor/registration/views.py\n+++ b/saleor/registration/views.py\n@@ -34,16 +34,13 @@\n         form.save()\n         password = form.cleaned_data.get('password')\n         email = form.cleaned_data.get('email')\n-        user = auth.authenticate(request=request, email=email,\n-                                 password=password)\n+        user = auth.authenticate(\n+            request=request, email=email, password=password)\n         if user:\n             auth.login(request, user)\n         messages.success(request, _('User has been created'))\n-        redirect_url = request.POST.get('next', '')\n-        if redirect_url:\n-            return redirect(redirect_url)\n-        else:\n-            return redirect(settings.LOGIN_REDIRECT_URL)\n+        redirect_url = request.POST.get('next', settings.LOGIN_REDIRECT_URL)\n+        return redirect(redirect_url)\n     ctx = {'form': form}\n     return TemplateResponse(request, 'account/signup.html', ctx)\n", "issue": "Logging does not redirect to ?next= link\n### What I'm trying to achieve\r\n\r\nCurrently Saleor has an option to redirect user to particular URL after being asked to log in - which isn't working ATM, beacuse user gets redirected to storefront main page.\r\n\r\n### Steps to reproduce the problem\r\n\r\n1. Go to auth-protected URL (such as `/dashboard`)\r\n2. Log in\r\n\r\n### What I expected to happen\r\n\r\nTo redirect user to requested page.\r\n\r\n### What happened instead/how it failed\r\n\r\nUser gets redirected to `/`\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nfrom django.conf import settings\nfrom django.contrib import auth, messages\nfrom django.contrib.auth import views as django_views\nfrom django.contrib.auth.decorators import login_required\nfrom django.shortcuts import redirect\nfrom django.template.response import TemplateResponse\nfrom django.urls import reverse_lazy\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom saleor.cart.utils import find_and_assign_anonymous_cart\n\nfrom .forms import LoginForm, PasswordSetUpForm, SignupForm\n\n\n@find_and_assign_anonymous_cart()\ndef login(request):\n    kwargs = {\n        'template_name': 'account/login.html', 'authentication_form': LoginForm}\n    return django_views.LoginView.as_view(**kwargs)(request, **kwargs)\n\n\n@login_required\ndef logout(request):\n    auth.logout(request)\n    messages.success(request, _('You have been successfully logged out.'))\n    return redirect(settings.LOGIN_REDIRECT_URL)\n\n\ndef signup(request):\n    form = SignupForm(request.POST or None)\n    if form.is_valid():\n        form.save()\n        password = form.cleaned_data.get('password')\n        email = form.cleaned_data.get('email')\n        user = auth.authenticate(request=request, email=email,\n                                 password=password)\n        if user:\n            auth.login(request, user)\n        messages.success(request, _('User has been created'))\n        redirect_url = request.POST.get('next', '')\n        if redirect_url:\n            return redirect(redirect_url)\n        else:\n            return redirect(settings.LOGIN_REDIRECT_URL)\n    ctx = {'form': form}\n    return TemplateResponse(request, 'account/signup.html', ctx)\n\n\ndef password_reset(request):\n    kwargs = {\n        'template_name': 'account/password_reset.html',\n        'success_url': reverse_lazy('account_reset_password_done'),\n        'email_template_name': 'account/email/password_reset_message.txt',\n        'subject_template_name': 'account/email/password_reset_subject.txt'}\n    return django_views.PasswordResetView.as_view(**kwargs)(request, **kwargs)\n\n\nclass PasswordResetConfirm(django_views.PasswordResetConfirmView):\n    template_name = 'account/password_reset_from_key.html'\n    success_url = reverse_lazy('account_reset_password_complete')\n    set_password_form = PasswordSetUpForm\n    token = None\n    uidb64 = None\n\n\ndef password_reset_confirm(request, uidb64=None, token=None):\n    kwargs = {\n        'template_name': 'account/password_reset_from_key.html',\n        'success_url': reverse_lazy('account_reset_password_complete'),\n        'set_password_form': 'PasswordSetUpForm',\n        'token': token,\n        'uidb64': uidb64}\n    return PasswordResetConfirm.as_view(**kwargs)(\n        request, **kwargs)\n", "path": "saleor/registration/views.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nfrom django.conf import settings\nfrom django.contrib import auth, messages\nfrom django.contrib.auth import views as django_views\nfrom django.contrib.auth.decorators import login_required\nfrom django.shortcuts import redirect\nfrom django.template.response import TemplateResponse\nfrom django.urls import reverse_lazy\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom saleor.cart.utils import find_and_assign_anonymous_cart\n\nfrom .forms import LoginForm, PasswordSetUpForm, SignupForm\n\n\n@find_and_assign_anonymous_cart()\ndef login(request):\n    kwargs = {\n        'template_name': 'account/login.html', 'authentication_form': LoginForm}\n    return django_views.LoginView.as_view(**kwargs)(request, **kwargs)\n\n\n@login_required\ndef logout(request):\n    auth.logout(request)\n    messages.success(request, _('You have been successfully logged out.'))\n    return redirect(settings.LOGIN_REDIRECT_URL)\n\n\ndef signup(request):\n    form = SignupForm(request.POST or None)\n    if form.is_valid():\n        form.save()\n        password = form.cleaned_data.get('password')\n        email = form.cleaned_data.get('email')\n        user = auth.authenticate(\n            request=request, email=email, password=password)\n        if user:\n            auth.login(request, user)\n        messages.success(request, _('User has been created'))\n        redirect_url = request.POST.get('next', settings.LOGIN_REDIRECT_URL)\n        return redirect(redirect_url)\n    ctx = {'form': form}\n    return TemplateResponse(request, 'account/signup.html', ctx)\n\n\ndef password_reset(request):\n    kwargs = {\n        'template_name': 'account/password_reset.html',\n        'success_url': reverse_lazy('account_reset_password_done'),\n        'email_template_name': 'account/email/password_reset_message.txt',\n        'subject_template_name': 'account/email/password_reset_subject.txt'}\n    return django_views.PasswordResetView.as_view(**kwargs)(request, **kwargs)\n\n\nclass PasswordResetConfirm(django_views.PasswordResetConfirmView):\n    template_name = 'account/password_reset_from_key.html'\n    success_url = reverse_lazy('account_reset_password_complete')\n    set_password_form = PasswordSetUpForm\n    token = None\n    uidb64 = None\n\n\ndef password_reset_confirm(request, uidb64=None, token=None):\n    kwargs = {\n        'template_name': 'account/password_reset_from_key.html',\n        'success_url': reverse_lazy('account_reset_password_complete'),\n        'set_password_form': 'PasswordSetUpForm',\n        'token': token,\n        'uidb64': uidb64}\n    return PasswordResetConfirm.as_view(**kwargs)(\n        request, **kwargs)\n", "path": "saleor/registration/views.py"}]}