Try it
Try it

Reputation: 315

aem 6.1 extend user properties

Printscreen additional fields useradmin

How can I add some new User Properties to the CQ Users?

I found an solution but it don't work --> http://experience-aem.blogspot.ch/2014/01/aem-cq-56-extend-useradmin-add-new-user.html

I tried to manipulate in CRX the UserProperties.js with new Properties, I see them in useradmin but if I try to add the new propertie in Java Code (not via useradmin) I can save it without error, but the value is empty in useradmin. And if I try to add some value via useradmin for the new propertie, all user gets the same value.

How can I add new User Properties, that I can set the Value via Java code like the standard properties.

user = userManager.createUser(username, password);
                ValueFactory valueFactory = session.getValueFactory();
                emailValue = valueFactory.createValue(email);
                givennameValue = valueFactory.createValue(givenname);
                nameValue = valueFactory.createValue(name);

                //User class just accepts Value Object
                user.setProperty("profile/" + UserProperties.EMAIL, emailValue);
                user.setProperty("profile/" + UserProperties.FAMILY_NAME, nameValue);
                user.setProperty("profile/" + UserProperties.GIVEN_NAME, givennameValue);

Upvotes: 1

Views: 2078

Answers (3)

marveshy
marveshy

Reputation: 76

i hope this may helps you the file exist on http://[host name]:[port]/crx/de/index.jsp#/libs/cq/security/widgets/source/widgets/security/UserProperties.js

and you will have two major properties the first one is for the user this.userForm the other one is this.groupForm for groups.

Upvotes: 0

Try it
Try it

Reputation: 315

I found an solution. Go to crx /libs/cq/security/widgets/source/widgets/security/UserProperties.js

  1. add the fields you need in the items array of the user (Caution - there are items for user and items for groups in the same place)

  2. in the loadRecord method of your JS, you have to add each new field to the "record" object

           "items":[{
    
                "xtype":"textfield",
                "fieldLabel":CQ.I18n.getMessage("Mail"),
                "anchor":"100%",
                "vtype":"email",
                "msgTarget":"under",
                "name":"email"
            },{
                "xtype":"textfield",
                "fieldLabel":CQ.I18n.getMessage("My Field"),
                "anchor":"100%",
                "msgTarget":"under",
                "name":"myfield"
            },{
                "xtype":"textarea",
                "fieldLabel":CQ.I18n.getMessage("About"),
                "anchor":"100% -155",
                "name":"aboutMe"
    
    
        }],
    
    
    loadRecord: function(rec) {
    this.enableUserSaveButton(false);
    this.enableGroupSaveButton(false);
    
    var type = rec.get("type");
    if (type=="user") {
        this.activeForm = this.userForm;
        this.hiddenForm = this.groupForm;
        if (rec.id==CQ.security.UserProperties.ADMIN_ID) {
            this.pwdButtons.each(function(bt) {bt.hide(); return true;} )
        } else {
    
            this.pwdButtons.each(function(bt) {bt.show(); return true;} )
        }
    
    } else {
        this.activeForm = this.groupForm;
        this.hiddenForm = this.userForm;
    }
    //is loading additional property from json and show it in formular
    rec.data["myfield"] = rec.json["myfield"];
    
    this.activeForm.getForm().loadRecord(rec);
    

In the java code you can then add the new properties via the "user" object to the new properties. Note that the properties are put into the subfolder "profile".

user.setProperty("profile/" +  "myfield", myFieldValue);

Upvotes: 1

mish
mish

Reputation: 1065

Did you try the second approach, posted by "pedro" in the link you've posted? It probably has to do with pushing the new field to the record: http://experience-aem.blogspot.com/2014/01/aem-cq-56-extend-useradmin-add-new-user.html?showComment=1390804750445#c2823498719990547675

Upvotes: 0

Related Questions