0

I am trying to make use of the forgot password functionality in my community(aloha template). I am not sure what is going wrong. This is my component:

<!-- add implements="forceCommunity:availableForAllPageTypes" to surface the component in community builder --><aura:component controller="LightningForgotPasswordController">
<aura:attribute name="usernameLabel"        type="String" required="false" default="Your email address"/>
<aura:attribute name="passwordLabel"        type="String" required="false" default="Your Password"/>
<aura:attribute name="loginButtonLabel"     type="String" required="false" default="LOG IN"/>
<aura:attribute name="RegisterButtonLabel"  type="String" required="false" default="SIGN UP"/>
<aura:attribute name="cancelButtonLabel"    type="String" required="false" default="Cancel"/>
<aura:attribute name="sendEmailButtonLabel" type="String" required="false" default="SEND EMAIL"/>
<aura:attribute name="labels"               type="Object"   description="labels of the fields"/>
<aura:attribute name="stepnumber"       access="public"             type="integer"  description="number of step"/>
<aura:attribute name="isManditory"      type="boolean"      default="true"  access="public" />
<aura:attribute name="showError" type="Boolean" required="true" description="" default="false" access="private"/>
<aura:attribute name="errorMessage" type="String" required="false" description="" access="private"/>
<aura:attribute name="checkEmailUrl" type="String" required="true"/>
<aura:attribute name="submitButtonLabel" type="String" required="false" default="Send Password Reset Email"/>

<div class="slds-grid">

    <div class="slds-col ">
        <div class="slds-size_1-of-2">
            <div class="start_middle"> 

                <div class=" slds-card slds-p-left--xx-large cardWidth ">



                    <div class="slds-text-heading--large slds-p-top--large slds-p-bottom--medium boldFont "><b>{!$Label.c.B2B_Partners_Forgot_Password}</b></div>
                    <p class="slds-theme--shade lightFont">{!$Label.c.B2B_Partners_Forgot_Password_Body} </p>


                    <div id="sfdc_username_container" class="slds-form slds-p-top--medium">
                        <lightning:input type="email" aura:id="username" value="" class="slds-lookup__search-input slds-input--bare slds-has-divider--bottom input sfdc_usernameinput sfdc"  name="username" label="{!v.labels.email__c+' '}" onchange="{!c.onKeyUp}"/>
                    </div>
                    <div class="slds-text-align--right slds-p-top--xx-large">
                        <lightning:button label="{!v.cancelButtonLabel}" variant="bare" onclick="{!c.onClickStep1}" iconName="utility:left" class=" pressed bookFontLink"/>
                        <lightning:button label="{!v.sendEmailButtonLabel}" aura:id="submitButton" variant="brand"  onclick="{!c.handleForgotPassword}"  class="slds-p-left--medium  sfdc_button boldFontWhite"/>
                    </div>


                </div>
            </div>
        </div>
    </div>

</div>

This is my javascript controller:

handleForgotPassword: function (component, event, helper) {
    helper.forgotPassword(component, event, helper);
    console.log('FGPW2')
    var stepnumber     = component.get('v.stepnumber');
    component.set('v.stepnumber', stepnumber=3);
},

onKeyUp: function(component, event, helper){
//checks for "enter" key
if (event.getParam('keyCode')===13) {
    helper.handleForgotPassword(component, event, helper);
}
}

This is my helper:

 ({
  forgotPassword: function (component, event, helper) {

    var username = component.find("username").get("v.value");
    var checkEmailUrl = './login2';
    var action = component.get("c.resetPassword");

    action.setParams({username:username, checkEmailUrl:checkEmailUrl});
    action.setCallback(this, function(a) {
      var rtnValue = a.getReturnValue();
      console.log('rtnValue'+rtnValue)
      if (rtnValue != null) {
       component.set("v.errorMessage",rtnValue);
       component.set("v.showError",true);
         console.log('rtnValue'+rtnValue)
      }
    });
     $A.enqueueAction(action);
   }
 })

This is my apex class:

 global class LightningForgotPasswordController {

public LightningForgotPasswordController() {

}

@AuraEnabled
public static String resetPassword(String username, String checkEmailUrl) {
    try {
        Site.forgotPassword(username);
        ApexPages.PageReference checkEmailRef = new PageReference(checkEmailUrl);
        if(!Site.isValidUsername(username)) {
            return Label.Site.invalid_email;
        }
        aura.redirect(checkEmailRef);
        return null;
    }
    catch (Exception ex) {
        return ex.getMessage();
    }
}

}

I am sending my username correctly back to the class. But it is not sending the email. How do I solve this? I have verified in Setup -> Email Administration -> Deliverability that Access Level is set to 'All email'. I am trying to reset in the community. And the email template is configured in the right way. Any ideas?

Your Answer

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

Browse other questions tagged or ask your own question.