diff options
| author | kanadeko <[email protected]> | 2017-01-16 04:45:29 -0300 |
|---|---|---|
| committer | kanadeko <[email protected]> | 2017-01-16 04:45:29 -0300 |
| commit | 570f6c3ce3669571b05eeb6c8ebb2ca21d641a3c (patch) | |
| tree | 40198cf3a89191a8b29b270b1f6725842584295a /database | |
| parent | Added generation of random token (diff) | |
| download | host.fuwn.me-570f6c3ce3669571b05eeb6c8ebb2ca21d641a3c.tar.xz host.fuwn.me-570f6c3ce3669571b05eeb6c8ebb2ca21d641a3c.zip | |
Print and save tokens
Diffstat (limited to 'database')
| -rw-r--r-- | database/db.js | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/database/db.js b/database/db.js index 94f48c6..2dc2005 100644 --- a/database/db.js +++ b/database/db.js @@ -27,35 +27,38 @@ let init = function(db, config){ // == Generate a 1 time token == // db.table('tokens').then((tokens) => { - if(tokens.length === 0){ - - // This is the first launch of the app - let clientToken = require('randomstring').generate() - let adminToken = require('randomstring').generate() - - db.table('tokens').insert( - [ - { - name: 'client', - value: clientToken - }, - { - name: 'admin', - value: adminToken - } - ] - ).then(() => { - console.log('Your client token is: ' + clientToken) - console.log('Your admin token is: ' + adminToken) - config.clientToken = clientToken - config.adminToken = adminToken - }) - - } + if(tokens.length !== 0) return printAndSave(config, tokens[0].value, tokens[1].value) + + // This is the first launch of the app + let clientToken = require('randomstring').generate() + let adminToken = require('randomstring').generate() + + db.table('tokens').insert( + [ + { + name: 'client', + value: clientToken + }, + { + name: 'admin', + value: adminToken + } + ] + ).then(() => { + printAndSave(config, clientToken, adminToken) + }) + }) }) } +function printAndSave(config, clientToken, adminToken){ + console.log('Your client token is: ' + clientToken) + console.log('Your admin token is: ' + adminToken) + config.clientToken = clientToken + config.adminToken = adminToken +} + module.exports = init
\ No newline at end of file |