[SalesForce] Redirect to Page on Community Not Working

I recreated the login page with a visualforce page. Here is the site:

https://rockpool.force.com/portal

To reproduce the issue:
1. go to the site and click Forgot Password
2. type something in and click submit

It will then go to this url: /ForgotPasswordConfirm

But the page that is displayed is this url: /portal (the login page again)

Sometimes this doesn't happen and the correct page is displayed (forgotpasswordconfirm).

Here is what I have for the forgot password logic:

public with sharing class ForgotPasswordController {
public String username {get; set;}   

public ForgotPasswordController() {}

public PageReference forgotPassword() {
    boolean success = Site.forgotPassword(username);

    PageReference redirect = new PageReference('/apex/ForgotPasswordConfirm'); 
    redirect.setRedirect(true); 

    return redirect;
}

public PageReference cancel() 
{
    PageReference redirect = new PageReference('/apex/Portal'); 
    redirect.setRedirect(true); 

    return redirect;
}

}

And here is the markup for the forgot password confrim page:

<apex:page showHeader="false" title="{!$Label.site.forgot_password_confirmation}">

#wrap {display:table;height:100%}
</style>

</script>

<style>
* {
    margin: 0;
    padding: 0;
}
body {
    width: 100%;
    background: linear-gradient(180deg, #AEB3B7 50%, #94999F 50%);
}
#form_login {
    left: 50%;
    top: 50%;
    position: absolute;
    -webkit-transform: translate3d(-50%, -50%, 0);
    -moz-transform: translate3d(-50%, -50%, 0);
    transform: translate3d(-50%, -50%, 0);
    //width:550px;
    width: 315px;
    padding: 25px;
    background-color:white;
    box-shadow: 10px 10px 5px #66696E;
    border-radius: 25px;
}
@media all and (max-height: 430px) {
    .slds #formAndFishContainer {
        margin-top:60px;
    }
}
</style>
</head>
<body>
<div class="slds">
    <div id="main" style="width:auto;">
        <c:LoginCommunityHeader />
           <div id="form_login">
              <apex:outputText style="color:black;" value="{!$Label.site.temp_password_sent}"/>
            </div>

So if I just go to: https://rockpool.force.com/forgotpasswordConfirm

I get the login screen even though that is not what should be displayed for the forgotpasswordconfirm page. Does anyone know why?

EDIT

Here is the forgot password submit page:

<apex:page docType="html-5.0" showHeader="false" sidebar="false" standardStylesheets="false" applyHtmlTag="false" applyBodyTag="false" id="forgotPassword" controller="ForgotPasswordController" title="{!$Label.site.forgot_password}">
<html>
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1.0" />
      <apex:stylesheet value="{!URLFOR($Resource.SLDS103, 'assets/styles/salesforce-lightning-design-system-vf.css')}" />
      <apex:stylesheet value="{!$Resource.Community_Style}"/>
      <apex:includeScript value="{!$Resource.Community_JS}"/>
      <!--[if !IE 7]>
        <style type="text/css">
            #wrap {display:table;height:100%}
        </style>
      <![endif]-->
      <!--[if lt IE 9]>
          <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
      <![endif]-->

          <style>
* {
    margin: 0;
    padding: 0;
}
body {
    width: 100%;
    background: linear-gradient(180deg, #AEB3B7 50%, #94999F 50%);
}
#formAndFishContainer {
    left: 50%;
    top: 50%;
    position: absolute;
    -webkit-transform: translate3d(-50%, -50%, 0);
    -moz-transform: translate3d(-50%, -50%, 0);
    transform: translate3d(-50%, -50%, 0);
    width:550px;
}
#form_login {
    width: 370px;
    padding: 25px;
    background-color:white;
    box-shadow: 10px 10px 5px #66696E;
    border-radius: 25px;
    margin-left:85px;
}
.slds .loginTitle {
    font-size:27px;
    font-weight:bold;
}
.slds .loginTextBox {
    width:100%;
    -moz-border-radius: 15px;
    border-radius: 15px;
    border:solid 1px #94999F; 
    padding:5px;
    margin-bottom:10px;
    margin-top:10px;
}
.slds .loginButton {
    width:100%;
    -moz-border-radius: 15px;
    border-radius: 15px;
    border:solid 1px #94999F; 
    padding:5px;
    margin-bottom:10px;
    margin-top:10px;
    background-color:#99092D;
    color:white;
    text-transform: uppercase;
}
.slds .fish {
    float:right;
    margin-top:165px;
}
</style>
</head>
<body>
  <div class="slds">
    <div id="main" style="width:auto;">
      <c:LoginCommunityHeader />

      <div id="formAndFishContainer">
            <div id="form_login" style="float:left;">
              <h1 class="loginTitle">Forgotten Password</h1>
              <apex:outputText styleClass="title" value="{!$Label.site.enter_password}"/>
              <apex:form id="theForm">
                  <apex:pageMessages id="error"/>
                  <apex:panelGrid columns="3" style="margin-top:1em;">
                  <apex:inputText required="true" id="username" value="{!username}" html-placeholder="Username" styleClass="loginTextBox"/>
                  <apex:commandButton id="submit" value="{!$Label.site.submit}" action="{!forgotPassword}" styleClass="loginButton"/>
                  </apex:panelGrid>

              </apex:form>
              <apex:form >
              <center><apex:commandLink action="{!cancel}">Cancel</apex:commandLink></center>
              </apex:form> 
            </div>
    </div>         
     </div>
   </div>                  
 </body>
 </html>             

Best Answer

@Joe, The controller class has a redirect for success scenario and not for fail. If the fail clause is handled before the final return, then you can add some comment on the same page to show an error/information msg on this same page. This link has some insights too: Forgot password page on visualforce

Related Topic