DNN Hotcakes检出视图中的访问角色 [英] Access Roles in DNN Hotcakes Checkout Views

查看:63
本文介绍了DNN Hotcakes检出视图中的访问角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够根据用户角色显示/隐藏某些付款方式。

I'd like to be able to show/hide certain payment methods based on user roles.

在Hotcakes的 _DisplayPaymentMethods视图集下,我看到了一个开关以 payMethod.MethodId作为表达式的语句。在每种情况下,我想设置一条if语句来检查当前用户是否具有 x角色。

In Hotcakes under the "_DisplayPaymentMethods" view set I see a switch statement with "payMethod.MethodId" as the expression. Inside each case I'd like to set an if statement that checks if the current user has "x" role.

如何从此视图集中访问用户角色?

How can I access the user roles from this view set?

推荐答案

您将在 Hotcakes Commerce文档区域中找到答案。我也将其包括在此处,以便在SO上用作后代。

You'll find the answer in the Hotcakes Commerce documentation area. I've included it here for posterity on SO as well.

安全角色在您网站的电子商务和CMS部分中都有大量用途。有时,您可能想重新调整这些角色的用途,以使视图动态化。一个示例可能是仅将添加到购物车按钮显示给特定角色。在本示例中,我们将使用该用例。

Security roles are used for a large number of purposes in both the e-commerce and CMS parts of your website. On occasion, you might want to re-purpose these roles to do something dynamic with your views. One example might be to only show the Add to Cart button to a specific role. We'll use that use case for this example.

首先,您需要一个计划。在此计划中,我们将使所有登录的人员都可以使用添加到购物车按钮,并且该按钮属于 VIP客户安全角色。 (这不是内置角色。它是本代码示例的虚构内容。您可以创建和使用所需的任何角色。)

First, you'll need a plan. In this plan, we're going to make the Add to Cart button available to all people that are logged in and part of the "VIP-Customer" security role. (This isn't a built-in role. It's made-up for this code sample. You can create and use whatever roles that you want.)

添加代码

@functions
{

    private bool IsVipCustomer()
    {
        var customer = DotNetNuke.Entities.Users.UserController.Instance.GetCurrentUserInfo();
        if (customer != null && customer.UserID > 0)
        {
            return customer.IsInRole("VIP-Customer") || customer.IsInRole("Administrators");
        }

        return false;
    }

}

在下面的代码示例中,我们正在检查角色是否符合我们的期望。如果是这样,我们将显示添加到购物车按钮。只要它在同一个视图文件中具有上面创建的功能,就可以在任意位置添加和使用此代码。

In this code sample below, we're checking to see if the role matches what we expect. If it does, we show the Add to Cart button. You can add and use this code anywhere you want, as long as it has the function we created above in the same view file.

@if (IsVipCustomer())
{
    <input type="submit" id="addtocartbutton" value="@Localization.GetString("AddToCart")" class="dnnPrimaryAction largeButton fullCartButton" />
}

我们希望这可以作为基线示例,帮助您动态处理带有以下内容的视图:涉及CMS中的安全角色。

We hope this helps you as a baseline example for doing anything dynamic with views that involves the security roles in the CMS.

这篇关于DNN Hotcakes检出视图中的访问角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