• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python urls.login_redirect函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mezzanine.utils.urls.login_redirect函数的典型用法代码示例。如果您正苦于以下问题:Python login_redirect函数的具体用法?Python login_redirect怎么用?Python login_redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了login_redirect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: signup

def signup(request, template="accounts/account_signup.html",
           extra_context=None):
    """
    Signup form.
    """
    #Staat in admin_forms
    form = NewUserCreationForm(request.POST or None, request.FILES or None)
    if request.method == "POST" and form.is_valid():
        new_user = form.save()
        if not new_user.is_active:
            if settings.ACCOUNTS_APPROVAL_REQUIRED:
                send_approve_mail(request, new_user)
                info(request, _("Thanks for signing up! You'll receive "
                                "an email when your account is activated."))
            else:
                send_verification_mail(request, new_user, "signup_verify")
                info(request, _("A verification email has been sent with "
                                "a link for activating your account."))
            return redirect(next_url(request) or "/")
        else:
            info(request, _("Successfully signed up"))
            auth_login(request, new_user)
            return login_redirect(request)
    context = {"form": form, "title": _("Sign up")}
    context.update(extra_context or {})
    return render(request, template, context)
开发者ID:nigelvanherwijnen,项目名称:nsawebdev,代码行数:26,代码来源:views_backup.py


示例2: signup

def signup(request, template="accounts/account_signup.html"):
    """
    Signup form.
    """
    profile_form = get_profile_form()
    form = profile_form(request.POST or None, request.FILES or None)
    if request.method == "POST" and form.is_valid():
        new_user = form.save()
        if not new_user.is_active:
            if settings.ACCOUNTS_APPROVAL_REQUIRED:
                send_approve_mail(request, new_user)
                info(request, _("Thanks for signing up! You'll receive "
                                "an email when your account is activated."))
            else:
                send_verification_mail(request, new_user, "signup_verify")
                info(request, _("A verification email has been sent with "
                                "a link for activating your account."))
            return redirect(request.GET.get("next", "/"))
        else:
            info(request, _("Successfully signed up"))
            auth_login(request, new_user)
            return login_redirect(request)
    else:
        log.debug('Form is not valid. Errors: %s' % form.errors)
    context = {"form": form, "title": _("Create an Account"), "submit_label": "Next Step"}
    return render(request, template, context)
开发者ID:orlenko,项目名称:sfpirg,代码行数:26,代码来源:views.py


示例3: login

def login(request, template="accounts/account_login.html"):
    """
    Login form.
    """
    isAjax = False
    form = LoginForm(request.POST or None)
    next = get_login_redirect_url(request)
    if request.method == "POST" and form.is_valid():
        authenticated_user = form.save()
        #info(request, _("Successfully logged in"))
        auth_login(request, authenticated_user)
        if request.is_ajax():
            if  request.user.is_authenticated():
                return HttpResponse(simplejson.dumps(dict(url=next,
                                                          success=True)))
            else:
                return HttpResponse(simplejson.dumps(dict(success=False)))                
        else:
            return login_redirect(request)
    elif form.errors:
        return HttpResponse(simplejson.dumps(dict(errors=form.errors, success=False)))

    if request.is_ajax():
        template = "accounts/ajax_account_login.html"

    context = {"form": form, "title": _("Log in"), "next":next}
    return render(request, template, context)
开发者ID:saumishr,项目名称:mezzanine,代码行数:27,代码来源:views.py


示例4: signup

