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
SFDCmack08180939826349907SFDCmack08180939826349907 

Trying to build a code that uses system.resetpassword () method to overwrite the default community password reset Since it is not working due to Winter 16

The code appears to be working from the debug logs and resetting the password internally by clicking on the view button in Visualforce. I am not sure what I am missing:

* An apex page controller that exposes the site forgot password functionality
 */
Global class ForgotPasswordController {
    Global String username {get; set;}   
      
     
             
   Global ForgotPasswordController() {}
    
    Global PageReference forgotPassword() {
        User usr = [select Id from User where username=:username];
        system.debug(usr);
        boolean success = Site.forgotPassword(username);
        PageReference pr = Page.ForgotPasswordConfirm;
        pr.setRedirect(true);
       
       
        if (success) {
            system.resetPassword(usr.Id,True);         
            return pr;
        }
        return null;
    }
    
     Global static testMethod void testForgotPasswordController() {
        // Instantiate a new controller with all parameters in the page
        ForgotPasswordController controller = new ForgotPasswordController();
        controller.username = 'test@salesforce.com';        
    
        System.assertEquals(controller.forgotPassword(),null); 
    }
}

When you go to communities and conduct a password reset outside it does not work why?
SFDCmack08180939826349907SFDCmack08180939826349907
<apex:page id="forgotPassword" showHeader="false" controller="ForgotPasswordController" title="{!$Label.site.forgot_password}" standardStylesheets="true">
 <apex:composition template="{!$Site.Template}">
    <apex:define name="body">  
      <center>
        <apex:panelGrid bgcolor="white" columns="1" style="align: center;"> 
          <br/>
          <br/>
          <apex:panelGrid width="758" cellpadding="0" cellspacing="0" bgcolor="white" columns="1" style="border:1px solid #ccc;"> 
            <br/>
            <apex:outputPanel layout="block" style="background-color: white; border: 1px solid #ccc; padding: 0px; margin-top: 10px; margin-bottom: 0px; margin-left: 10px; margin-right: 10px;">
              <apex:panelGrid width="758" cellpadding="0" cellspacing="0" bgcolor="white" columns="2"> 
                <apex:image url="{!$Site.Prefix}{!$Label.site.img_path}/clock.png"/>
                <apex:panelGroup >
                  <br/>
                  <apex:outputText style="font-size: larger; font-weight: bold;" value="{!$Label.site.enter_password}"/>
                  <br/>
                  <apex:form id="theForm">
                    <apex:messages id="msg" styleClass="errorMsg" layout="table" style="margin-top:1em;"/>
                    <apex:panelGrid columns="3" style="margin-top:1em;">
                      <apex:outputLabel value="{!$Label.site.username}" for="username"/>
                      <apex:inputText required="true" id="username" value="{!username}"/>
                      <apex:commandButton id="submit" value="{!$Label.site.submit}" action="{!forgotPassword}"/>
                    </apex:panelGrid> 
                    </apex:form>                  
                  <br/>
                </apex:panelGroup>
              </apex:panelGrid> 
             </apex:outputPanel>
            <c:SiteFooter />
          </apex:panelGrid> 
       </apex:panelGrid>
      </center>
      <br/>
    </apex:define>
  </apex:composition>
</apex:page>