Git Product home page Git Product logo

accountdown's Introduction

accountdown

manage accounts with leveldb

build status

example

create

To create a user, we can just do:

var accountdown = require('accountdown');
var level = require('level');
var db = level('/tmp/users.db');

var users = accountdown(db, {
    login: { basic: require('accountdown-basic') }
});

var opts = {
    login: { basic: { username: 'substack', password: 'beep boop' } },
    value: { bio: 'beep boop' }
};
users.create('substack', opts, function (err) {
    if (err) console.error(err);
});

The string we gave to users.create() need not necessarily match the username credential. You might want to use a uid integer for example. In either case you will get implicitly encforced unique names because if a username already exists the users.create() call will fail even if the id is available and likewise if an id is unavailable but a username is available.

verify

To verify a credential:

var accountdown = require('accountdown');
var level = require('level');
var db = level('/tmp/users.db');

var users = accountdown(db, {
    login: { basic: require('accountdown-basic') }
});

var creds = { username: 'substack', password: 'beep boop' };
users.verify('basic', creds, function (err, ok) {
    if (err) console.error(err)
    else console.log('verified:', ok)
});

methods

var accountdown = require('accountdown')

var users = accountdown(db, opts)

Create a new account instance users given a leveldb database handle db and some options opts.

opts can be:

  • opts.login - map of type names to login plugin functions
  • opts.valueEncoding - value encoding to use, 'json' by default

users.create(id, opts, cb)

Create a user by an id.

users.verify()

users.list()

users.get(id, cb)

Get the data for a username

users.put(id, cb)

users.remove(id, cb)

users.register(type, plugin)

Register a login plugin at a string name type.

login plugins

Login plugins such as accountdown-basic should export a single function that will be created with db and prefix arguments and should return an object with .verify() and .create() functions:

module.exports = function (db, prefix) {
    return {
        verify: function (creds, cb) {
            // calls cb(err, success, id)
        },
        create: function (id, creds) {
            // returns an array of batch rows
        }
    };
};

plugin.verify(creds, cb)

Check whether creds are valid login credentials. cb(err, success, id) fires with any errors, the success as a boolean, and the user id.

plugin.create(id, creds)

Return an array of rows to batch insert if and only if all the keys do not already exist using level-create-batch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.