node.js - Node: How to change keys stored in LevelDB for accounts using the Accountdown module -


i'm using accountdown, accountdown-basic plugin (https://www.npmjs.com/package/accountdown), , each account stored using leveldb (https://www.npmjs.com/package/level) key-value store. right now, key each account username:

    { key: 'user1',       value:        { admin: true,          email: 'user1@gmail.com',          username: 'user1',          color: 'rgb(155, 26, 2)' } }     { key: 'test',       value:        { admin: true,          color: 'rgb(58, 48, 48)',          email: 'test@test.com',          username: 'test' } }     { key: 'test2',       value:        { admin: false,          color: 'rgb(75, 77, 154)',          email: 'test2@test.com',          username: 'test2' } } 

but want use uuid's instead of username:

   { key: '03b49d10-ee20-11e4-b966-bfcbf13ae8c2',      value:       { admin: true,         email: 'user1@gmail.com',         username: 'user1',         color: 'rgb(155, 26, 2)' } }    { key: '0485a8b0-ee20-11e4-b966-bfcbf13ae8c2',      value:       { admin: true,         color: 'rgb(58, 48, 48)',         email: 'test@test.com',         username: 'test' } }    { key: '04eea3b0-ee20-11e4-b966-bfcbf13ae8c2',      value:       { admin: false,         color: 'rgb(75, 77, 154)',         email: 'test2@test.com',         username: 'test2' } } 

how can change these keys on existing accounts (ie perform migration)? i'm stuck in attempt delete each account , re-create accounts using uuid key, because must provide raw password string account-basic plugin. seems have access each account's salted password's hash. suggestions? i'm happy provide more clarification.

here attempt @ writing script checks whether each account starts uuid, , if so, creates new account using uuid key , deletes existing account:

var level = require('level'); var uuid = require('uuid').v1; var each = require('each-async'); var accountdown = require('accountdown'); var sublevel = require('subleveldown'); var accounthandler = require('../handlers/accounts');  var db = level(__dirname + '/../data/db', { valueencoding: 'json' }); var sheets = require('../models/sheets')(db);  var accountdownaccounts = accountdown(sublevel(db, 'accounts'), {   login: { basic: require('accountdown-basic') } });  var accountstream = accountdownaccounts.list();  var accountlist = []; // convert our stream of accounts list: accountstream   .on('data', function (data) {     accountlist.push(data);   })   .on('error', function (err) {     return console.log(err);   })   .on('end', function () {     var uuidregex = /^([a-fa-f0-9]{8}-[a-fa-f0-9]{4}-[a-fa-f0-9]{4}-[a-fa-f0-9]{4}-[a-fa-f0-9]{12})$/;     // iterate through list of accounts, deleting , re-creating accounts not have uuid key     accountlist.foreach(function (account) {       // example of account:       // { key: 'user1',       //   value:       //   { admin: true,       //     email: 'user1@gmail.com',       //     username: 'user1',       //     color: 'rgb(155, 26, 2)' }        //  }       if (!uuidregex.test(account.key) ) {         // since account key dd new account using uuid key, , remove old account         accountdownaccounts.get(account.key, function (err, accountvalue) {           if (err) return console.log("error retrieving test account:", err);            var opts = {            login: {              basic: {                username: accountvalue.username,                password: password // cannot access password create new account!!!              }            },            value: accountvalue           };            accountdownaccounts.create(uuid(), opts, function (err) {            if (err) return console.log("err while putting in new account:", err);            accountdownaccounts.remove(account.key, function (err) {              if (err) return console.log("err while deleting old account:", err);            });           });         });        } else {         console.log("account valid:", account);       }     });   }); 

i believe way alter key in key-value store leveldb delete , recreate row.

that being said, accountdown-basic has ability save accounts under arbitrary key instead of default username. (that option recent, implement 2 days ago)


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -