4

I tried following this resource with some code from here. Under Communities > Settings > Administration I have the login page set to Custom_Sign_In. I am sent to my custom signin page when appropriate, but when I sign in, I get sent back to my custom sign in page and the URL looks like this:

https://developer-edition.na34.force.com/wpu/Custom_Sign_In?refURL=http%3A%2F%2Fdeveloper-edition.na34.force.com%2Fwpu%2FCustom_Sign_In

I want it to go to https://developer-edition.na34.force.com/wpu/ and I cannot figure out how to do so. I am assuming there is a problem with my controller, but I don't know what.

When I change the login page to the default, I can log in without problems.

Here's my code:

Custom Sign In Page

<apex:page applyBodyTag="false" docType="html-5.0" showHeader="false" standardStylesheets="false" controller="CustomLoginController"
title="{!$Label.site.site_login}">

        <apex:form forceSSL="true" styleClass="form-signin col-md-4 col-centered">
            <apex:actionFunction name="login" action="{!login}" />
            <h2 class="form-signin-heading">Please sign in</h2>
            <label for="inputEmail" class="sr-only">Email address</label>
            <input type="email" id="inputEmail" class="form-control" placeholder="Email address" required="required" autofocus="autofocus" />
            <label for="inputPassword" class="sr-only">Password</label>
            <input type="password" id="inputPassword" class="form-control" placeholder="Password" required="required" />
            <apex:commandButton value="Sign in" styleClass="btn btn-lg btn-primary btn-block" action="{!login}" />

        </apex:form>

</apex:page>

CustomLoginController

public class CustomLoginController {

    public String username{get; set;}
    public String password {get; set;}

    public pageReference login()
        {  
            return Site.login(username,password,null);
    }
}

CommunitiesLogin Page

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

CommunitiesLanding Page

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

CommunitiesLoginController

global with sharing class CommunitiesLoginController {

    global CommunitiesLoginController () {}

    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.getPathPrefix() + '/Custom_Sign_In?startURL=' +
        EncodingUtil.urlEncode(startURL, 'UTF-8'));
    }

}

CommunitiesLandingController

public with sharing class CommunitiesLandingController {


    public PageReference forwardToStartPage() {
        return Network.communitiesLanding();
    }

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


    public CommunitiesLandingController() {}
}
1

The controller was fine. The fault was in my visualforce page. Here is the corrected code:

<apex:form forceSSL="true" styleClass="form-signin col-md-4 col-centered">
        <apex:actionFunction name="login" action="{!login}" />
        <h2 class="form-signin-heading">Please sign in</h2>
        <label for="username" class="sr-only">Email address</label>
        <apex:inputText value="{!username}" id="username" styleClass="form-control" html-placeholder="Email" />
        <label for="password" class="sr-only">Password</label>
        <apex:inputSecret id="password" value="{!password}" styleClass="form-control" html-placeholder="Password" />
        <apex:commandButton value="Sign in" styleClass="btn btn-lg btn-primary btn-block" action="{!login}" />

    </apex:form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.