0

want forgot password feature with lightning component in community i have seen many reference in visual force page but not able to find it in lightning, so how can i achieve it in lightning component

VisualForce:

Apex:

    public class TestForgotController { 


    public String username {get; set;} 

    public PageReference forgotPassword() { 

    if(username != '') {  
         User UserToReset = [Select Id, Username from User where Username = :Username and IsActive = true LIMIT 1];  
         boolean success = Site.forgotPassword(username);  
         PageReference pr = Page.CommunityForgotPasswordConfirm;     
         pr.setRedirect(true);  
         return pr;  
    }  
    return null; 

    }  
}

want same thing achieve in lightning component

1

We have implemented this using below code and it is working on prod org as well.

     @AuraEnabled
  public static String forgotPassowrd(String userid) {
    String procesMsg = '';
    User user = [SELECT Id FROM User WHERE Id = :userid]; //Added username in query for test class
    if (user != null) {
      if (Site.isValidUsername(user.Username)) {
        Site.forgotPassword(user.Username);
        procesMsg = 'LoginResetSuccess';
      } else {
        procesMsg = 'LoginResetWarning';
      }
    }
    return procesMsg;
  }

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.