def signup(request, template="accounts/account_signup.html"):
    """
    Signup form.
    """
    profile_form = UserRegistrationLeadForm
    form = profile_form(request.POST or None, request.FILES or None)
    if request.method == "POST" and form.is_valid():
        data = form.cleaned_data.copy()

        # ensure user is not a robot
        honeypot = data.pop('superpriority')
        if honeypot:
            raise PermissionDenied

        # save the user
        new_user = form.save()

        if not new_user.is_active:
            if settings.ACCOUNTS_APPROVAL_REQUIRED:
                send_approve_mail(request, new_user)
                info(request, _("Thanks for signing up! You'll receive "
                                "an email when your account is activated."))
            else:
                send_verification_mail(request, new_user, "signup_verify")
                info(request, _("A verification email has been sent with "
                                "a link for activating your account."))
            return redirect(next_url(request) or "/")
        else:
            info(request, _("Successfully signed up"))
            auth_login(request, new_user)
            return login_redirect(request)
    context = {"form": form, "title": _("Sign up")}
    return render(request, template, context)
开发者ID:Osmose,项目名称:fxoss,代码行数:33,代码来源:views.py


示例5: signup

def signup(request, template="accounts/account_signup.html", extra_context=None):
    """
    Signup form. Overriding mezzanine's view function for signup submit
    """
    form = SignupForm(request, request.POST, request.FILES)
    if request.method == "POST" and form.is_valid():
        try:
            new_user = form.save()
        except ValidationError as e:
            if e.message == "Email already in use.":
                messages.error(request, '<p>An account with this email already exists.  Log in '
                                'or click <a href="' + reverse("mezzanine_password_reset") +
                               '" >here</a> to reset password',
                               extra_tags="html")
            else:
                messages.error(request, e.message)
            return HttpResponseRedirect(request.META['HTTP_REFERER'])
        else:
            if not new_user.is_active:
                if settings.ACCOUNTS_APPROVAL_REQUIRED:
                    send_approve_mail(request, new_user)
                    info(request, _("Thanks for signing up! You'll receive "
                                    "an email when your account is activated."))
                else:
                    send_verification_mail(request, new_user, "signup_verify")
                    info(request, _("A verification email has been sent to " + new_user.email +
                                    " with a link that must be clicked prior to your account "
                                    "being activated. If you do not receive this email please "
                                    "check that you entered your address correctly, or your " 
                                    "spam folder as sometimes the email gets flagged as spam. "
                                    "If you entered an incorrect email address, please request "
                                    "an account again."))
                return redirect(next_url(request) or "/")
            else:
                info(request, _("Successfully signed up"))
                auth_login(request, new_user)
                return login_redirect(request)

    # remove the key 'response' from errors as the user would have no idea what it means
    form.errors.pop('response', None)
    messages.error(request, form.errors)

    # TODO: User entered data could be retained only if the following
    # render function would work without messing up the css

    # context = {
    #     "form": form,
    #     "title": _("Sign up"),
    # }
    # context.update(extra_context or {})
    # return render(request, template, context)

    # This one keeps the css but not able to retained user entered data.
    return HttpResponseRedirect(request.META['HTTP_REFERER'])
开发者ID:hydroshare,项目名称:hydroshare,代码行数:54,代码来源:views.py


示例6: login

def login(request, template="accounts/account_login.html"):
    """
    Login form.
    """
    form = LoginForm(request.POST or None)
    if request.method == "POST" and form.is_valid():
        authenticated_user = form.save()
        info(request, _("Successfully logged in"))
        auth_login(request, authenticated_user)
        return login_redirect(request)
    context = {"form": form, "title": _("Log in")}
    return render(request, template, context)
开发者ID:31H0B1eV,项目名称:mezzanine,代码行数:12,代码来源:views.py


示例7: login

def login(request, template="accounts/account_login.html"):
    """
    Login Form
    """
    # Copied from mezzanine/accounts/views so we can override cacheing behavior
    # as it related to the CSRF cookie.
    form = LoginForm(request.POST or None)
    if request.method == "POST" and form.is_valid():
        authenticated_user = form.save()
        info(request, _("Successfully logged in"))
        auth_login(request, authenticated_user)
        return login_redirect(request)
    context = {"form": form, "title": _("Login")}
    return render(request, template, context)
开发者ID:Edinunzio,项目名称:raspberryio,代码行数:14,代码来源:views.py


示例8: login

