Example #1
0
def signup(request, **kwargs):

    form_class = kwargs.pop("form_class", SignupForm)
    template_name = kwargs.pop("template_name", "account/signup.html")
    redirect_field_name = kwargs.pop("redirect_field_name", "next")
    success_url = kwargs.pop("success_url", None)

    if success_url is None:
        success_url = get_default_redirect(request, redirect_field_name)

    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid():
            user = form.save(request=request)
            return complete_signup(request, user, success_url)
    else:
        form = form_class()
    ctx = {
        "form":
        form,
        "login_url":
        passthrough_login_redirect_url(request, reverse("account_login")),
        "redirect_field_name":
        redirect_field_name,
        "redirect_field_value":
        request.REQUEST.get(redirect_field_name)
    }
    return render_to_response(template_name, RequestContext(request, ctx))
Example #2
0
def login(request, **kwargs):

    
    form_class = kwargs.pop("form_class", LoginForm)
    template_name = kwargs.pop("template_name", "account/login.html")
    success_url = kwargs.pop("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")
    
    if extra_context is None:
        extra_context = {}
    if success_url is None:
        success_url = get_default_redirect(request, redirect_field_name)
    
    if request.method == "POST" and not url_required:
        form = form_class(request.POST)
        if form.is_valid():
            form.login(request)
            return HttpResponseRedirect(success_url)
    else:
        form = form_class()
    
    ctx = {
        "form": form,
        "signup_url": passthrough_login_redirect_url(request,
                                                     reverse("account_signup")),
        "site": Site.objects.get_current(),
        "url_required": url_required,
        "redirect_field_name": redirect_field_name,
        "redirect_field_value": request.REQUEST.get(redirect_field_name),
    }
    ctx.update(extra_context)
    return render_to_response(template_name, RequestContext(request, ctx))
Example #3
0
def signup(request, **kwargs):
    
    form_class = kwargs.pop("form_class", SignupForm)
    template_name = kwargs.pop("template_name", "account/signup.html")
    redirect_field_name = kwargs.pop("redirect_field_name", "next")
    success_url = kwargs.pop("success_url", None)
    
    group, bridge = group_and_bridge(kwargs)
    ctx = group_context(group, bridge)
    
    if success_url is None:
        success_url = get_default_redirect(request, redirect_field_name)
    
    if request.method == "POST":
        form = form_class(request.POST, group=group)
        if form.is_valid():
            user = form.save(request=request)
            return complete_signup(request, user, success_url)
    else:
        form = form_class(group=group)
    
    ctx.update({
        "form": form,
        "redirect_field_name": redirect_field_name,
        "redirect_field_value": request.REQUEST.get(redirect_field_name),
    })
    
    return render_to_response(template_name, RequestContext(request, ctx))
Example #4
0
def signup(request, **kwargs):

    form_class = kwargs.pop("form_class", SignupForm)
    template_name = kwargs.pop("template_name", "account/signup.html")
    redirect_field_name = kwargs.pop("redirect_field_name", "next")
    success_url = kwargs.pop("success_url", None)

    if success_url is None:
        success_url = get_default_redirect(request, redirect_field_name)

    if request.method == "POST":
        form = form_class(request.POST, request=request)
        if form.is_valid():
            user = form.save(request=request)
            return complete_signup(request, user, success_url, provider='email')
    else:
        form = form_class(initial=request.GET)

    extra_context = kwargs.pop('extra_context', {})
    if extra_context is None:
        extra_context = {}
    ctx = {"form": form,
           "login_url": passthrough_login_redirect_url(request,
                                                       reverse("account_login")),
           "redirect_field_name": redirect_field_name,
           "redirect_field_value": request.REQUEST.get(redirect_field_name) }
    ctx.update(extra_context)
    return render_to_response(template_name, RequestContext(request, ctx))
Example #5
0
def signup(request, **kwargs):
    
    form_class = kwargs.pop("form_class", SignupForm)
    template_name = kwargs.pop("template_name", "account/signup.html")
    redirect_field_name = kwargs.pop("redirect_field_name", "next")
    success_url = kwargs.pop("success_url", None)
    
    if success_url is None:
        success_url = get_default_redirect(request, redirect_field_name)
    
    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid():
            user = form.save(request=request)
            # Begin default profile creation
            profile = UserProfile(user=user)
            profile.save()
            # End default profile creation
            return complete_signup(request, user, success_url)
    else:
        form = form_class()
    ctx = {"signuppage": True,
           "form": form,
           "login_url": passthrough_login_redirect_url(request,
                                                       reverse("account_login")),
           "redirect_field_name": redirect_field_name,
           "redirect_field_value": request.REQUEST.get(redirect_field_name) }
    return render_to_response(template_name, RequestContext(request, ctx))
