How to fetch password from Alfresco UI page which

2019-09-15 04:55发布

问题:

I had used this code for auto generation of mails. Now the problem is password shown in the mail is the password as generated by the script. I want the password to be fetched from alfresco new user page, where the admin has created the password for the new user not any random string. Below is the script that i generated for automatic mail generation.

if (document.isContainer && document.displayPath == "/Company Home/User Homes") {
var owner = document.properties["cm:owner"];
var pNode = people.getPerson(owner);
if (pNode!=null && pNode.exists()){

    var userName = pNode.properties.userName;
    var email = pNode.properties.email;
    var randPassword = Math.random().toString(36).substr(2, 30)+"-"+(Date.now());

    people.setPassword(userName, randPassword);
    logger.debug("Invitation mail: User "+userName+" password has been changed.");

    var mail = actions.create("mail");
    //mail.parameters.from = "noreply@customdomain";
    mail.parameters.to = email; 
    mail.parameters.subject = "Welcome to the site, login: "+userName+", password: "+randPassword;
    mail.parameters.template = companyhome.childByNamePath("Data Dictionary/Email Templates/Invite Email Templates/invite_user_email.ftl");
    var templateModel = new Array();
    templateModel['newPassword'] = randPassword; // use ${newPassword} expression inside template
    mail.parameters.template_model = templateModel;
    mail.executeAsynchronously(document);
    logger.debug("Invitation mail has been sent to "+email);
} else {
    logger.warn("Invitation mail: User not found: "+owner);
}
} 

Please guide me how to proceed further.

回答1:

You can't decode password from its hash. You can only encode new password and match it with hash.

You can modify Alfresco Share to store raw password in custom user aspect, but this is very bad practice. Admin shouldn't know user password.



回答2:

The final answer has been posted in Auto-generation of email with username and random password on creation of new user-- by @Imagine