+ Start a Discussion

User Authentication for websites



I am trying to setup the Customer Portal user authentication using Force.com sites. I followed the steps that are provided to do this setup and there were no hitches in it. I also setup the default Site Login page and tried to login, when I provide correct customer portal user details and click on submit the sites login page just refreshes and does nothing, when I provide incorrect details to login it throws proper error messages.

I need help in completing the authentication process and redirecting the customers towards their home page.




Shashikant SharmaShashikant Sharma

Are you using site.login method in controller, debug what it returns. One more thing try to login with contact for this user using the option in contact login as portal user.


Also, if possible, a link to your site would be helpful.


I would be willing to bet you're running into an unauthorized page error where it's redirecting you back to the login page on a successful login. You can test this one of two ways - after it redirects you back to your login page - try changing the URL to access a page you know exists. For example: name.force.com/Account -- if you can access it, that's most likely what's going on.


The other way to make sure you know that's what's going on is check your default web address for the Site. If it's something along the lines of "name.force.com/portal" then that's most likely where your problem is. If this is happening, read on!


Explanation of what's going on


Apparently with Sites, SF did not add code that automatically exempts the default web address from the "startUrl" variable (not sure why). Because of that, the login page considers the "/portal" (from the example above) to be passing the startUrl. So when you login, salesforce attempts to access a page called "Portal" which doesn't exist (hence the unauthorized error) and thus the redirect fails.


The Fix


The easiest way to get around this is to modify your SiteLoginController to something like I've done below (credit for the modifications to make to the SiteLoginController goes to this post):



if (startUrl == null || startUrl == '/portal') startURL = (Site.getPrefix() == null ? '' : Site.getPrefix()) + '/apex/Visualforce_Page_Name';

 Note that for the /apex/Visualforce_Page_Name you may not need /apex/ for your org. Really, you just need a relative path.