我希望通过 API 自动更改用户名,使其与电子邮件地址匹配。
我们社区的政策规定,对于电子邮件地址为 firstname.infix.lastname@company.com 的用户,用户名必须为 firstname.infix.lastname。
到目前为止,我一直是手动通过管理界面在用户注册后不久更改不符合规则的用户名,现在希望通过 API 或类似方式实现自动化。
我在 Discourse API 文档中未找到相关调用——是否隐藏了重命名用户的方法?
是否有替代方案,例如能否在注册时直接强制执行该规则?
If everyone works for the company, the usual solution is to use sso. They way they can’t create the wrong username.
I would like to dig this back up as I have a similar request. I need a newly registered user’s username to be changed to Firstname_Lastname automatically, but I am already using an SSO (Memberful) and they refuse to do this for ‘security concerns’
so I have to do it manually each time a person signs up and inevitably the user emails me about it before I have a chance to change it because it is super boring using only the first name. So is there anyway to to add this as a task? It would of course have to check if the name exists and add a numeral behind it if so. Thanks!
from How does one change a username via the API? - #2 by blake :
Try this endpoint instead:
curl -i -sS -X PUT "http://127.0.0.1:3000/u/blake/preferences/username.json" \ -H "Content-Type: multipart/form-data;" \ -F "api_key=a66d01fbe98cc51b2747d8bfe99f81d7adca18317fbf3c43aa20f340d8e25bfe" \ -F "api_username=system" \ -F "new_username=blake2"And it will output:
{"id":1,"username":"blake2"}