function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
johnhurleyjohnhurley 

Login form conditional visibility

Hi all,

 

I'm new to Salesforce and am trying to work on a client site.  I'm getting the hang of working with pages and such and have the basic layout of the site on the client's Force.com site.  Now I'm getting into the nitty-gritty of things and keep hitting brick walls everywhere I turn.  I've tried searching, reading docs and this message board, but I can't seem to find what I'm looking for.  So in my last ditch effort, I'm hoping one of you gurus can point me in the right direction.

 

Here's the scenario....

 

I have a client e-commerce site, subscription based.  In order for the customer to access their account, they (obviously) need to login.  I have the login component working, but, after they login, I want the login form to switch to account related links (i.e. My Account).  I'm a PHP guy, and it would be relatively easy to set an "IF" conditional statement to display the login form or links based on if they are logged in, but it seems to be a bit more complicated in Salesforce.  Maybe (hopefiully) I'm looking too deep into this and it's a relatively simple process.

 

I don't want to take too much of anyone's time in this, nor am I looking for someone to outright code it for me.  I'm just looking for someone that can point me in the right direction as to how I can make this happen, whether it be through controllers, classes, or directly in the page itself.

 

Thanks in advance and hopefully in the near future, I can return the favor here when I get the hang of it.

Best Answer chosen by Admin (Salesforce Developers) 
BulentBulent

Take a look at the sample SiteHeader component. It has the code to hide and show links based on anonymous vs. authenticated access

 

 

<apex:component id="headerComponent">

<apex:panelGrid cellpadding="0" cellspacing="0" width="98%" border="0" columns="2" style="text-align: left;" id="theHeader">

<apex:image url="{!$Site.Prefix}{!$Label.site.img_path}/force_logo.gif" style="align: left;" alt="Salesforce" width="233" height="55" title="Salesforce"/>

<apex:panelGrid cellpadding="0" cellspacing="0" width="100%" border="0" columns="1" style="text-align: right;" id="Links">

<apex:panelGroup rendered="{!AND(ISPICKVAL($User.UserType,'Guest'), $Site.LoginEnabled)}">

<apex:outputLink value="{!$Page.SiteLogin}">{!$Label.site.login_button}</apex:outputLink>

<apex:outputText value=" | "/>

<apex:outputLink value="{!$Page.ForgotPassword}">{!$Label.site.forgot_your_password_q}</apex:outputLink>

<apex:outputText value=" | " rendered="{!$Site.RegistrationEnabled}"/>

<apex:outputLink value="{!$Page.SiteRegister}" rendered="{!$Site.RegistrationEnabled}">{!$Label.site.new_user_q}</apex:outputLink>

</apex:panelGroup>

<apex:outputLink value="{!$Site.Prefix}/secur/logout.jsp" rendered="{!NOT(ISPICKVAL($User.UserType,'Guest'))}">{!$Label.site.logout}</apex:outputLink>

</apex:panelGrid>

</apex:panelGrid>

</apex:component>

 

 

 

Message Edited by Bulent on 07-30-2009 09:11 AM
Message Edited by Bulent on 07-30-2009 09:22 AM

All Answers

BulentBulent

Take a look at the sample SiteHeader component. It has the code to hide and show links based on anonymous vs. authenticated access

 

 

<apex:component id="headerComponent">

<apex:panelGrid cellpadding="0" cellspacing="0" width="98%" border="0" columns="2" style="text-align: left;" id="theHeader">

<apex:image url="{!$Site.Prefix}{!$Label.site.img_path}/force_logo.gif" style="align: left;" alt="Salesforce" width="233" height="55" title="Salesforce"/>

<apex:panelGrid cellpadding="0" cellspacing="0" width="100%" border="0" columns="1" style="text-align: right;" id="Links">

<apex:panelGroup rendered="{!AND(ISPICKVAL($User.UserType,'Guest'), $Site.LoginEnabled)}">

<apex:outputLink value="{!$Page.SiteLogin}">{!$Label.site.login_button}</apex:outputLink>

<apex:outputText value=" | "/>

<apex:outputLink value="{!$Page.ForgotPassword}">{!$Label.site.forgot_your_password_q}</apex:outputLink>

<apex:outputText value=" | " rendered="{!$Site.RegistrationEnabled}"/>

<apex:outputLink value="{!$Page.SiteRegister}" rendered="{!$Site.RegistrationEnabled}">{!$Label.site.new_user_q}</apex:outputLink>

</apex:panelGroup>

<apex:outputLink value="{!$Site.Prefix}/secur/logout.jsp" rendered="{!NOT(ISPICKVAL($User.UserType,'Guest'))}">{!$Label.site.logout}</apex:outputLink>

</apex:panelGrid>

</apex:panelGrid>

</apex:component>

 

 

 

Message Edited by Bulent on 07-30-2009 09:11 AM
Message Edited by Bulent on 07-30-2009 09:22 AM
This was selected as the best answer
johnhurleyjohnhurley

Hi Bulent,

 

Thanks a LOT for the quick reply!  This sample code looks nothing like the code I see in my default SiteLogin component,  I really appreciate the information.  I'll work it into the header component now and let you know how it goes.

 

John

BulentBulent
my bad, not the SiteLogin component, it's the SiteHeader component
johnhurleyjohnhurley

Thanks a LOT for your help Bulent!  I appreciate it.  At first, the solution you gave me sorta helped me in what I was doing, but with a stroke of luck, the client changed his mind and wanted a separate login page instead of the login form in the site header, which makes things a LOT easier.

 

Thanks again! :-D

ManDarMan2ManDarMan2

What can be done to prevent an error with forceSSL if the user mistakenly enters in the default web URL for an Ideas Site (say) when they are already logged in? To clarify: I am logged in to an Ideas Site which uses HTTPS. I now type in the non-secure URL in the browser: http://xxx.force.com/. I am shown the login page, but when I click login, it throws an error: "Error occurred while loading a Visualforce page."

 

If I am to conditionallydisplay the login page, I need to detect if the user is already logged in. The secure page has the right usertype, profile etc. But the non-secure page doesn't have any info on the user to distinguish them from a non logged-in user. I have set cache=false on the login page.

 

Any tips?

 

BulentBulent

do you have to have the login page in HTTP? or you'll be ok to alway use HTTPS?

if you are okay to use https then you can put a check on the login component and redirect to https if it's called as http

current issue is in a way simulating a cross site scripting attack since their session is for secure URL and they're going back and posting from insecure one more time.