diff options
author | John Christopher Anderson <jchris@apache.org> | 2010-01-07 20:02:46 +0000 |
---|---|---|
committer | John Christopher Anderson <jchris@apache.org> | 2010-01-07 20:02:46 +0000 |
commit | cd0e9c9b6384e4c9200d10088a13164ce4229ea6 (patch) | |
tree | 0ac40098a49b2dd62b0099f742323a7811399489 /share/www/script/couch.js | |
parent | dd15c8ed5bf5873aec08a99a0687849f1d29f4c3 (diff) |
merge account branch to trunk
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@896989 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script/couch.js')
-rw-r--r-- | share/www/script/couch.js | 62 |
1 files changed, 18 insertions, 44 deletions
diff --git a/share/www/script/couch.js b/share/www/script/couch.js index 19b98edb..21ea39b3 100644 --- a/share/www/script/couch.js +++ b/share/www/script/couch.js @@ -340,60 +340,34 @@ CouchDB.logout = function() { return JSON.parse(CouchDB.last_req.responseText); } -CouchDB.createUser = function(username, password, email, roles, basicAuth) { - var roles_str = "" - if (roles) { - for (var i=0; i< roles.length; i++) { - roles_str += "&roles=" + encodeURIComponent(roles[i]); - } - } - var headers = {"Content-Type": "application/x-www-form-urlencoded"}; - if (basicAuth) { - headers['Authorization'] = basicAuth - } else { - headers['X-CouchDB-WWW-Authenticate'] = 'Cookie'; - } - - CouchDB.last_req = CouchDB.request("POST", "/_user/", { - headers: headers, - body: "username=" + encodeURIComponent(username) + "&password=" - + encodeURIComponent(password) + "&email=" - + encodeURIComponent(email) + roles_str - }); +CouchDB.session = function(options) { + options = options || {}; + CouchDB.last_req = CouchDB.request("GET", "/_session", options); + CouchDB.maybeThrowError(CouchDB.last_req); return JSON.parse(CouchDB.last_req.responseText); -} - -CouchDB.updateUser = function(username, email, roles, password, old_password) { - var roles_str = "" - if (roles) { - for (var i=0; i< roles.length; i++) { - roles_str += "&roles=" + encodeURIComponent(roles[i]); - } - } +}; - var body = "email="+ encodeURIComponent(email)+ roles_str; +CouchDB.user_prefix = "org.couchdb.user:"; - if (typeof(password) != "undefined" && password) { - body += "&password=" + password; +CouchDB.prepareUserDoc = function(user_doc, new_password) { + user_doc._id = user_doc._id || CouchDB.user_prefix + user_doc.username; + if (new_password) { + // handle the password crypto + user_doc.salt = CouchDB.newUuids(1)[0]; + user_doc.password_sha = hex_sha1(new_password + user_doc.salt); } - - if (typeof(old_password) != "undefined" && old_password) { - body += "&old_password=" + old_password; + user_doc.type = "user"; + if (!user_doc.roles) { + user_doc.roles = [] } - - CouchDB.last_req = CouchDB.request("PUT", "/_user/"+encodeURIComponent(username), { - headers: {"Content-Type": "application/x-www-form-urlencoded", - "X-CouchDB-WWW-Authenticate": "Cookie"}, - body: body - }); - return JSON.parse(CouchDB.last_req.responseText); -} + return user_doc; +}; CouchDB.allDbs = function() { CouchDB.last_req = CouchDB.request("GET", "/_all_dbs"); CouchDB.maybeThrowError(CouchDB.last_req); return JSON.parse(CouchDB.last_req.responseText); -} +}; CouchDB.allDesignDocs = function() { var ddocs = {}, dbs = CouchDB.allDbs(); |