Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Limit Downloads to Authenticated Users for Document Attachments View modes: 
User avatar
Member
Member
Armysniper89 - 10/4/2010 1:34:28 PM
   
Limit Downloads to Authenticated Users for Document Attachments
I am using the document attachments web part control and I can hide or show the web part based on whether a user is authenticated...but could I set it up to display the list of document attachments but not allow them to download it if they are not an authenticated user?

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 10/6/2010 9:54:25 AM
   
RE:Limit Downloads to Authenticated Users for Document Attachments
Hello,

The easiest way woud be to change the default transformation to not to generate links to the files. Than there would be a different transformation (the default one) where the links are generated as always. The first transformation would be used if the user isn't authenticated, the second one, if he is. This can be done by a macro expression which would select the correct transformation according to the current user.

Best regards,
Boris Pocatko

User avatar
Member
Member
Armysniper89 - 10/7/2010 9:21:03 AM
   
RE:Limit Downloads to Authenticated Users for Document Attachments
Can you give me some idea where I would do this kind of switch? Would I need to do this in some code behind somewhere or could this be done some other way. I could use a bit more detail. ;)

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 10/9/2010 8:46:14 PM
   
RE:Limit Downloads to Authenticated Users for Document Attachments
Hi,

you can use the macro expression (as Boris suggested) in the Attachments webpart properties.
If you're using Portal engine and see "Design" tab, you can simply open the properties dialog and put the macro in the "Transformation" property instead of the particular transformation that's used by default.

The macro could look like:

{%currentuser.username|(notequals)public|(truevalue)AuthTransfName|(falsevalue)OpenTransfName%}

...and as AuthTransfName please use the transformation name, that has been designed for authenticated users. The second expression will be the name of default transformation showing content for public users.

Regards,
Zdenek

User avatar
Member
Member
Armysniper89 - 10/12/2010 4:59:27 PM
   
RE:Limit Downloads to Authenticated Users for Document Attachments
Great! Thanks for helping with that! Now what if I wanted to display to the "unauthenticated" user text below the list that tells the user to login or register to download. I have code like this:


<div class="notLoggedList">
<br />
<p>To download these attachments, please <a href="~/Login.aspx">login</a> or <a href="~/Login.aspx">register</a>.
</div>


I thought I would add this to the HTMLEnvelope after Content After property but I cannot figure out how to do this. How can I setup a macro to test and dispay that HTML versus NO html if the user is authenticated?

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 10/13/2010 10:47:26 AM
   
RE:Limit Downloads to Authenticated Users for Document Attachments
Hi,

You can add your code into the OpenTransfName transformation. This way only unauthorized users will be asked to register or login.

If your goal is something else, could you provide us some example, please?

Best regards,
Ivana Tomanickova

User avatar
Member
Member
Armysniper89 - 10/13/2010 8:42:34 PM
   
RE:Limit Downloads to Authenticated Users for Document Attachments
I thought I could do that in the "Open Transformation" but because it is a repeater transformation, the text repeats on every item in the list. Here is what the transformation I have (notice it is the main ArticleList transformation, I just removed the link):


<div>
<img src="<%# GetAttachmentIconUrl(Eval("AttachmentExtension"), "List") %>" alt="<%# Eval("AttachmentName") %>" />
 
<%# Eval("AttachmentName") %>
</div>
<div class="notLoggedList">
<br />
<p>If you want to download these attachments, please <a href="~/Login.aspx">login</a> or <a href="~/Login.aspx">register</a>.
</div>


So where would I put this text if this is a repeater transformation?

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 10/14/2010 8:17:56 AM
   
RE:Limit Downloads to Authenticated Users for Document Attachments
Hi,

Yes, you are right. In the repeater transformation it would be complicated to add your code.

Could you please add following code into Content After property?

{%currentuser.username|(equals)public|(truevalue)<div class="notLoggedList"><br /><p>To download these attachments, please <a href="~/Login.aspx">login</a> or <a href="~/Login.aspx">register</a></div>|(falsevalue)%}


Best regards,
Ivana Tomanickova

User avatar
Member
Member
Armysniper89 - 10/14/2010 2:44:11 PM
   
RE:Limit Downloads to Authenticated Users for Document Attachments
That worked great! Thanks! OK now...what if I wanted it that when the sees the message to login and clicks on it. How can I get them back to the document so they can proceed after logging in or registering.

I tried changing the code you had above to this:

{%currentuser.username|(equals)public|(truevalue)<div class="notLoggedList"><br /><p>To download these attachments, please <a href="~/Login.aspx?ReturnUrl={%currentdocument.documenturlpath%}


But it did not work. It would not put in the path to the current page or document in there but part of the macro. What am I missing?

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 10/15/2010 8:49:43 AM
   
RE:Limit Downloads to Authenticated Users for Document Attachments
Hi,
you can use following code with macro:


{(1)%username|(equals)public|(truevalue)<div class="notLoggedList"><br /><p>To download these attachments, please <a href="~/Login.aspx?a={(2)%nodealiaspath%(2)}">login</a> or <a href="~/Login.aspx?a={(2)%nodealiaspath%(2)}">register</a></div>|(falsevalue)%(1)}



In the logonform webpart on Login.aspx page set Default target URL: http://localhost/{%a|(default)/home.aspx%}.aspx

You can modify the default path according to your needs. If the "a" query parameter is not specified /home.aspx will be used.

This way query parameter will be resolved and the user will be redirected back to the requested document after login.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
Armysniper89 - 10/18/2010 9:02:18 AM
   
RE:Limit Downloads to Authenticated Users for Document Attachments
Great! Your the best Ivana. ;)

User avatar
Member
Member
Armysniper89 - 10/19/2010 1:07:59 PM
   
RE:Limit Downloads to Authenticated Users for Document Attachments
I had to make some adjustments as the code you sent along did not attach .aspx and my site is not configured without extensions.


{(1)%username|(equals)public|(truevalue)<div class="notLoggedList"><br /><p>To download these attachments, please <a href="~/Login.aspx?ReturnUrl={(2)%nodealiaspath%(2)}.aspx">login</a> or <a href="~/Login.aspx?ReturnUrl={(2)%nodealiaspath%(2)}.aspx">register</a>.</div>|(falsevalue)%(1)}
<br />
<br />