def login(request, template="accounts/account_login.html",
          form_class=LoginForm, extra_context=None):
    """
    Login form.
    """
    form = form_class(request.POST or None)
    if request.method == "POST" and form.is_valid():
        authenticated_user = form.save()
        info(request, _("Successfully logged in"))
        auth_login(request, authenticated_user)
        return login_redirect(request)
    context = {"form": form, "title": _("Log in")}
    context.update(extra_context or {})
    return TemplateResponse(request, template, context)
开发者ID:Anlim,项目名称:mezzanine,代码行数:14,代码来源:views.py


示例9: signup

def signup(request, template="accounts/account_signup.html"):
    """
    Signup form.
    """
    profile_form = UserRegistrationLeadForm
    form = profile_form(request.POST or None, request.FILES or None)
    if request.method == "POST" and form.is_valid():
        data = form.cleaned_data.copy()

        # ensure user is not a robot
        honeypot = data.pop('superpriority')
        if honeypot:
            raise PermissionDenied

        # save the user
        new_user = form.save()

        # Generate Salesforce Lead
        # Pop non-Salesforce Fields
        for field in ['password1', 'password2']:
            data.pop(field)
        for k, v in SALESFORCE_FIELD_MAPPINGS.items():
            data[v] = data.pop(k)
        data['oid'] = '00DU0000000IrgO'
        # As we're doing the Salesforce POST in the background here,
        # `retURL` is never visited/seen by the user. I believe it
        # is required by Salesforce though, so it should hang around
        # as a placeholder (with a valid URL, just in case).
        data['retURL'] = (request.build_absolute_uri())

        r = requests.post('https://www.salesforce.com/servlet/'
                          'servlet.WebToLead?encoding=UTF-8', data)

        if not new_user.is_active:
            if settings.ACCOUNTS_APPROVAL_REQUIRED:
                send_approve_mail(request, new_user)
                info(request, _("Thanks for signing up! You'll receive "
                                "an email when your account is activated."))
            else:
                send_verification_mail(request, new_user, "signup_verify")
                info(request, _("A verification email has been sent with "
                                "a link for activating your account."))
            return redirect(next_url(request) or "/")
        else:
            info(request, _("Successfully signed up"))
            auth_login(request, new_user)
            return login_redirect(request)
    context = {"form": form, "title": _("Sign up")}
    return render(request, template, context)
开发者ID:J0WI,项目名称:fxoss,代码行数:49,代码来源:views.py


示例10: signup_verify

def signup_verify(request, uidb36=None, token=None):
    """
    View for the link in the verification email sent to a new user
    when they create an account and ``ACCOUNTS_VERIFICATION_REQUIRED``
    is set to ``True``. Activates the user and logs them in,
    redirecting to the URL they tried to access when signing up.
    """
    user = authenticate(uidb36=uidb36, token=token, is_active=False)
    if user is not None:
        user.is_active = True
        user.save()
        auth_login(request, user)
        info(request, _("Successfully signed up"))
        return login_redirect(request)
    else:
        error(request, _("The link you clicked is no longer valid."))
        return redirect("/")
开发者ID:alwinus,项目名称:mezzanine,代码行数:17,代码来源:views.py


示例11: signup

def signup(request, template="accounts/account_signup.html"):
    """
    Signup form.
    """
    form = ProfileForm(request.POST or None)
    if request.method == "POST" and form.is_valid():
        new_user = form.save()
        if not new_user.is_active:
            send_verification_mail(request, new_user, "signup_verify")
            info(request, _("A verification email has been sent with "
                            "a link for activating your account."))
        else:
            info(request, _("Successfully signed up"))
            auth_login(request, new_user)
            return login_redirect(request)
    context = {"form": form, "title": _("Signup")}
    return render(request, template, context)
开发者ID:a5an0,项目名称:mezzanine,代码行数:17,代码来源:views.py


示例12: connect

def connect(request):
    error = False
    if request.GET:
        articleAttempt = True
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if user:
                login(request, user)
                return login_redirect(request)
            else:
                obsolete = True
                return render(request, 'login.html', locals())
    else:
        form = LoginForm()
    return render(request, 'login.html', locals())
