<commit_before>from django.conf import settings
from django.contrib.auth import login, REDIRECT_FIELD_NAME
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.models import User
from django.contrib.sites.models import Site, RequestSite
from django.core import urlresolvers
from django.http import HttpResponseRedirect, QueryDict
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.cache import never_cache
from forms import RegistrationAddressForm, RegistrationForm, EmailAuthenticationForm
from l10n.models import Country
from livesettings import config_get_group, config_value
from satchmo_store.accounts.mail import send_welcome_email
from satchmo_store.accounts import signals
from satchmo_store.contact import CUSTOMER_ID
from satchmo_store.contact.models import Contact
from satchmo_store.shop.models import Config
import logging

log = logging.getLogger('satchmo_store.accounts.views')

YESNO = (
    (1, _('Yes')),
    (0, _('No'))
)

def emaillogin(request, template_name='registration/login.html', 
    auth_form=EmailAuthenticationForm, redirect_field_name=REDIRECT_FIELD_NAME):
    "Displays the login form and handles the login action. Altered to use the EmailAuthenticationForm"
    redirect_to = request.REQUEST.get(redirect_field_name, '')
    if request.method == "POST":
        form = auth_form(data=request.POST)
        if form.is_valid():
            # Light security check -- make sure redirect_to isn't garbage.
            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
                redirect_to = settings.LOGIN_REDIRECT_URL
            login(request, form.get_user())
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            return HttpResponseRedirect(redirect_to)
    else:
        form = auth_form(request)
    request.session.set_test_cookie()
    if Site._meta.installed:
        current_site = Site.objects.get_current()
    else:
        current_site = RequestSite(request)
    return render_to_response(template_name, {
        'form': form,
        redirect_field_name: redirect_to,
        'site_name': current_site.name,
    }, context_instance=RequestContext(request))
emaillogin = never_cache(emaillogin)

def _login(request, redirect_to):
    """"Altered version of the default login, intended to be called by `combined_login`.<commit_msg>fix redirection error. Closes #856<commit_after>from django.conf import settings
from django.contrib.auth import login, REDIRECT_FIELD_NAME
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.models import User
from django.contrib.sites.models import Site, RequestSite
from django.core import urlresolvers
from django.http import HttpResponseRedirect, QueryDict
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.cache import never_cache
from forms import RegistrationAddressForm, RegistrationForm, EmailAuthenticationForm
from l10n.models import Country
from livesettings import config_get_group, config_value
from satchmo_store.accounts.mail import send_welcome_email
from satchmo_store.accounts import signals
from satchmo_store.contact import CUSTOMER_ID
from satchmo_store.contact.models import Contact
from satchmo_store.shop.models import Config
import logging

log = logging.getLogger('satchmo_store.accounts.views')

YESNO = (
    (1, _('Yes')),
    (0, _('No'))
)

def emaillogin(request, template_name='registration/login.html', 
    auth_form=EmailAuthenticationForm, redirect_field_name=REDIRECT_FIELD_NAME):
    "Displays the login form and handles the login action. Altered to use the EmailAuthenticationForm"
    redirect_to = request.REQUEST.get(redirect_field_name, '')

    # Avoid redirecting to logout if the user clicked on login after logout
    if redirect_to == urlresolvers.reverse('auth_logout'):
        redirect_to = None

    if request.method == "POST":
        form = auth_form(data=request.POST)
        if form.is_valid():
            # Light security check -- make sure redirect_to isn't garbage.
            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
                redirect_to = settings.LOGIN_REDIRECT_URL
            login(request, form.get_user())
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            return HttpResponseRedirect(redirect_to)
    else:
        form = auth_form(request)
    request.session.set_test_cookie()
    if Site._meta.installed:
        current_site = Site.objects.get_current()
    else:
        current_site = RequestSite(request)
    return render_to_response(template_name, {
        'form': form,
        redirect_field_name: redirect_to,
        'site_name': current_site.name,
    }, context_instance=RequestContext(request))
emaillogin = never_cache(emaillogin)

def _login(request, redirect_to):
    """"Altered version of the default login, intended to be called by `combined_login`.
{'fraction_non_alphanumeric': 0.07516778523489932, 'fraction_numerical': 0.002109300095877277, 'mean_word_length': 4.231695085255767, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5002299', 'n_tokens_mistral': 1477, 'n_tokens_neox': 1444, 'n_words': 386}