[英]Adding new user to ejabberd through Smack android api
I have installed ejabberd on my local server.我已经在我的本地服务器上安装了ejabberd 。 This was then tested in spark for its functionality and it worked fine.
然后在 spark 中对其功能进行了测试,并且运行良好。 Now I want to add a new user through the android app.
现在我想通过 android 应用添加一个新用户。
I tried adding a new user through spark and it worked fine.我尝试通过 spark 添加一个新用户,效果很好。 The fields I have given are
uesrname
, password
, confirm password
, server
.我给出的字段是
uesrname
、 password
、 confirm password
、 server
。 But when I tried to do it using the smack api in the android app it gave the following error:但是,当我尝试在 android 应用程序中使用smack api执行此操作时,出现以下错误:
org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: forbidden - auth
I was using createAccount() , seen in the code I was using below, to create the new account in smack.我正在使用createAccount() ,在下面使用的代码中看到,在 smack 中创建新帐户。
AccountManager accountManager = AccountManager.getInstance(conn1);
try {
accountManager.createAccount("tryuser", "qwerty");
Log.i("log", "created user successfully");
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
I have checked if it supports new account creation by supportsAccountCreation() and it returned true
.我已经检查过它是否支持通过supportsAccountCreation()创建新帐户并返回
true
。
I have changed my register
rule to allow all
in ejabberd server.我已更改我的
register
规则以allow all
在 ejabberd 服务器中。 and i don't think it has any problem because i can create account from spark, but getting error in smack.我不认为它有任何问题,因为我可以从 spark 创建帐户,但在 smack 中出错。
I have looked into the following SO questions related to this topic but no luck.我已经研究了与此主题相关的以下 SO 问题,但没有运气。
Does anyone have any suggestions on how to solve this?有没有人对如何解决这个问题有任何建议?
Please give a try with below -请尝试以下 -
AccountManager accountManager = AccountManager.getInstance(connection);
try {
if (accountManager.supportsAccountCreation()) {
accountManager.sensitiveOperationOverInsecureConnection(true);
accountManager.createAccount("userName", "password");
}
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
And you also need to set below in ejabberd.cfg (config file)并且您还需要在 ejabberd.cfg(配置文件)中进行以下设置
{access, register, [{allow, all}]}.
which means - In-band registration allows registration of any possible username.这意味着 - 带内注册允许注册任何可能的用户名。 To disable in-band registration, replace 'allow' with 'deny'.
要禁用带内注册,请将“允许”替换为“拒绝”。
And in mod_register (module in same config file) please set below -在 mod_register (同一配置文件中的模块)中,请在下面设置 -
{access_from, register}
& before that please check you are connected to XMPP server. & 在此之前,请检查您是否已连接到 XMPP 服务器。
Probably this will resolve your issue.可能这将解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.