在CouchDB 1.0中创建用户时出错 [英] Error creating user in CouchDB 1.0

查看:72
本文介绍了在CouchDB 1.0中创建用户时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统是ubuntu 10.04,并且我安装了CouchDB 1.0。我可以创建一个或多个管理员,以admin身份登录,一切正常。

My system is ubuntu 10.04 and I have CouchDB 1.0 installed. I can create admin, or more admins, log in as admin and everything works fine.

CouchDB中的版本为0.11,因此用户不是管理员,可以拥有对数据库的精细权限。我想创建这样的用户。我打开Futon,但尚未登录,然后单击注册链接(右下角)。然后是关于用户名和密码的问题。当我填写表单并提交表单时,用户名字段下有很长的错误消息:

Since 0.11 in CouchDB there is notion of users which are not admins, and can have fine grained rights to databases. I want to create such user. I open Futon, I am not logged in, and I click "Signup" link (lower right corner). Then there is question about username and password. When I fill in the form and submit it, there is very long error message under "Username" field:

注册错误:{gen_server,call,[couch_query_servers,{get_proc ,{doc,< __ design / _auth >>,{1,[< 84,165,145,147,156,145,146,42,53,239,238,7,235,44,58,114 >>]},{[{{<语言 >>,<< javascript >>},{< validate_doc_update >>,<< \n函数(newDoc,oldDoc,userCtx){\n if(( oldDoc&& oldDoc.type!=='用户')|| newDoc.type!=='用户'){\n throw({禁止:'doc.type必须是用户'});)n } // //现在仅允许用户文档\n\n if(newDoc._deleted === true){\n //允许管理员删除并匹配用户\n //不检查其他字段\ ifn if(((userCtx.roles.indexOf('_ admin')!== -1)|| \n(userCtx.name == oldDoc.name)){\n return; \n} else {\ thrown throw({forbidden:'只有管理员可以删除其他用户文档。'}); \n} \n} \n\n if(!newDoc.name){\n throw({forbidden: 'doc.name是必填项'}); \n} \n\n if(!(newDoc.role && (typeof newDoc.roles.length!=='undefined'))){\n throw({禁止:'doc.roles必须是一个数组'}); \n} \n\n if(newDoc ._id!==('org.couchdb.user:'+ newDoc.name)){\n throw({\n禁止:'Doc ID的格式必须为org.couchdb.user:name'\ n}); \n} \n\n if(oldDoc){//验证所有更新\n if(oldDoc.name!== newDoc.name){\n throw({forbidden:'Usernames不能更改。'});如果(newDoc.password_sha&!newDoc.salt){\n throw({\n forbidden:'拥有password_sha的用户必须注意一下。'+ \n'有关示例代码,请参见/_utils/script/couch.js。'\n}); \n \n\n if(userCtx.roles。 indexOf('_ admin')=== -1){\n if(oldDoc){//验证非管理员更新\n if(userCtx.name!== newDoc.name){\n throw({ \n禁止:您只能更新自己的用户文档。 \n}); \n} \n //验证角色更新\n var oldRoles = oldDoc.roles.sort(); \ n var newRoles = newDoc.roles.sort(); \n\n if(oldRoles.length!== newRoles.length){\n throw({forbidden:'Only _admin可以编辑角色’}); \n} \n\n(var i = 0;我< oldRoles.length; i ++){\n if(oldRoles [i]!== newRoles [i]){\n throw({forbidden:'只有_admin可以编辑角色'}); \n} \n} \n } else if(newDoc.roles.length> 0){\n throw({forbidden:'只有 admin可以设置角色'}); \n} \n} \n\n //对于(var i = 0; i< newDoc.roles.length; i ++),用户db\n中没有系统角色{{n if(newDoc.roles [i] [0] ===' '){\n throw({\n forbidden:\n'用户数据库中没有系统角色(以下划线开头)。'\n}); \n} \n} \n\ n //没有系统名称作为名称\n if(newDoc.name [0] ==='_'){\n throw({forbidden:'用户名不能以下划线开头。'}); \n } \n} \n >>}]},[],false,[]},{< _ design / _auth >>,<< 1-54a591939c91922a35efee07eb2c3a72 >>}} ]}

Signup error: {gen_server,call, [couch_query_servers, {get_proc,{doc,<<"_design/_auth">>, {1, [<<84,165,145,147,156,145,146,42,53,239,238,7, 235,44,58,114>>]}, {[{<<"language">>,<<"javascript">>}, {<<"validate_doc_update">>, <<"\n function(newDoc, oldDoc, userCtx) {\n if ((oldDoc && oldDoc.type !== 'user') || newDoc.type !== 'user') {\n throw({forbidden : 'doc.type must be user'});\n } // we only allow user docs for now\n\n if (newDoc._deleted === true) {\n // allow deletes by admins and matching users\n // without checking the other fields\n if ((userCtx.roles.indexOf('_admin') !== -1) ||\n (userCtx.name == oldDoc.name)) {\n return;\n } else {\n throw({forbidden: 'Only admins may delete other user docs.'});\n }\n }\n\n if (!newDoc.name) {\n throw({forbidden: 'doc.name is required'});\n }\n\n if (!(newDoc.roles && (typeof newDoc.roles.length !== 'undefined'))) {\n throw({forbidden: 'doc.roles must be an array'});\n }\n\n if (newDoc._id !== ('org.couchdb.user:' + newDoc.name)) {\n throw({\n forbidden: 'Doc ID must be of the form org.couchdb.user:name'\n });\n }\n\n if (oldDoc) { // validate all updates\n if (oldDoc.name !== newDoc.name) {\n throw({forbidden: 'Usernames can not be changed.'});\n }\n }\n\n if (newDoc.password_sha && !newDoc.salt) {\n throw({\n forbidden: 'Users with password_sha must have a salt.' +\n 'See /_utils/script/couch.js for example code.'\n });\n }\n\n if (userCtx.roles.indexOf('_admin') === -1) {\n if (oldDoc) { // validate non-admin updates\n if (userCtx.name !== newDoc.name) {\n throw({\n forbidden: 'You may only update your own user document.'\n });\n }\n // validate role updates\n var oldRoles = oldDoc.roles.sort();\n var newRoles = newDoc.roles.sort();\n\n if (oldRoles.length !== newRoles.length) {\n throw({forbidden: 'Only _admin may edit roles'});\n }\n\n for (var i = 0; i < oldRoles.length; i++) {\n if (oldRoles[i] !== newRoles[i]) {\n throw({forbidden: 'Only _admin may edit roles'});\n }\n }\n } else if (newDoc.roles.length > 0) {\n throw({forbidden: 'Only admin may set roles'});\n }\n }\n\n // no system roles in users db\n for (var i = 0; i < newDoc.roles.length; i++) {\n if (newDoc.roles[i][0] === '') {\n throw({\n forbidden:\n 'No system roles (starting with underscore) in users db.'\n });\n }\n }\n\n // no system names as names\n if (newDoc.name[0] === '_') {\n throw({forbidden: 'Username may not start with underscore.'});\n }\n }\n">>}]}, [],false,[]}, {<<"_design/_auth">>, <<"1-54a591939c91922a35efee07eb2c3a72">>}}]}

这是什么?如何在CouchDB中创建用户?

What is it? How can I create users in CouchDB?

推荐答案

要创建用户,请将JSON文档放入 http:// localhost:5984 / _users / org.couchdb.user:< username>

To create a user, PUT a JSON document to http://localhost:5984/_users/org.couchdb.user:<username>

例如,创建一个文件 login.json ,如下所示:

For example create a file login.json like this:

{
    "_id": "org.couchdb.user:test",
    "name": "test",
    "password_sha": "24e8e07c23d8ae85108468ec4814b2f0fa84edde",
    "salt": "78f67e252351a56d6e1e6df9ba005239",
    "roles": [],
    "type": "user"
}

然后将数据放入beddb中:

Then PUT the data into couchdb:

curl -X PUT http://<admin>:<password>@localhost:5984/_users/org.couchdb.user%3Atest -S -s -H "Content-Type: application/json" -d @login.json

(替换< admin> < password> 以及您的ouchdb凭据。)

(Replace <admin> and <password> with your couchdb credentials.)

现在,您应该可以使用用户 test和密码 test123登录到benchdb。

Now you should be able to log into couchdb with the user "test" and the password "test123".

这篇关于在CouchDB 1.0中创建用户时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