summaryrefslogtreecommitdiff
path: root/share/www/script/jquery.couch.js
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2009-08-04 19:50:46 +0000
committerDamien F. Katz <damien@apache.org>2009-08-04 19:50:46 +0000
commit8e2215ee6306b0f4c13553796d401e9f5f93bcb6 (patch)
tree948b9179887e73379bc445b9ad058de3a0bbe870 /share/www/script/jquery.couch.js
parentfd72a9bc48ebab76976f538c28459a0e26aa1750 (diff)
Initial check-in of OAuth and cookie authentication.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@800938 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script/jquery.couch.js')
-rw-r--r--share/www/script/jquery.couch.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/share/www/script/jquery.couch.js b/share/www/script/jquery.couch.js
index 73d064c4..54e32617 100644
--- a/share/www/script/jquery.couch.js
+++ b/share/www/script/jquery.couch.js
@@ -61,6 +61,41 @@
);
},
+ // TODO make login/logout and db.login/db.logout DRY
+ login: function(options) {
+ options = options || {};
+ $.ajax({
+ type: "POST", url: "/_login", dataType: "json",
+ data: {username: options.username, password: options.password},
+ complete: function(req) {
+ var resp = $.httpData(req, "json");
+ if (req.status == 200) {
+ if (options.success) options.success(resp);
+ } else if (options.error) {
+ options.error(req.status, resp.error, resp.reason);
+ } else {
+ alert("An error occurred logging in: " + resp.reason);
+ }
+ }
+ });
+ },
+ logout: function(options) {
+ options = options || {};
+ $.ajax({
+ type: "POST", url: "/_logout", dataType: "json",
+ complete: function(req) {
+ var resp = $.httpData(req, "json");
+ if (req.status == 200) {
+ if (options.success) options.success(resp);
+ } else if (options.error) {
+ options.error(req.status, resp.error, resp.reason);
+ } else {
+ alert("An error occurred logging out: " + resp.reason);
+ }
+ }
+ });
+ },
+
db: function(name) {
return {
name: name,