From 11130806f9fb122f89d815774f0c0af55ce15ba8 Mon Sep 17 00:00:00 2001 From: Badlop Date: Wed, 28 Jul 2010 19:48:06 +0200 Subject: [PATCH] Return Registered element when account exists (thanks to PioneerMike) --- src/mod_register.erl | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/mod_register.erl b/src/mod_register.erl index e67a4fca0..315ccfa0c 100644 --- a/src/mod_register.erl +++ b/src/mod_register.erl @@ -180,13 +180,28 @@ process_iq(From, To, exmpp_iq:error(IQ_Rec, 'bad-request') end; get -> + {UsernameSubels, QuerySubels} = + case {exmpp_jid:node_as_list(From), exmpp_jid:prep_domain_as_list(From)} of + {User, Server} when is_list(User) and is_list(Server) -> + case ejabberd_auth:is_user_exists(User,Server) of + true -> + {[#xmlcdata{cdata = list_to_binary(User)}], + [#xmlel{ns = ?NS_INBAND_REGISTER, name = 'registered'}]}; + false -> + {[#xmlcdata{cdata = list_to_binary(User)}], []} + end; + _ -> + {[], []} + end, Result = #xmlel{ns = ?NS_INBAND_REGISTER, name = 'query', children = - [#xmlel{ns = ?NS_INBAND_REGISTER, name = 'instructions', children = - [#xmlcdata{cdata = list_to_binary(translate:translate(Lang, - "Choose a username and password " - "to register with this server"))}]}, - #xmlel{ns = ?NS_INBAND_REGISTER, name = 'username'}, - #xmlel{ns = ?NS_INBAND_REGISTER, name = 'password'}]}, + [#xmlel{ns = ?NS_INBAND_REGISTER, name = 'instructions', children = + [#xmlcdata{cdata = list_to_binary( + translate:translate(Lang, + "Choose a username and password " + "to register with this server"))}]}, + #xmlel{ns = ?NS_INBAND_REGISTER, name = 'username', children = UsernameSubels}, + #xmlel{ns = ?NS_INBAND_REGISTER, name = 'password'} + | QuerySubels]}, exmpp_iq:result(IQ_Rec, Result) end.