I'd like to be able to show/hide certain payment methods based on user roles.
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?
You'll find the answer in the Hotcakes Commerce documentation area. I've included it here for posterity on SO as well.
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.
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.)
Add the code below to the header area of the view that you want to edit, such as the _ProductDetails.cshtml view.
#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" />
}
We hope this helps you as a baseline example for doing anything dynamic with views that involves the security roles in the CMS.
Related
I need help. How do I create profile visitors in Laravel 8? I have not written the code yet and I do not even have an idea how to complete this task. I would be very grateful if you could help me.
You can leave the visitor without any profile. He will be able to access public web pages without authentication and therefore only logged in users will have profile.
UPDATE
Proposed skeleton in two steps using cookies
1- When a user make request on profile page generate an unique identifier and store it in user cookie with a long enough validity if it not yet exists
2- Using this unique token register a new view count (if not yet done) before sending response to user.
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Http\Requests;
use App\Http\Controllers\Controller;
public function getProfilePage(Request $request){
if(!Cookie::has('uniqueId')){
$uniqueId = Str::uuid(); // generate unique id for current user
Cookie::queue('uniqueId', $uniqueId, [live time in minutes]);
// save it using Cookie::queue
// one year for example as live time
}
// check if view count already exists for $uniqueId
// and save it in a persistent way if not
// other stuff ....
return ....
}
I am new to Graphql and some things still confuse me.
I am working on a project, similar to Todo List.
User may have multiple todo items, some of item's properties must be visible to owner only, some should be public.
So far I came up with two ideas:
1) First is to create two separate types, something like:
ToDoType {
id
name
complete
}
ToDoPrivateType {
id
name
complete
colorGroup
createdAt
...other private properties
}
And access
- ToDoType from root query user {...} and everywhere else, except
- viewer {...} where I will use ToDoPrivateType
It will work but looks a little like double-work,
plus if I retrieve todo lists from standard user root query I will not be able to pull private properties for user's own user.
2) I can also provide access to all properties and set to null properties to which a random user should not have access (like createdAt of other's users) but it also does not look right.
Hope what I am asking is not too confusing.
Do these approaches make sense?
Is there a better way to control access to some properties?
Thanks!
I have built a site that pulls the comments from Trello to show it on my site using this code:
var resource = "cards/" + card.id + "/actions";
Trello.get(resource, function(comments) {
if(!$.isEmptyObject(comments)){
var commentStr="<div class='comments_c'>";
$.each(comments, function(c, cda){
//console.log(cda.data.text);
commentStr += "<p>"+cda.data.text+"</p>";
//addComments(cda.data.text);
});
commentStr += "</div>";
}
console.log(commentStr);
Now it works fine to pull the comments but it doesn't show the activity like "Sarah Hastings added this card to ". The api documentation doesn't talk about it and I am at a dead-end. We need it for reporting and looking for a way to get the activities (copied, moved, added) from Trello to our site. Any help is appreciated.
By default, the cards/[idCard]/actions endpoint returns actions filtered to commentCard,updateCard:idList. If you want to get actions of additional types from that endpoint you will want to include the filter parameter with the list of action types that you want returned. You can see the full list of options documented here: https://developers.trello.com/advanced-reference/card#get-1-cards-card-id-or-shortlink-actions by clicking Show next to Arguments for that call.
For example actions of adding cards to a board would be of type: moveCardToBoard so you would want to add that to the filter parameter.
So, given that I have user table with a field of "is_confirmed", I want funnel anyone with an "is_confirmed" that is equal to 0 to a single url using the redirect...
Is there a way to do this check so that it only needs to be implemented once? I guess a good example would be the default user functionality of how any page that requires a logged-in user forces the user to the login page...
Haven't tried this specifically myself, but based on Yii's documentation one would probably redirect the user inside the login action based on the value. If the user is confirmed, call the CWebUser::login(..) method to store the identity in persistent storage and use the returnUrl redirect, otherwise the user is not confirmed so skip that part and just render the in limbo page.
Inside your SiteController::actionLogin() you'll probably do something like this (additionally the UserIdentity component should have a method for returning the value of the confirmation field)-
$identity = new UserIdentity();
if($identity->authenticate()) {
if($identity->isConfirmed() == 1) {
Yii::app()->user->login($identity);
$this->redirect(Yii::app()->user->returnUrl);
} else {
$this->render('not_yet_confirmed_view');
}
} else {
throw new CHttpException(500,'Internal Server Error. Could not authenticate.');
}
Edit- Removed the accidental extra CWebUser::login() and clarified that the UserIdentity component will require just a bit of additional smarts.
So one of my clients has a request to do rule based static blocks on their home page. The page will basically swap out several static blocks for others based on the perceived gender of the person viewing the site. It will get this data from the session that the user is currently in, or the data associated with the users account. Basically, if a user searches in a specific set of categories (Men's or Women's categories) it should swap the static blocks out on the home page, so when that user visits the site again they will have a more personalized experience. There will be a default set of blocks if the user is new to the site.
Something like this (and excuse my shabby php):
if($categories = $user->getViewedCategories()){
foreach($categories as $category){
switch($category){
case 14: //insert womens category id here
echo $staticBlockWomen
break;
case 16: //insert mens category id here
echo $staticBlockMen
break;
}
}
} else {
echo $staticBlockDefault
}
I know Magento tracks a users path through a site, and I know that other elements in Magento can have rules based on this data (the dynamic banners and checkout rules), but I am really lost on where to get started.
If someone could point me in the right direction, any help would be appreciated!
Cheers,
Matthew
I'm assuming you know the basics of Magento (at least how to create new blocks and how to manage the layout using xml).
If you need more info about that,
You can accomplish what you need in a few steps:
1 - create the blocks you need (create a new module and block classes inside it within the corresponding .phtml files)
2 - from the admin panel, select the category for which you want to add a block and navigate to "Custom Design" tab, then add in the "Custom Layout Update" textarea something like this:
<reference name="content" >
<block type="mymodule/myblock" name="myblock" />
</reference>
This way, every time the selected category is viewed by the custmer, a block of type "mymodule/myblock" will be added in the content area.