Check user is registered or not in ejabberd Server..

I have integrated ejabberd in my site with JWCHAT as client. In my site serveral users will login and i have changed functionality, that on first login users get registered in ejabberd server and can start chat.

I want to know how to know a user is registered or not?.Suppose if a user is login to site first time and due to some reason he not get registered to ejabberd server,then I need to test and regsiter him in the server on the second time.

Can anyone please help me.

Thanks in advance

Kiran

You can easily know which

You can easily know which user is registered by using the web admin interface. Also, you can access this information while your are logged in on your jabber server with your administrator account, by browsing the services of your server and chosing the one that allows you to check all the registered users.

Automated way using mod_xmlrpc or ejabberd_ctl patch

If you want an automated way to check this using XML-RPC calls, you can install mod_xmlrpc in ejabberd. It provides calls for that.

If you want an automated way to check this using the system shell, you can apply this patch to ejabberd 2.0.5:

 
--- a/src/ejabberd_ctl.erl
+++ b/src/ejabberd_ctl.erl
@@ -123,6 +123,38 @@ process(["register", User, Server, Password]) ->
            ?STATUS_ERROR
     end;

+process(["is_registered", User, Server]) ->
+    case ejabberd_auth:is_user_exists(User, Server) of
+       true ->
+           ?PRINT("User ~p already registered at node ~p~n",
+                     [User ++ "@" ++ Server, node()]),
+           ?STATUS_SUCCESS;
+       false ->
+           ?PRINT("User ~p not registered at node ~p~n",
+                     [User ++ "@" ++ Server, node()]),
+           ?STATUS_ERROR;
+       {error, Reason} ->
+           ?PRINT("Can't register user ~p at node ~p: ~p~n",
+                     [User ++ "@" ++ Server, node(), Reason]),
+           ?STATUS_ERROR
+    end;
+
+process(["check_password", User, Server, Password]) ->
+    case ejabberd_auth:check_password(User, Server, Password) of
+       true ->
+           ?PRINT("Password of user ~p is good~n",
+                     [User ++ "@" ++ Server]),
+           ?STATUS_SUCCESS;
+       false ->
+           ?PRINT("Password of user ~p is bad~n",
+                     [User ++ "@" ++ Server]),
+           ?STATUS_ERROR;
+       {error, Reason} ->
+           ?PRINT("Can't register user ~p at node ~p: ~p~n",
+                     [User ++ "@" ++ Server, node(), Reason]),
+           ?STATUS_ERROR
+    end;
+
 process(["unregister", User, Server]) ->
     case ejabberd_auth:remove_user(User, Server) of
        {error, Reason} ->

And then you can get that information with:

 
$ sudo ejabberdctl is_registered badlop localhost
User "badlop@localhost" already registered at node ejabberd@localhost

$ echo $?
0

$ sudo ejabberdctl is_registered badlop2 localhost
User "badlop2@localhost" not registered at node ejabberd@localhost

$ echo $?
1

$ sudo ejabberdctl check_password badlop localhost paspass
Password of user "badlop@localhost" is good

$ sudo ejabberdctl check_password badlop localhost gugubadpass
Password of user "badlop@localhost" is bad

In ejabberd 2.1.0 and higher those modules will be replaced with ejabberd_xmlrpc, mod_admin_extra. Also mod_rest can be used to support HTTP POST calls.

Syndicate content