{"id":44003994,"url":"https://github.com/yisbug/restify-user","last_synced_at":"2026-02-07T13:07:27.392Z","repository":{"id":28581096,"uuid":"32099039","full_name":"yisbug/restify-user","owner":"yisbug","description":"一个通用的基于restify和mongoose的用户模块，支持登录登出加密等基础功能，可自由扩展。","archived":false,"fork":false,"pushed_at":"2017-01-14T02:39:33.000Z","size":67,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-02T10:41:37.997Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yisbug.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-12T19:56:39.000Z","updated_at":"2017-01-14T02:39:00.000Z","dependencies_parsed_at":"2022-09-03T16:12:43.294Z","dependency_job_id":null,"html_url":"https://github.com/yisbug/restify-user","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/yisbug/restify-user","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisbug%2Frestify-user","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisbug%2Frestify-user/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisbug%2Frestify-user/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisbug%2Frestify-user/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yisbug","download_url":"https://codeload.github.com/yisbug/restify-user/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yisbug%2Frestify-user/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29194626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T12:38:28.597Z","status":"ssl_error","status_checked_at":"2026-02-07T12:38:23.888Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-02-07T13:07:26.848Z","updated_at":"2026-02-07T13:07:27.384Z","avatar_url":"https://github.com/yisbug.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# restify-user\n\n一个通用的用户模块，基于`restify`,`mongoose`。\n\n每次新建项目都要加用户模块，干脆把这一部分剥离出来，以后用起来方便。\n\n### 等待添加的功能\n\n* 用户名密码约束长度。\n* 限制`del`,`put`接口的权限，以适应普通用户的场景。\n\n### 安装\n    npm install restify-user\n\n### 使用\n\n示例：\n```coffeescript\nrestify = require 'restify'\nmongoose = require 'mongoose'\nuserCenter = require 'restify-user'\n\nserver = restify.createServer {}\nserver.use restify.authorizationParser()\nserver.use restify.bodyParser mapParams:false\nserver.use restify.queryParser()\n\ndb = mongoose.createConnection 'mongodb://localhost/test'\ndb.once 'open',-\u003e\n    userCenter server,db,options\n    sever.listen 8080,-\u003e\n        console.log '%s listening at %s',server.name,server.url\n```\n\n`userCenter`接收3个参数，分别为：\n\n* `server`： 即`restify`创建的`server`实例。\n* `db`：`mongoose`数据库连接对象\n* `options`：其他参数,`object`类型\n\n\u003e 注：`server`需要使用`bodyParser`等中间件\n\n\n`options`参数支持字段：\n\n* `endpoint` 路由地址，默认为`/user`\n* `fields` 用户表其他扩展字段，使用`mongoose`中`Schema`所支持的格式。\n* `model` 用户`collection`名称，默认为`admin`\n\n目前还没实现的参数：\n\n* `usernameMinLen` 用户名最小长度，默认为1\n* `usernameMaxLen` 用户名最大长度，默认不做限制\n* `passwordMinLen` 密码最小长度，默认为1\n* `passwordMaxLen` 密码最大长度，默认不做限制\n\n\n之后会自动创建`/user`路由，支持`restify`的`post/get/del/put`等请求。其中`/user`可在`options`的`entpoint`属性中重新定义。\n\n### 路由\n\n#### `POST /user` 创建用户\n\n参数：\n\n* `username` 登陆用户名\n* `nickname` 昵称\n* `password` 密码\n* 其他自定义字段，由`options`中`fields`字段配置。\n\n返回：\n\n* `200` 创建成功，返回创建的用户数据。\n* 其他失败\n\n#### `GET /user` 获取用户列表\n\n参数使用queryString\n\n* `limit` 每页条数，默认不分页\n* `page` 页码\n\n返回`object`对象，属性：\n\n* `count` 用户总数\n* `list` 用户列表\n* `page` 当前页码\n\n#### `PUT /user/:userid` 修改用户基本信息\n\n#### `DEL /user/:userid` 删除用户\n\n#### `GET /user/:userid` 获取用户详细信息\n\n参数使用queryString\n\n* `type` 查询方式，支持`username`,`userid`，默认为`userid`。\n\n#### `GET /user/my` 获取当前已登陆账户信息\n\n\n#### `POST /user/login` 用户登陆\n\n参数：\n\n* `username`\n* `password`\n* `grant_type`  password\n\n需要设置base token\n\n如果成功则返回`200`,和`access_token`，其他状态为登陆失败。\n\n* `access_token` object，包括：`token`,`username`,`userid`,`nickname`字段\n* `token_type`\n\n\n### 测试\n\n\u003e 所有测试均使用`coffeescript`编写。\n\n#### 运行单个测试\n\n    grunt test:[filename]\n\n\u003e 运行单个测试可以不加`test/`路径前缀和`.coffee`后缀。\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyisbug%2Frestify-user","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyisbug%2Frestify-user","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyisbug%2Frestify-user/lists"}