1

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 Answer 1

2

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,Username 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;
  }
6

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .