How to use the actionhero.api.users function in actionhero

To help you get started, we’ve selected a few actionhero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github actionhero / actionhero-tutorial / tasks / stats.js View on Github external
async run () {
    const users = await api.users.list()
    const posts = await api.users.postsList()
    api.log('*** STATUS ***', 'info', { users: users.length, posts: posts.length })
  }
}
github actionhero / actionhero-tutorial / initializers / users.js View on Github external
async initialize () {
    const redis = api.redis.clients.client

    api.users = {}

    api.users.add = async (userName, password) => {
      const savedUser = await redis.hget(this.usersHash, userName)
      if (savedUser) { throw new Error('userName already exists') }
      const hashedPassword = await api.users.cryptPassword(password)
      const data = {
        userName: userName,
        hashedPassword: hashedPassword,
        createdAt: new Date().getTime()
      }

      await redis.hset(this.usersHash, userName, JSON.stringify(data))
    }

    api.users.list = async () => {
      const userData = await redis.hgetall(this.usersHash)
      return Object.keys(userData).map((k) => {
        const data = JSON.parse(userData[k])
github actionhero / actionhero-tutorial / tasks / stats.js View on Github external
async run () {
    const users = await api.users.list()
    const posts = await api.users.postsList()
    api.log('*** STATUS ***', 'info', { users: users.length, posts: posts.length })
  }
}
github actionhero / actionhero-tutorial / actions / users.js View on Github external
async run ({ response, params }) {
    response.authenticated = await api.users.authenticate(params.userName, params.password)
    if (!response.authenticated) { throw new Error('unable to log in') }
  }
}
github actionhero / actionhero-tutorial / actions / users.js View on Github external
async run ({ response, params }) {
    const users = await api.users.list()
    response.users = users.map((user) => { return user.userName })
  }
}
github actionhero / actionhero-tutorial / initializers / users.js View on Github external
}
    }

    api.users.delete = async (userName, password) => {
      await redis.del(this.usersHash, userName)
      const titles = await api.blog.postsList(userName)
      for (const i in titles) {
        await api.blog.deletePost(userName, titles[i])
      }
    }

    api.users.cryptPassword = async (password) => {
      return bcrypt.hash(password, this.saltRounds)
    }

    api.users.comparePassword = async (hashedPassword, userPassword) => {
      return bcrypt.compare(userPassword, hashedPassword)
    }
  }
github actionhero / actionhero-tutorial / actions / users.js View on Github external
async run ({ params }) {
    await api.users.delete(params.userName, params.password)
  }
}
github actionhero / actionhero-tutorial / initializers / users.js View on Github external
createdAt: new Date().getTime()
      }

      await redis.hset(this.usersHash, userName, JSON.stringify(data))
    }

    api.users.list = async () => {
      const userData = await redis.hgetall(this.usersHash)
      return Object.keys(userData).map((k) => {
        const data = JSON.parse(userData[k])
        delete data.hashedPassword
        return data
      })
    }

    api.users.authenticate = async (userName, password) => {
      try {
        let data = await redis.hget(this.usersHash, userName)
        data = JSON.parse(data)
        return api.users.comparePassword(data.hashedPassword, password)
      } catch (error) {
        throw new Error(`userName does not exist (${error})`)
      }
    }

    api.users.delete = async (userName, password) => {
      await redis.del(this.usersHash, userName)
      const titles = await api.blog.postsList(userName)
      for (const i in titles) {
        await api.blog.deletePost(userName, titles[i])
      }
    }
github actionhero / actionhero-tutorial / initializers / users.js View on Github external
data = JSON.parse(data)
        return api.users.comparePassword(data.hashedPassword, password)
      } catch (error) {
        throw new Error(`userName does not exist (${error})`)
      }
    }

    api.users.delete = async (userName, password) => {
      await redis.del(this.usersHash, userName)
      const titles = await api.blog.postsList(userName)
      for (const i in titles) {
        await api.blog.deletePost(userName, titles[i])
      }
    }

    api.users.cryptPassword = async (password) => {
      return bcrypt.hash(password, this.saltRounds)
    }

    api.users.comparePassword = async (hashedPassword, userPassword) => {
      return bcrypt.compare(userPassword, hashedPassword)
    }
  }
github actionhero / actionhero-tutorial / initializers / users.js View on Github external
api.users = {}

    api.users.add = async (userName, password) => {
      const savedUser = await redis.hget(this.usersHash, userName)
      if (savedUser) { throw new Error('userName already exists') }
      const hashedPassword = await api.users.cryptPassword(password)
      const data = {
        userName: userName,
        hashedPassword: hashedPassword,
        createdAt: new Date().getTime()
      }

      await redis.hset(this.usersHash, userName, JSON.stringify(data))
    }

    api.users.list = async () => {
      const userData = await redis.hgetall(this.usersHash)
      return Object.keys(userData).map((k) => {
        const data = JSON.parse(userData[k])
        delete data.hashedPassword
        return data
      })
    }

    api.users.authenticate = async (userName, password) => {
      try {
        let data = await redis.hget(this.usersHash, userName)
        data = JSON.parse(data)
        return api.users.comparePassword(data.hashedPassword, password)
      } catch (error) {
        throw new Error(`userName does not exist (${error})`)
      }