Repository: couchdb-couch
Updated Branches:
  refs/heads/master 2ae31331e -> 27f365696


Make _session endpoint accept username in addition to name

Before _session endpoint was only accepting "name" and "password" parameters
This, makes _session endpoint, in addition,  to accept "username" and
"password" parameters

JIRA: COUCHDB-2754
BugzId: 47059


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/078f7a8c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/078f7a8c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/078f7a8c

Branch: refs/heads/master
Commit: 078f7a8c6c895773ecc6329f72ea6a9ee2ac5f69
Parents: a150e5d
Author: Mayya Sharipova <[email protected]>
Authored: Thu Jul 23 15:04:43 2015 -0400
Committer: Mayya Sharipova <[email protected]>
Committed: Tue Aug 11 17:35:42 2015 -0400

----------------------------------------------------------------------
 src/couch_httpd_auth.erl | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/078f7a8c/src/couch_httpd_auth.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_auth.erl b/src/couch_httpd_auth.erl
index 0e78946..2372bb1 100644
--- a/src/couch_httpd_auth.erl
+++ b/src/couch_httpd_auth.erl
@@ -287,7 +287,7 @@ handle_session_req(#httpd{method='POST', 
mochi_req=MochiReq}=Req, AuthModule) ->
         _ ->
             []
     end,
-    UserName = ?l2b(couch_util:get_value("name", Form, "")),
+    UserName = ?l2b(extract_username(Form)),
     Password = ?l2b(couch_util:get_value("password", Form, "")),
     couch_log:debug("Attempt Login: ~s",[UserName]),
     {ok, UserProps, AuthCtx} = case AuthModule:get_user_creds(Req, UserName) of
@@ -366,6 +366,19 @@ handle_session_req(#httpd{method='DELETE'}=Req, 
_AuthModule) ->
 handle_session_req(Req, _AuthModule) ->
     send_method_not_allowed(Req, "GET,HEAD,POST,DELETE").
 
+extract_username(Form) ->
+    CouchFormat = couch_util:get_value("name", Form),
+    case couch_util:get_value("username", Form, CouchFormat) of
+        undefined ->
+            throw({bad_request, <<"request body must contain a username">>});
+        CouchFormat ->
+            CouchFormat;
+        Else1 when CouchFormat == undefined ->
+            Else1;
+        _Else2 ->
+            throw({bad_request, <<"request body contains different 
usernames">>})
+    end.
+
 maybe_value(_Key, undefined, _Fun) -> [];
 maybe_value(Key, Else, Fun) ->
     [{Key, Fun(Else)}].

Reply via email to