25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Return 409 conflict error code on register if user already exists

This commit is contained in:
Mickael Remond 2016-07-30 11:50:04 +02:00
parent 42e6f72ee9
commit fb2603d3cd
No known key found for this signature in database
GPG Key ID: E6F6045D79965AA3
2 changed files with 19 additions and 17 deletions

View File

@ -382,7 +382,7 @@ register(User, Host, Password) ->
{atomic, exists} -> {atomic, exists} ->
String = io_lib:format("User ~s@~s already registered at node ~p", String = io_lib:format("User ~s@~s already registered at node ~p",
[User, Host, node()]), [User, Host, node()]),
{exists, String}; {conflict, String};
{error, Reason} -> {error, Reason} ->
String = io_lib:format("Can't register user ~s@~s at node ~p: ~p", String = io_lib:format("Can't register user ~s@~s at node ~p: ~p",
[User, Host, node(), Reason]), [User, Host, node(), Reason]),

View File

@ -444,22 +444,24 @@ ejabberd_command(Auth, Cmd, Args, Version, IP) ->
format_command_result(Cmd, Auth, Result, Version) -> format_command_result(Cmd, Auth, Result, Version) ->
{_, ResultFormat} = ejabberd_commands:get_command_format(Cmd, Auth, Version), {_, ResultFormat} = ejabberd_commands:get_command_format(Cmd, Auth, Version),
case {ResultFormat, Result} of case {ResultFormat, Result} of
{{_, rescode}, V} when V == true; V == ok -> {{_, rescode}, V} when V == true; V == ok ->
{200, 0}; {200, 0};
{{_, rescode}, _} -> {{_, rescode}, _} ->
{200, 1}; {200, 1};
{{_, restuple}, {V1, Text1}} when V1 == true; V1 == ok -> {{_, restuple}, {V, Text}} when V == true; V == ok ->
{200, iolist_to_binary(Text1)}; {200, iolist_to_binary(Text)};
{{_, restuple}, {_, Text2}} -> {{_, restuple}, {V, Text}} when V == conflict ->
{500, iolist_to_binary(Text2)}; {409, iolist_to_binary(Text)};
{{_, {list, _}}, _V} -> {{_, restuple}, {_, Text2}} ->
{_, L} = format_result(Result, ResultFormat), {500, iolist_to_binary(Text2)};
{200, L}; {{_, {list, _}}, _V} ->
{{_, {tuple, _}}, _V} -> {_, L} = format_result(Result, ResultFormat),
{_, T} = format_result(Result, ResultFormat), {200, L};
{200, T}; {{_, {tuple, _}}, _V} ->
_ -> {_, T} = format_result(Result, ResultFormat),
{200, {[format_result(Result, ResultFormat)]}} {200, T};
_ ->
{200, {[format_result(Result, ResultFormat)]}}
end. end.
format_result(Atom, {Name, atom}) -> format_result(Atom, {Name, atom}) ->