Example #6
0
def signup(request, **kwargs):
    form_class = kwargs.pop("form_class", SignupForm)
    template_name = kwargs.pop("template_name", "account/signup.html")
    redirect_field_name = kwargs.pop("redirect_field_name", "next")
    success_url = kwargs.pop("success_url", None)
    
    if success_url is None:
        success_url = get_default_redirect(request, redirect_field_name)
    
    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid():
            user = form.save(request=request)
            return complete_signup(request, user, success_url)
        if request.is_ajax():
            return HttpResponse(simplejson.dumps(
                {
                    'status': 'error',
                    'errors': form.errors,
                    'prefix': form.prefix,
                }),
                mimetype="application/json"
            )
    else:
        form = form_class()
    ctx = {"form": form,
           "redirect_field_name": redirect_field_name,
           "redirect_field_value": request.REQUEST.get(redirect_field_name) }
    return render_to_response(template_name, RequestContext(request, ctx))
Example #7
0
def login(request, **kwargs):
    
    form_class = kwargs.pop("form_class", LoginForm)
    template_name = kwargs.pop("template_name", "account/login.html")
    success_url = kwargs.pop("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")
    
    if extra_context is None:
        extra_context = {}
    if success_url is None:
        success_url = get_default_redirect(request, redirect_field_name)
    
    if request.method == "POST" and not url_required:
        form = form_class(request.POST)
        if form.is_valid():
            form.login(request)
            messages.add_message(request, messages.SUCCESS,
                ugettext(u"Successfully signed in as %(user)s.") % {
                    "user": user_display(form.user)
                }
            )
            return HttpResponseRedirect(success_url)
    else:
        form = form_class()
    
    ctx = {
        "form": form,
        "url_required": url_required,
        "redirect_field_name": redirect_field_name,
        "redirect_field_value": request.REQUEST.get(redirect_field_name),
    }
    ctx.update(extra_context)
    return render_to_response(template_name, RequestContext(request, ctx))
Example #8
0
def login(request, **kwargs):

    form_class = kwargs.pop("form_class", LoginForm)
    template_name = kwargs.pop("template_name", "account/login.html")
    success_url = kwargs.pop("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")

    if extra_context is None:
        extra_context = {}
    if success_url is None:
        success_url = get_default_redirect(request, redirect_field_name)

    if request.method == "POST" and not url_required:
        form = form_class(request.POST)
        if form.is_valid():
            form.login(request)
            messages.add_message(
                request,
                messages.SUCCESS,
                ugettext(u"Successfully signed in as %(user)s.") % {"user": user_display(form.user)},
            )
            return HttpResponseRedirect(success_url)
    else:
        form = form_class()

    ctx = {
        "form": form,
        "url_required": url_required,
        "redirect_field_name": redirect_field_name,
        "redirect_field_value": request.REQUEST.get(redirect_field_name),
    }
    ctx.update(extra_context)
    return render_to_response(template_name, RequestContext(request, ctx))
Example #9
0
def login(request, **kwargs):
    form_class = kwargs.pop("form_class", LoginForm)
    template_name = kwargs.pop("template_name", "account/login.html")
    success_url = kwargs.pop("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")
    
    if extra_context is None:
        extra_context = {}
    if success_url is None:
        success_url = get_default_redirect(request, redirect_field_name)
    
    if request.method == "POST" and not url_required:
        form = form_class(request.POST)
        if form.is_valid():
            form.login(request)
            messages.add_message(request, messages.DEBUG,
                ugettext(u"Successfully signed in as %(user)s.") % {
                    "user": user_display(form.user)
                }
            )
            if request.is_ajax():
                return HttpResponse(simplejson.dumps(
                    {
                        'status': 'ok',
                        'redirect': success_url,
                    }),
                    mimetype="application/json"
                )
            else:
                return HttpResponseRedirect(success_url)
        else:
            if request.is_ajax():
                return HttpResponse(simplejson.dumps(
                    {
                        'status': 'error',
                        'errors': form.errors,
                    }),
                    mimetype="application/json"
                )
            
    else:
        form = form_class()
    
    ctx = {
        "form": form,
        "url_required": url_required,
        "redirect_field_name": redirect_field_name,
        "redirect_field_value": request.REQUEST.get(redirect_field_name),
    }
    ctx.update(extra_context)
    return render_to_response(template_name, RequestContext(request, ctx))
