/**
     * Provision storage
     * @param {string} file
     */
    constructor (file)
    {
        let dir = path.dirname(file);

        if (!Utils.isValidPath(dir) || !Utils.hasAccess(dir, 'frw')) {
            throw new Error('Invalid file or insufficient permissions');
        }

        if (path.basename(file).length === 0) {
            file = path.resolve(dir, 'provisions.json');
        }

        this._file = file;
    }
Esempio n. 2
0
    /**
     * Create new User
     * @param {string} userId
     * @param {string} bandPublicKey
     * @param {string} keyId
     * @returns {boolean}
     */
    createNewUser (userId, bandPublicKey, keyId)
    {
        let con = new Database(this._db),
            sql = 'INSERT INTO users (keyId, userId, bandPublicKey) VALUES (:keyId, :userId, :bandPublicKey);',
            /** @property {number} info.changes */
            info = Utils.tryCatch(() => con.prepare(sql).run({keyId, userId, bandPublicKey}));

        con.close();

        return info !== undefined && info.changes === 1;
    }
Esempio n. 3
0
    /**
     * Get UserID from KeyID
     * @param {string} keyId
     * @returns {string}
     */
    getUserIDFromKeyID (keyId)
    {
        let con = new Database(this._db),
            sql = 'SELECT userId FROM users WHERE keyId = :keyId;',
            /** @property {string} userRow.userId */
            userRow = Utils.tryCatch(() => con.prepare(sql).get({keyId}));

        con.close();

        return userRow !== undefined ? userRow.userId : '';
    }
 //noinspection JSUnusedGlobalSymbols
 /**
  * Write provision data
  * @param {string} data
  * @return {void}
  */
 write (data)
 {
     fs.writeFileSync(this._file, Utils.tryCatch(() => JSON.stringify(data, null, 4), '{}'), 'utf8');
 }
 //noinspection JSUnusedGlobalSymbols
 /**
  * Read provision data
  * @return {string}
  */
 read ()
 {
     return Utils.tryCatch(() => fs.readFileSync(this._file, 'utf8'), '{}');
 }