Appending the validated User id into the Request header (Cookie) in DataPower - xslt

I want append to Username into Cookie , so that the backend team will fetc the username from cookie.
So i tried to use the below code , but it dint append
<dp:append-http-request-header name = "'Cookie'" value = "concat('SM_USER=',$UserID) "/>
Where UserID contains value of username.
Is it right or anything else need to be added?

Take out the http-. The extension element name is dp:append-request-header.
It's one of those odd inconsistencies in DataPower extension naming. (They have been trying to deprecate the http-specific extension element names for some time now.)

Related

Self.request.cookies.get is not returning complete value of the cookie in google app engine

I am setting the cookie value to (id, hash_of_id), but when the code is reading the value of the cookie it is getting only the part before comma. Not sure why:
These are the codes:
This is setting the values of the cookie named user_id.
self.response.headers.add_header('Set-Cookie', 'user_id = %s; Path=/'
% id_hash)
The value of id_hash is coming from following:
def make_hash(user_id): return hmac.new(SECRET,
str(user_id)).hexdigest()
def new_hash(user_id): id_hash = make_hash(user_id) return "%s,%s"
%((user_id), id_hash)
id_hash = new_hash(user.key().id())
When I am checking the value of the cookie in the browser using Edit this Cookie extension, it shows something like this:
This shows cookie has got id and hashed value of id.
Now value of cookie is being read:
cookiess = self.request.cookies.get('user_id')
When I am displaying the value of variable cookiess using
self.render("welcome.html", username = cookiess)
It shows only the part before comma,
enter image description here
I am not able to understand why the self.request.cookie.get returns value only till comma and not complete value.
Came to know that there is a bug in google appengine due to which
self.request.cookie.get()
was returning value only till comma. Instead of comma if something else like a pipe (|) is used as separator, then this function is working properly.

Django existing cookie is not updating

What i am trying to do is updating the existing django cookie that already exist. I am creating a add to cart functionality but unable to add more items in existing cookie. Any help would be praise-able.
My code is:
def AddToCart(request):
id = request.POST.get('id')
product = Product.objects.get(pk=id)
response = render(request,'index.html')
if request.COOKIES.get('product'):
request.COOKIES['product'] = {'name':product.name,'price':product.price,'img':product.image.url}
else:
response.set_cookie('product',{'name':product.name,'price':product.price,'img':product.image.url},
max_age= 14 * 24 * 60 * 60)
return response
Using request.COOKIES['product'] = .... sets the product value only in the current request context ( or maybe a copy of the COOKIES dict, not sure really), so it won't set the cookie on the client side (response), and on the next request it will be overridden by the cookie it gets from the client response (which is the cookie prior to using request.COOKIES['product'] = ....).
So first you need to replace: request.COOKIES['product'] = ... by response.set_cookie("product", ...) for the value to change.
This will solve your cookie setting problem only, but not appending multiple products to your cookie.
For that i suggest you use sessions instead, as they are easier to use when it comes to manipulating data structures like dicts and arrays, for eg: on the client-side cookies approach, you need to write your own serialization to manipulate a dict/array stored in the cookie, example here: https://stackoverflow.com/a/2383482
Also you can refer to this answer to tell if you need cookie or db based sessions:
https://stackoverflow.com/a/18240232/4724196

how to verify email through link in rails4 application

How to verify email through link.
I have user edit profile and it is showing user email.I want to give one link to verify email.I do not what to do.
Add one column to your
User Model : email_verification and by default set to zero (0).
Then using persistence_token create a URL and sent to that specific email address. If you dnt have persistence_token as column in your User model then you can add custom column of your choice like verify_email_token as column name and stored 50 random string.
Using
o = [('a'..'z'),('A'..'Z'),('0'..'9')].map{|i| i.to_a}.flatten
string = (0...50).map{ o[rand(o.length)] }.join
URL example :
http://www.yoursitename.com/VerifyEmailAddress/?token=persistence_token ;
When user click on that link, internally call function like VerifyEmailAddress and in that method update email_verification column by one (1).

Get the item matching a URL in Sitecore

