npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

restify-user

v1.0.7

Published

一个通用的用户模块

Downloads

4

Readme

restify-user

一个通用的用户模块,基于restify,mongoose

每次新建项目都要加用户模块,干脆把这一部分剥离出来,以后用起来方便。

等待添加的功能

  • 用户名密码约束长度。
  • 限制del,put接口的权限,以适应普通用户的场景。

安装

npm install restify-user

使用

示例:

restify = require 'restify'
mongoose = require 'mongoose'
userCenter = require 'restify-user'

server = restify.createServer {}
server.use restify.authorizationParser()
server.use restify.bodyParser mapParams:false
server.use restify.queryParser()

db = mongoose.createConnection 'mongodb://localhost/test'
db.once 'open',->
    userCenter server,db,options
    sever.listen 8080,->
        console.log '%s listening at %s',server.name,server.url

userCenter接收3个参数,分别为:

  • server: 即restify创建的server实例。
  • dbmongoose数据库连接对象
  • options:其他参数,object类型

注:server需要使用bodyParser等中间件

options参数支持字段:

  • endpoint 路由地址,默认为/user
  • fields 用户表其他扩展字段,使用mongooseSchema所支持的格式。
  • model 用户collection名称,默认为admin

目前还没实现的参数:

  • usernameMinLen 用户名最小长度,默认为1
  • usernameMaxLen 用户名最大长度,默认不做限制
  • passwordMinLen 密码最小长度,默认为1
  • passwordMaxLen 密码最大长度,默认不做限制

之后会自动创建/user路由,支持restifypost/get/del/put等请求。其中/user可在optionsentpoint属性中重新定义。

路由

POST /user 创建用户

参数:

  • username 登陆用户名
  • nickname 昵称
  • password 密码
  • 其他自定义字段,由optionsfields字段配置。

返回:

  • 200 创建成功,返回创建的用户数据。
  • 其他失败

GET /user 获取用户列表

参数使用queryString

  • limit 每页条数,默认不分页
  • page 页码

返回object对象,属性:

  • count 用户总数
  • list 用户列表
  • page 当前页码

PUT /user/:userid 修改用户基本信息

DEL /user/:userid 删除用户

GET /user/:userid 获取用户详细信息

参数使用queryString

  • type 查询方式,支持username,userid,默认为userid

GET /user/my 获取当前已登陆账户信息

POST /user/login 用户登陆

参数:

  • username
  • password
  • grant_type password

需要设置base token

如果成功则返回200,和access_token,其他状态为登陆失败。

  • access_token object,包括:token,username,userid,nickname字段
  • token_type

测试

所有测试均使用coffeescript编写。

运行单个测试

grunt test:[filename]

运行单个测试可以不加test/路径前缀和.coffee后缀。