def login(request, **kwargs):

    form_class = kwargs.pop("form_class", LoginForm)
    template_name = kwargs.pop("template_name", "account/login.html")
    success_url = (request.GET.get("success_url")
                   or request.POST.get("success_url")
                   or kwargs.pop("success_url", None))
    associate_openid = kwargs.pop("associate_openid", False)
    openid_success_url = kwargs.pop("openid_success_url", None)
    url_required = kwargs.pop("url_required", False)
    extra_context = kwargs.pop("extra_context", {})
    redirect_field_name = kwargs.pop("redirect_field_name", "next")

    group, bridge = group_and_bridge(kwargs)

    if extra_context is None:
        extra_context = {}
    if success_url is None:
        if hasattr(settings, "LOGIN_REDIRECT_URLNAME"):
            fallback_url = reverse(settings.LOGIN_REDIRECT_URLNAME)
        else:
            fallback_url = settings.LOGIN_REDIRECT_URL
        success_url = get_default_redirect(
            request, fallback_url, redirect_field_name)

    if request.method == "POST" and not url_required:
        form = form_class(request.POST, group=group)
        if form.is_valid():
            form.login(request)
            if associate_openid and association_model is not None:
                for openid in request.session.get("openids", []):
                    assoc, created = UserOpenidAssociation.objects.get_or_create(
                        user=form.user, openid=openid.openid
                    )
                success_url = openid_success_url or success_url
            messages.add_message(
                request, messages.SUCCESS,
                ugettext(u"Successfully logged in as %(user)s.") % {
                    "user": user_display(form.user)
                })
            return HttpResponseRedirect(success_url)
    else:
        form = form_class(group=group)

    ctx = group_context(group, bridge)
    ctx.update({
        "form": form,
        "url_required": url_required,
        "redirect_field_name": redirect_field_name,
        "redirect_field_value": request.GET.get(
            redirect_field_name,
            request.POST.get(redirect_field_name)
        ),
        "success_url": success_url,
    })
    ctx.update(extra_context)

    return render_to_response(template_name, RequestContext(request, ctx))
dataset/ETHPy150Open amarandon/smeuhsocial/apps/account/views.py/login/original