In a site I'm building, I'm trying to use the referer to verify AJAX requests are coming from the correct URLs.
To do this I'd like to get Sitecore to resolve a URL to an Item. For example,
http://www.mysite.com/abc/def
might resolve to the item at the path
sitecore/Content/MySite/Home/abc/def
What's the recommended way to go about this in my code?
Thanks for all the answers but none of them did everything I needed. This worked for me.
var url = new Uri(...);
// Obtain a SiteContext for the host and virtual path
var siteContext = SiteContextFactory.GetSiteContext(url.Host, url.PathAndQuery);
// Get the path to the Home item
var homePath = siteContext.StartPath;
if (!homePath.EndsWith("/"))
homePath += "/";
// Get the path to the item, removing virtual path if any
var itemPath = MainUtil.DecodeName(url.AbsolutePath);
if (itemPath.StartsWith(siteContext.VirtualFolder))
itemPath = itemPath.Remove(0,siteContext.VirtualFolder.Length);
// Obtain the item
var fullPath = homePath + itemPath;
var item = siteContext.Database.GetItem(fullPath);
This answer is more for other visitors hitting this SO question. In case of Sitecore 8 you could do this:
new Sitecore.Data.ItemResolvers.ContentItemPathResolver().ResolveItem(<string path>)
Where <string path> is like any local path (or relative url, if you will) string that sitecore would be able to generate for you. When using displayname values instead of item names (possibly the case if you have a multilingual site), this is very handy to actually retrieve the corresponding Item from database.
In my case I use this to show a valid breadcrumb where the parent paths DO have the context language item version added, but the requested page has no context language version to render. Sitecore.Context.Database.GetItem(<string path>) couldn't resolve the displayname-based path, while the ResolveItem method does... searched a day for a good answer on this case.
Questioning myself now, why this isn't used much...?
Maybe it is an expensive query for a site with a big tree. That is something to consider yourself.
Don't really get what you're trying to do (with your AJAX request and such), but if you want http://www.mysite.com/abc/def to resolve the item sitecore/content/MySite/Home/abc/def, you need to configure your <site> in the web.config like this:
<site name="MySite" hostName="www.mysite.com" rootPath="/sitecore/content/MySite" startItem="/Home" *other attributes here* />
You can use the method ItemManager.GetItem(itemPath, language, version, database, securityCheck) To resolve an item based on it's (full)path.

Display name & picture knowing ID

I was looking to find an answer to my question, but so far I got this:
https://graph.facebook.com/the_user_id?fields=name,picture
I need to be able to display/print first,last name and picture of a set list of users for which I know their ID. What code is required to get this data and then to publish it on a php/html page? Of course, this will means that if I want to show 10 users, I will input 10 different IDs (read smtg about an array list?). Notice that I DO NOT require for this to work for the current user.
Thanks in advance for your replies.
You need to use file_get_contents ( http://uk3.php.net/file_get_contents ) or curl in php and issue a request to the url such as follows:
https://graph.facebook.com/?ids=id1,id2,id3&fields=name,picture
(replacing id1,id2 with your ids)
this will then return you a json object. You then need to decode ( http://uk3.php.net/json_decode ) and loop through this and access the information
this should get you started
// people array uses the users id as the key and the dessert as the value. The id is then used in the query to facebook to select the corresponding value from this array
$people = array("id1"=>"favourite "dessert", "id2"=>"favourite dessert", "id3"=>"apple pie");
$json = file_get_contents('https://graph.facebook.com/?ids=id1,id2,id3&fields=id,name,picture');
$json = json_decode($json);
foreach($json as $key=>$person){
echo '<p><img src="'.$person->picture.'" alt="'.$person->name.'" />';
echo $person->name.'\'s favourite dessert is '.$people[$person->id'];
echo '</p>';
}
I've batched the requests here, alternatively you could perform 10 separate queries for each user, but that would be a bit pointless and inefficient
The easiest way is with an FQL query:
SELECT first_name, last_name, pic, uid FROM user WHERE uid IN
(Known_ID_1, Known_ID_2, ... Known_ID_n)
The easiest, if you're using PHP is to install the PHP SDK, though you can also make a call directly to https://graph.facebook.com/fql?q=URL_ENCODED_QUERY