Example #10
0
def login(request, **kwargs):
    form_class = kwargs.pop("form_class", LoginForm)
    success_url = get_default_redirect(request, "next")

    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid():
            return form.login(request, redirect_url=success_url)
    else:
        form = form_class()

    return shared_sign(request, login_form=form)
Example #11
0
def login(request, **kwargs):
    
    form_class = kwargs.pop("form_class", LoginForm)
    
    if request.is_ajax():
        template_name = "account/_ajax_login.html"
    else:
        template_name = kwargs.pop("template_name", "account/login.html")
    
    success_url = 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:
        success_url = get_default_redirect(request, 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 signed 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.REQUEST.get(redirect_field_name),
    })
    ctx.update(extra_context)
    
    return render_to_response(template_name, RequestContext(request, ctx))
Example #12
0
def signup(request, **kwargs):

    form_class = kwargs.pop("form_class", SignupForm)
    success_url = get_default_redirect(request, "next")

    if request.method == "POST":
        form = form_class(request.POST)
        if form.is_valid():
            user = form.save(request)
            return complete_signup(request, user, success_url)
    else:
        form = form_class()
    return shared_sign(request, signup_form=form)
Example #13
0
def shared_sign(request, login_form=None, signup_form=None):
    if not login_form:
        login_form = LoginForm()
    if not signup_form:
        signup_form = SignupForm()
    template_name = "account/shared_sign.html"
    success_url = get_default_redirect(request, "next")

    ctx = { "login_form": login_form,
            "signup_form": signup_form,
            "site": Site.objects.get_current(),
            "redirect_field_value": request.REQUEST.get("next"),
    }
    return render_to_response(template_name, RequestContext(request, ctx))
Example #14
0
def signup(request, **kwargs):
    form_class = kwargs.pop("form_class", SignupForm)
    template_name = kwargs.pop("template_name", "account/signup.html")
    redirect_field_name = kwargs.pop("redirect_field_name", "next")
    success_url = kwargs.pop("success_url", None)

    group, bridge = group_and_bridge(kwargs)
    ctx = group_context(group, bridge)

    if success_url is None:
        if hasattr(settings, "SIGNUP_REDIRECT_URLNAME"):
            fallback_url = reverse(settings.SIGNUP_REDIRECT_URLNAME)
        else:
            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":
        form = form_class(request.POST, group=group)
        if form.is_valid():
            user = form.save(request=request)
            if settings.ACCOUNT_EMAIL_VERIFICATION:
                ctx.update({
                    "email": form.cleaned_data["email"],
                    "success_url": success_url,
                    })
                ctx = RequestContext(request, ctx)
                return render_to_response("account/verification_sent.html", ctx)
            else:
                form.login(request, user)
                messages.add_message(request, messages.SUCCESS,
                    ugettext("Successfully logged in as %(user)s.") % {
                        "user": user_display(user)
                    }
                )
                return HttpResponseRedirect(success_url)
    else:
        form = form_class(group=group)

    ctx.update({
        "form": form,
        "redirect_field_name": redirect_field_name,
        "redirect_field_value": request.REQUEST.get(redirect_field_name),
        })

    return render_to_response(template_name, RequestContext(request, ctx))
Example #15
0
def login(request, **kwargs):
    form_class = kwargs.pop("form_class", LoginForm)
    template_name = kwargs.pop("template_name", "account/login.html")
    success_url = kwargs.pop("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)
            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.REQUEST.get(redirect_field_name),
        })
    ctx.update(extra_context)

    return render_to_response(template_name, RequestContext(request, ctx))
Example #16
0
 def get_success_url(self):
     ret = self.success_url
     if not ret:
         ret = get_default_redirect(self.request, self.redirect_field_name)
     return ret