Customize communities login page

Hi I’m attempting to use a custom visualforce page to login external communities users (customers). I have read the implementation guide this guide and followed all the instructions. But when I enter the credentials for a test user on my VF login page, it takes me to the landing page instead of the homepage. I have also looked at this doc for customizing portal logins but I’m not sure what I’m missing. Below are my customLoginController,CommunitiesLandingController, SiteController, CommunitiesLogin and CommunitiesLanding.

global with sharing class CommunitiesLoginController {

    global CommunitiesLoginController () {}

    // Code we will invoke on page load.
    /**global PageReference forwardToAuthPage() {
        String startUrl = System.currentPageReference().getParameters().get('startURL');
        String displayType = System.currentPageReference().getParameters().get('display');
        return Network.forwardToAuthPage(startUrl, displayType);
    }*/

    global PageReference forwardToCustomAuthPage() {
        String startUrl = System.currentPageReference().getParameters().get('startURL');
        return new PageReference(Site.getPrefix() + '/MYCustomerPortalLogin?startURL=' +
        EncodingUtil.urlEncode(startURL, 'UTF-8'));
    }
}

public with sharing class CommunitiesLandingController {

    // Code we will invoke on page load.
    public PageReference forwardToStartPage() {
        return Network.communitiesLanding();
    }

    public PageReference forwardToCustomAuthPage() {
        String startUrl = System.currentPageReference().getParameters().get('startURL');
        return new PageReference(Site.getPrefix() + '/MYCustomerPortalLogin?startURL=' +
        EncodingUtil.urlEncode(startURL, 'UTF-8'));
    }

    public CommunitiesLandingController() {}
}

global with sharing class SiteLoginController {
    global String username {get; set;}
    global String password {get; set;}

    global PageReference login() {
        String startUrl = System.currentPageReference().getParameters().get('startURL');
        return Site.login(username, password, startUrl);
    }

     global SiteLoginController () {}
}

<apex:page id="loginPage" controller="CommunitiesLoginController" action="      {!forwardToCustomAuthPage}" title="{!$Label.site.site_login}"> 
</apex:page>


<apex:page id="communitiesLandingPage" controller="CommunitiesLandingController" action="{!forwardToCustomAuthPage}" title="{!$Label.site.site_login}">
</apex:page>

<apex:page showHeader="false" controller="SiteLoginController"
standardStylesheets="false" sidebar="false">

<head>
    <title>Customized Customer Login</title>

    <script type='text/javascript'>
    function noenter(ev)  {
        if (window.event && window.event.keyCode == 13 || ev.which == 13) {
            javascriptLogin();
            return false;
         } else {
              return true;
         }
     }
    </script>
    <style type="text/css">
         fieldset.login {
            background: none repeat scroll 0 0 white;
            border: 1px solid #AAAAAA;
            border-radius: 5px 5px 5px 5px;
            font-family: "Century Gothic","Lucida Grande",Arial,sans-serif;
            margin: 0 0 25px;
            padding: 10px;
        }

        fieldset.login label {
            clear: both;
            color: #333333;
            display: block;
            font-size: 12px;
            font-weight: bold;
            padding-top: 10px;
        }

        fieldset.login input.text {
            border: 1px solid #AAAAAA;
            color: #5E5E5E;
            float: left;
            padding: 5px;
            width: 320px;
        }

        .clear {
            clear: both;
        }

        .content {
            margin: 0 auto;
            width: 419px;
        }
    </style>
</head>
<body>
    <div class="content">
        <div class="login">
            <apex:form id="loginForm" forceSSL="true">
                <apex:actionFunction name="javascriptLogin" action="{!login}" />
                <fieldset class="login">
                    <b>Customer Login</b>
                    <apex:pageMessages id="error" />

                    <apex:outputLabel styleClass="label"
                        value="{!$Label.site.username}" for="username" />
                    <apex:inputText styleClass="text" id="username"
                        value="{!username}" />
                    <apex:outputLabel styleClass="label"
                        value="{!$Label.site.password}" for="password" />
                    <apex:inputSecret styleClass="text" id="password"
                        value="{!password}" onkeypress="return noenter(event);" />

                    <div class="clear"></div>
                    <span class="form-link"> </span>
                    <div class="clear"></div>
                    <p>
                        <apex:commandButton value="Login" styleClass="button"
                            action="{!login}" id="submitbutton" />
                    </p>
                </fieldset>
            </apex:form>
        </div>
    </div>
</body>
</apex:page>

Thanks.

Answer

Salesforce support engineer got back to me and he identified the problem as an error in the Communities Implementation Guide. Here are the changes he suggested for steps # 7 and 15 in the implementation guide(I have implemented these changes and it works):

Step 7:

Add the following code:

 public PageReference forwardTocustomStartPage() {
     return new PageReference('/LANDING_VF_PAGE_NAME_WITH PARAMETERS_IF_ANY');
 }

Step 15. In the first line of code, add the following:

action="{!forwardTocustomStartPage}"

Thanks.

Attribution
Source : Link , Question Author : sw6 – KTBFFH , Answer Author : sw6 – KTBFFH

Leave a Comment