couchdb-auth-provider


Vocabulary
furnace.auth.providers.couchdb

Class description
Implements the furnace authentication protocol for CouchDB.
base-urlThe base URL for the CouchDB database, e.g. http://foo.org:5984/mydatabase
username-viewA URL for a view which emits usernames as keys and user documents as values, i.e. something like emit(doc.username, doc). The URL should be relative to base-url (e.g. "_design/my_views/_view/by_username"). The view is not defined automatically by the library.
prefixIn order to ensure the uniqueness of user IDs and email addresses, the library creates documents in the database with ids corresponding to these values. These ids are prefixed by the string given as the value for this slot. Ideally, you should guarantee that no other documents in the database can have ids with this prefix. However, the worst that can happen is for someone to falsely be told that a username is taken when it is in fact free.
field-mapAn assoc taking user slot names to CouchDB document field names. It is not usually necessary to set this slot - it is useful only if you do not wish to use the default field names.


Definition
USING: assocs strings ;

IN: furnace.auth.providers.couchdb

TUPLE: couchdb-auth-provider
base-url
{ username-view string initial: "" }
{ prefix string initial: "user_reservation_" }
{ field-map assoc initial: { } } ;


Methods
USING: furnace.auth.providers furnace.auth.providers.couchdb
furnace.auth.providers.couchdb.private kernel namespaces ;

M: couchdb-auth-provider get-user
couchdb-auth-provider
[ (get-user) [ user-hash>user ] [ f ] if* ] with-variable ;


USING: accessors furnace.auth.providers
furnace.auth.providers.couchdb
furnace.auth.providers.couchdb.private kernel namespaces ;

M: couchdb-auth-provider new-user
couchdb-auth-provider [
dup (new-user)
[ username>> couchdb-auth-provider get get-user ]
[ drop f ] if
] with-variable ;


USING: accessors assocs couchdb furnace.auth.providers
furnace.auth.providers.couchdb
furnace.auth.providers.couchdb.private json.writer kernel
namespaces ;

M: couchdb-auth-provider update-user
couchdb-auth-provider [
[ username>> (get-user)/throw-on-no-user dup ]
[ drop "_id" of get-url ] [
user>user-hash swapd 2dup check-update drop
unify-users >json swap couch-put drop
] tri
] with-variable ;