Пример #1
0
 def clean_signup_code(self):
     code = self.cleaned_data.get("signup_code")
     signup_code = SignupCode.check(code)
     if signup_code:
         return signup_code
     else:
         if settings.ACCOUNT_OPEN_SIGNUP:
             return None
         else:
             raise forms.ValidationError("Signup code was not valid.")
Пример #2
0
def signup(request, **kwargs):
    
    form_class = kwargs.pop("form_class", SignupForm)
    template_name = kwargs.pop("template_name", "account/signup.html")
    template_name_failure = kwargs.pop("template_name_failure", "signup_codes/failure.html")
    success_url = kwargs.pop("success_url", None)
    
    group, bridge = group_and_bridge(request)
    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)
    
    code = request.GET.get("code")
    
    if request.method == "POST":
        form = form_class(request.POST, group=group)
        if form.is_valid():
            user = form.save(request=request)
            
            signup_code = form.cleaned_data["signup_code"]
            if signup_code:
                signup_code.use(user)
            
            form.login(request, user)
            messages.add_message(request, messages.SUCCESS,
                ugettext("Successfully logged in as %(username)s.") % {
                    "username": user_display(user),
                }
            )
            return HttpResponseRedirect(success_url)
    else:
        signup_code = SignupCode.check(code)
        if signup_code:
            initial = {
                "signup_code": code,
                "email": signup_code.email,
            }
            form = form_class(initial=initial, group=group)
        else:
            if not settings.ACCOUNT_OPEN_SIGNUP:
                ctx.update({
                    "code": code,
                })
                ctx = RequestContext(request, ctx)
                # if account signup is not open we want to fail when there is
                # no sign up code or what was provided failed.
                return render_to_response(template_name_failure, ctx)
            else:
                form = form_class(group=group)
    
    ctx.update({
        "code": code,
        "form": form,
    })
    
    return render_to_response(template_name, RequestContext(request, ctx))
Пример #3
0
def signup(request, **kwargs):

    form_class = kwargs.pop("form_class", SignupForm)
    template_name = kwargs.pop("template_name", "account/signup.html")
    template_name_failure = kwargs.pop("template_name_failure",
                                       "signup_codes/failure.html")
    success_url = kwargs.pop("success_url", None)

    group, bridge = group_and_bridge(request)
    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)

    code = request.GET.get("code")

    if request.method == "POST":
        form = form_class(request.POST, group=group)
        if form.is_valid():
            user = form.save(request=request)

            signup_code = form.cleaned_data["signup_code"]
            if signup_code:
                signup_code.use(user)

            form.login(request, user)
            messages.add_message(
                request, messages.SUCCESS,
                ugettext("Successfully logged in as %(username)s.") % {
                    "username": user_display(user),
                })
            return HttpResponseRedirect(success_url)
    else:
        signup_code = SignupCode.check(code)
        if signup_code:
            initial = {
                "signup_code": code,
                "email": signup_code.email,
            }
            form = form_class(initial=initial, group=group)
        else:
            if not settings.ACCOUNT_OPEN_SIGNUP:
                ctx.update({
                    "code": code,
                })
                ctx = RequestContext(request, ctx)
                # if account signup is not open we want to fail when there is
                # no sign up code or what was provided failed.
                return render_to_response(template_name_failure, ctx)
            else:
                form = form_class(group=group)

    ctx.update({
        "code": code,
        "form": form,
    })

    return render_to_response(template_name, RequestContext(request, ctx))