]> granicus.if.org Git - ejabberd/commitdiff
Return 409 conflict error code on register if user already exists
authorMickael Remond <mremond@process-one.net>
Sat, 30 Jul 2016 09:50:04 +0000 (11:50 +0200)
committerMickael Remond <mremond@process-one.net>
Sat, 30 Jul 2016 09:50:04 +0000 (11:50 +0200)
src/ejabberd_admin.erl
src/mod_http_api.erl

index f20aeebf00bf54d8d1297c008ea07d8e383ed0f6..f40b99ea50f58d8664687b8949145b9b248e96d5 100644 (file)
@@ -382,7 +382,7 @@ register(User, Host, Password) ->
        {atomic, exists} ->
            String = io_lib:format("User ~s@~s already registered at node ~p",
                                   [User, Host, node()]),
-           {exists, String};
+           {conflict, String};
        {error, Reason} ->
            String = io_lib:format("Can't register user ~s@~s at node ~p: ~p",
                                   [User, Host, node(), Reason]),
index ba3a14cf8c09714f91b418b25c7d03a47898d95f..f56a476665157510c1a9aa01a2e375caa39c7feb 100644 (file)
@@ -444,22 +444,24 @@ ejabberd_command(Auth, Cmd, Args, Version, IP) ->
 format_command_result(Cmd, Auth, Result, Version) ->
     {_, ResultFormat} = ejabberd_commands:get_command_format(Cmd, Auth, Version),
     case {ResultFormat, Result} of
-       {{_, rescode}, V} when V == true; V == ok ->
-           {200, 0};
-       {{_, rescode}, _} ->
-           {200, 1};
-       {{_, restuple}, {V1, Text1}} when V1 == true; V1 == ok ->
-           {200, iolist_to_binary(Text1)};
-       {{_, restuple}, {_, Text2}} ->
-           {500, iolist_to_binary(Text2)};
-       {{_, {list, _}}, _V} ->
-           {_, L} = format_result(Result, ResultFormat),
-           {200, L};
-       {{_, {tuple, _}}, _V} ->
-           {_, T} = format_result(Result, ResultFormat),
-           {200, T};
-       _ ->
-           {200, {[format_result(Result, ResultFormat)]}}
+        {{_, rescode}, V} when V == true; V == ok ->
+            {200, 0};
+        {{_, rescode}, _} ->
+            {200, 1};
+        {{_, restuple}, {V, Text}} when V == true; V == ok ->
+            {200, iolist_to_binary(Text)};
+        {{_, restuple}, {V, Text}} when V == conflict ->
+            {409, iolist_to_binary(Text)};
+        {{_, restuple}, {_, Text2}} ->
+            {500, iolist_to_binary(Text2)};
+        {{_, {list, _}}, _V} ->
+            {_, L} = format_result(Result, ResultFormat),
+            {200, L};
+        {{_, {tuple, _}}, _V} ->
+            {_, T} = format_result(Result, ResultFormat),
+            {200, T};
+        _ ->
+            {200, {[format_result(Result, ResultFormat)]}}
     end.
 
 format_result(Atom, {Name, atom}) ->