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
B2000B2000 

Custom Portal Login Page Using login_portal.jsp

I am using Sites to create a custom VF portal login page.  The custom VF portal login page works except when an invalid username and/or password is submitted.  When an invalid username and/or password is submitted, the default SF portal login page is displayed and not the current custom VF portal login page.  Is there a parameter that can be passed to the login_portal.jsp to redirect to the current custom VF portal login page.   Here is the current code:

 

 

Global pageReference login()
  {
    String startURL = 'https://naX.salesforce.com/secur/login_portal.jsp';
    startURL += '?orgId=00Dxxxxxxxxxxx&portalId=060xxxxxxxxxx&loginType=3';
    startURL += '&startURL='; 
    startURL += '&loginURL=';
    startURL += '&useSecure=true';
    startURL += '&un=' + username;
    startURL += '&pw='+ password;
    startURL += '&retURL=http://npifinancial.force.com/SmartSpend';
    
     pageReference p = new PageReference(startURL);
     p.setredirect(true);
     return p;
    
  }

 

 

Best Answer chosen by Admin (Salesforce Developers) 
B2000B2000

Unfortunately that didn't work.  Here is the solution that worked for me.

If a valid PageReference is returned when calling the site.login, then there was a successful login.

Redirect to the portal.jsp.

Otherwise redirect back to the site login page.

 

 

global pageReference login()
{
  String startUrl = 'https://na6.salesforce.com/secur/login_portal.jsp';
  startUrl += '?orgId=00Dxxxxxxxxx&portalId=060yyyyyyyyyy&loginType=3';
  startUrl += '&startUrl='; 
  startUrl += '&loginUrl=';
  startUrl += '&useSecure=true';
  startUrl += '&un=' + username;
  startUrl += '&pw='+ password;

  PageReference portalPage	= new PageReference(startUrl);
  portalPage.setRedirect(true);
  PageReference p = Site.login(username, password, startUrl);
  if (p == null) return Site.login(username, password, null);
  else return portalPage;
}

 

 

All Answers

Pradeep_NavatarPradeep_Navatar

In a similar type of application, i have developed customer portal login functionality by using component and visual force page. It works fine when i give invalid password/Username , it gives site generated message.

 

I have used site.login(username.password,starturl) method in apex and shown the message as an alert in component.

B2000B2000

Unfortunately that didn't work.  Here is the solution that worked for me.

If a valid PageReference is returned when calling the site.login, then there was a successful login.

Redirect to the portal.jsp.

Otherwise redirect back to the site login page.

 

 

global pageReference login()
{
  String startUrl = 'https://na6.salesforce.com/secur/login_portal.jsp';
  startUrl += '?orgId=00Dxxxxxxxxx&portalId=060yyyyyyyyyy&loginType=3';
  startUrl += '&startUrl='; 
  startUrl += '&loginUrl=';
  startUrl += '&useSecure=true';
  startUrl += '&un=' + username;
  startUrl += '&pw='+ password;

  PageReference portalPage	= new PageReference(startUrl);
  portalPage.setRedirect(true);
  PageReference p = Site.login(username, password, startUrl);
  if (p == null) return Site.login(username, password, null);
  else return portalPage;
}

 

 

This was selected as the best answer
EBenderEBender

Could someone post what the basic VF page would look like to capture the username and password, and also the call that would pass those into the controller?

rpp0910rpp0910

how do we customize the login page of customer portal . we are not using sites . 

 

can we give a dynamic logic message ?

KKarthikKKarthik
I have followed similar approach and facing a issue while authenticating portal user from sites and redirecting back to portal home. After login from custom logn controller the page is been redirected back to the standard portal login page. Verified the login history for the user and found that the first request has made success, and next request while hitting frontdoor.jsp it some how it comes back to standard portal login page  with status of invalid password. Not sure what im missing in the code. I have followed the same way that it was suggested above. Any thoughts would be appreciated..
Cong Hui 1Cong Hui 1
I followed this example, ending with the following code:
global PageReference login() {
 
      //static org-id and portal id
      String strOrgID = 'XXXXX';
      String strPortalID = 'YYYYY';
      String strURL = 'https://naZZZZ.salesforce.com';
      //start url of the page
      String startUrl = strUrl + '/secur/login_portal.jsp?orgId=' + strOrgID + '&portalId=' + strPortalID + '&loginType=3';
      
        startUrl += '&useSecure=true';
        startUrl += '&un=' + username;
        startUrl += '&pw=' + password;
 
        //set reference and attempt login
        PageReference portalPage = new PageReference(startUrl);
        portalPage.setRedirect(true);
        PageReference p = Site.login(username, password, startUrl);
 
        //if login==false
        if (p == null) return Site.login(username, password, null);
        //else return to custom login
        return portalPage;
    }

Which, as you can see, is basically a copy&paste of the OP's code.
However, the (p == null) portion seems to evaluate to "true" even when the login is successful, sending me back to my custom login page.
As experiment, I replaced everything after //if login==false with a return to portalPage, and it simply redirected to the default login page on a failed login and into the actual portal on a successful login.
I'm not sure what's making my code different from the OP's code, and would appreciate it if anyone could help me out with some advise. Thanks.