开发者ID:patsykakaz,项目名称:RDPC,代码行数:19,代码来源:views.py


示例13: login

def login(request, template="accounts/account_login.html",
          form_class=LoginForm, extra_context=None):
    """
    Login form - customized from Mezzanine login form so that quota warning message can be
    displayed when the user is logged in.
    """
    form = form_class(request.POST or None)
    if request.method == "POST" and form.is_valid():
        login_msg = "Successfully logged in"
        authenticated_user = form.save()
        add_msg = get_quota_message(authenticated_user)
        if add_msg:
            login_msg += ' - ' + add_msg
        info(request, _(login_msg))
        auth_login(request, authenticated_user)
        return login_redirect(request)
    context = {"form": form, "title": _("Log in")}
    context.update(extra_context or {})
    return TemplateResponse(request, template, context)
开发者ID:hydroshare,项目名称:hydroshare,代码行数:19,代码来源:views.py


示例14: signup

def signup(request, template="customers/account_signup.html"):

    stripe_key = settings.STRIPE_PUBLIC_KEY

    subscription_form = SubscriptionForm(request.POST or None)
    customer_form = CustomerForm(request.POST or None)

    if request.method == "POST" and subscription_form.is_valid() and \
        customer_form.is_valid():

        with transaction.commit_on_success():
            save = transaction.savepoint()
            try:
                customer = customer_form.save(commit=False)
                customer.update_card(request.POST['stripeToken'])
                subscription = subscription_form.save(commit=False)
                subscription.customer = customer
                customer.save()
                subscription.save()
                transaction.savepoint_commit(save)

                if not customer.user.is_active:
                    send_verification_mail(request, customer.user, "signup_verify")
                    info(request, _("A verification email has been sent with "
                                    "a link for activating your account."))
                    return redirect(request.GET.get("next", "/"))
                else:
                    info(request, _("Successfully signed up"))
                    auth_login(request, customer.user)
                    return login_redirect(request)

            except Exception as e:
                error(request, e)
                transaction.savepoint_rollback(save)

    context = {
        'customer_form': customer_form,
        'subscription_form': subscription_form,
        'stripe_key': stripe_key,
    }

    return render(request, template, context)
开发者ID:nijotz,项目名称:thesourcecoffee,代码行数:42,代码来源:views.py


示例15: gift_redeem

def gift_redeem(request, context):
    with transaction.commit_on_success():
        save = transaction.savepoint()
        try:
            code = context["gift_code"]
            gift = GiftSubscription.objects.get(code=code, redeemed=None)
            gift.redeemed = datetime.now()
            gift.save()

            # Create coupon so customer gets free subscription
            coupon = stripe.Coupon.create(percent_off=100, duration="once")["id"]

            customer_form = context["customer_form"]
            customer = customer_form.save(commit=False).customer

            subscription = Subscription(customer=customer, plan=context["plan"])
            subscription.save(coupon=coupon)

            transaction.savepoint_commit(save)

            if not customer.user.is_active:
                send_verification_mail(request, customer.user, "signup_verify")
                info(request, _("A verification email has been sent with " "a link for activating your account."))
                return redirect(request.GET.get("next", "/"))
            else:
                info(request, _("Successfully signed up"))
                auth_login(request, customer.user)
                return login_redirect(request)
            data = {
                "plan": context["plan"],
                "giftee": context["gift_form"].cleaned_data["giftee"],
                "gifter": context["gift_form"].cleaned_data["gifter"],
            }

        except Exception as e:
            transaction.savepoint_rollback(save)
            error(request, e)

    return context
开发者ID:nijotz,项目名称:thesourcecoffee,代码行数:39,代码来源:views.py



注:本文中的mezzanine.utils.urls.login_redirect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python urls.next_url函数代码示例发布时间:2022-05-27
下一篇:
Python urls.admin_url函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap