couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r982200 - in /couchdb/trunk: THANKS share/www/script/test/cookie_auth.js src/couchdb/couch_httpd_auth.erl
Date Wed, 04 Aug 2010 10:36:35 GMT
Author: fdmanana
Date: Wed Aug  4 10:36:35 2010
New Revision: 982200

URL: http://svn.apache.org/viewvc?rev=982200&view=rev
Log:
Allow POSTing of a JSON object to /_session/ for login.
Closes COUCHDB-842, patch by Jonathan D. Knezek.


Modified:
    couchdb/trunk/THANKS
    couchdb/trunk/share/www/script/test/cookie_auth.js
    couchdb/trunk/src/couchdb/couch_httpd_auth.erl

Modified: couchdb/trunk/THANKS
URL: http://svn.apache.org/viewvc/couchdb/trunk/THANKS?rev=982200&r1=982199&r2=982200&view=diff
==============================================================================
--- couchdb/trunk/THANKS (original)
+++ couchdb/trunk/THANKS Wed Aug  4 10:36:35 2010
@@ -64,5 +64,6 @@ suggesting improvements or submitting ch
  * Caleb Land <caleb.land@gmail.com>
  * Juhani Ränkimies <juhani@juranki.com>
  * Kev Jackson <foamdino@gmail.com>
+ * Jonathan D. Knezek <jdknezek@gmail.com>
 
 For a list of authors see the `AUTHORS` file.

Modified: couchdb/trunk/share/www/script/test/cookie_auth.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/cookie_auth.js?rev=982200&r1=982199&r2=982200&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/cookie_auth.js (original)
+++ couchdb/trunk/share/www/script/test/cookie_auth.js Wed Aug  4 10:36:35 2010
@@ -104,6 +104,18 @@ couchTests.cookie_auth = function(debug)
       T(CouchDB.login('Jason Davies', password).ok);
       T(CouchDB.session().userCtx.name == 'Jason Davies');
       
+      // JSON login works
+      xhr = CouchDB.request("POST", "/_session", {
+        headers: {"Content-Type": "application/json"},
+        body: JSON.stringify({
+          name: 'Jason Davies',
+          password: password
+        })
+      });
+
+      T(JSON.parse(xhr.responseText).ok);
+      T(CouchDB.session().userCtx.name == 'Jason Davies');
+
       // update one's own credentials document
       jasonUserDoc.foo=2;
       T(usersDb.save(jasonUserDoc).ok);

Modified: couchdb/trunk/src/couchdb/couch_httpd_auth.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_auth.erl?rev=982200&r1=982199&r2=982200&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_auth.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_auth.erl Wed Aug  4 10:36:35 2010
@@ -247,13 +247,17 @@ ensure_cookie_auth_secret() ->
 
 % session handlers
 % Login handler with user db
-% TODO this should also allow a JSON POST
 handle_session_req(#httpd{method='POST', mochi_req=MochiReq}=Req) ->
     ReqBody = MochiReq:recv_body(),
     Form = case MochiReq:get_primary_header_value("content-type") of
         % content type should be json
         "application/x-www-form-urlencoded" ++ _ ->
             mochiweb_util:parse_qs(ReqBody);
+        "application/json" ++ _ ->
+            {Pairs} = ?JSON_DECODE(ReqBody),
+            lists:map(fun({Key, Value}) ->
+              {?b2l(Key), ?b2l(Value)}
+            end, Pairs);
         _ ->
             []
     end,



Mime
View raw message