Set user field fails in plugin
-
Hello,
I created a plugin from a template that authenticates against an LDAP server, the code works fine but i also wanted to set some user fields if the user needs to be created. I looked up the code and it seems that i should be using : user.setUserField(uid, 'fullname', user.givenName + " " + user.sn); but this causes the whole plugin to error. User is declared earlier in my code and works fine since the user is created if i remove the user.setUserField.
My code is below:
ldap.authenticate(username, password, function (err, user) { if (err) { next(new Error('[[error:invalid-username-or-password]]')); } else { User.getUidByEmail(user.mail, function (err, uid) { if (err) { return callback(err); } if (!uid) { User.create({ username: user.sAMAccountName.toLowerCase(), email: user.mail }, function (err, uid) { if (err) { return callback(err); } user.setUserField(uid, 'fullname', user.givenName + " " + user.sn); next(null, { uid: uid }, '[[success:authentication-successful]]'); }); } else { next(null, { uid: uid }, '[[success:authentication-successful]]'); } }); } ldap.close(function (err) { if (err) { console.log("LDAP closing error: %s", err); } else { console.log("Success in closing"); } }); });
Am i doing something wrong?
Thanks
Copyright © 2024 NodeBB | Contributors