Uda
January 28, 2021, 2:17pm
1
Hello!
Have been digging in docs for few days and get stuck on my task.
Is there is a way I can change user password/login/email without UI but via API?
I have a dump of Wiki and have to update users email and password with current ones.
Will deeply appreciate if you’ll show me the way I can create and send request to the Wiki.
PS I have previous and current admin credentials if it is needed
surli
January 28, 2021, 2:46pm
2
Hi,
We started to work on a User API for this kind of things, but right now it doesn’t allow to change user password. The documentation is there: https://extensions.xwiki.org/xwiki/bin/view/Extension/User%20Module/API/ and what you need to manipulate is UserProperties, defined here: xwiki-platform/xwiki-platform-core/xwiki-platform-user/xwiki-platform-user-api/src/main/java/org/xwiki/user/UserProperties.java at master · xwiki/xwiki-platform · GitHub
Now note that each user in XWiki is an XWikiDocument with a dedicated xobject of type XWikiUser, so basically you can just manipulate the documents to perform the changes you need if UserProperties doesn’t expose enough API or if you’re using an older wiki. Don’t hesitate to submit any feature request to improve this API on https://jira.xwiki.org .
Hope that helps.
Uda
January 28, 2021, 3:25pm
3
Thank you very much for a fast answer!
Your notes will help for sure. Though could you please be so kind to explain, where exactly to use it?
As I understand, I will need to create JS-script and than run it “For example from a Java component”.
But what is Java component here and what way I can pass script to it?
surli
January 28, 2021, 3:39pm
4
The easiest way to manipulate the API I pointed is by using a velocity or a groovy script in XWiki. You can find documentation about scripting in XWiki there: https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Scripting/
Note that you might be able to do what you want just by using the REST API documented here: https://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/XWikiRESTfulAPI#HObjectresources
As I said previously since users are xobjects in a document, you are able to modify the properties of those objects. Now you have to dig a bit to find exactly the names of the properties you want to modify etc.
Uda
January 28, 2021, 3:41pm
5
Thanks for you help!
Will check links you have provided and try to finish my task.
Have a nice day! =)
Uda
February 2, 2021, 2:54pm
6
And hello again)
Here xwiki-platform/xwiki-platform-core/xwiki-platform-user/xwiki-platform-user-api/src/main/java/org/xwiki/user/UserProperties.java at master · xwiki/xwiki-platform · GitHub I can use several properties for my aim, but there is still problem with a password.
As far as I can see there is no property I can use for it. I’ve searched on code and see some scripts for updating and reseting passwords, but no one from them seems to be useful in my situation.
Is it possible at all to change it not from UI?
Yes, this is not implemented currently.
Yes, you need to change the password xproperty of the XWikiUsers xobject in the user doc.
See https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Scripting/XWikiVelocityTraining/#HManipulationofXObjects for example.
Uda
February 2, 2021, 3:13pm
8
Ok, thanks, probably I as usual choose the most complicated way. Will try to follow your advice)