{"name":"egg-userrole","version":"2.1.0","description":"user role plugin for egg","eggPlugin":{"name":"userrole"},"keywords":["egg","plugin","userrole"],"dependencies":{"koa-roles":"^2.0.0"},"devDependencies":{"autod":"^3.0.1","egg":"^2.0.0","egg-bin":"^4.3.5","egg-ci":"^1.10.0","egg-mock":"^3.13.1","eslint":"^4.11.0","eslint-config-egg":"^5.1.1"},"engines":{"node":">=8.0.0"},"scripts":{"test":"npm run lint -- --fix && npm run test-local","test-local":"egg-bin test","cov":"egg-bin cov","lint":"eslint .","ci":"npm run lint && npm run cov","autod":"autod"},"ci":{"version":"8, 10"},"repository":{"type":"git","url":"git+https://github.com/eggjs/egg-userrole.git"},"bugs":{"url":"https://github.com/eggjs/egg/issues"},"homepage":"https://github.com/eggjs/egg-userrole#readme","author":{"name":"TZ","email":"atian25@qq.com"},"license":"MIT","gitHead":"22c3208cb45728e8ca90e1c31a3eebb7d000b7a8","_id":"egg-userrole@2.1.0","_npmVersion":"6.4.1","_nodeVersion":"10.14.1","_npmUser":{"name":"wanghx","email":"whxaxes@gmail.com"},"dist":{"integrity":"sha512-uXzy90vRyAnd3Brg0lm+KrbQlrEi4NGf0HOIKkdcSQfR9ys6MywNzfyzTjgT37UhSwRYRI954xKRsuTw0disSA==","shasum":"36bd32b6e53fc3543cfd9f4a0ded14c4f948b54f","tarball":"http://registry-npm.ywwl.com/egg-userrole/download/egg-userrole-2.1.0.tgz","fileCount":7,"unpackedSize":7242,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcE260CRA9TVsSAnZWagAAte4P/ixy3uKUGzGwjhY1gEqe\nNFqJQMvJTO63moDqVsL/nXXAE83L7xNnR+hn8JBY82HzhX8iykmHk55CnNj8\nJF63D7z+CDUKmjaZ0L/Ketu/oAn1z5M312jA9MXiBg7kyGd10niVr4LnoObN\n/peHQL+jYI+R9ZohyltojhkLmjITiG5OH9TAm7X8/DMO0R9wguGFcee35o9V\n4cej3Q/tHzcNpBiIEUAulgt9baWnvXTuV0cttK4wvqmEJac+SeZEbbQvyzgc\nOLApqDMGY1QrkeFF6k4+3ndPbacmfDR5hAIcI29JXImyjA0WDn2bkutksCKC\nDlnfCxKDpHyvYoGxgQnsLnbo6Z5sOLCTsIFznJQSdUK26rv5VLny6PaE5o2M\nr7WZwcGGXX21/pZA/mB7raUzSJByZXPqp55357rUllo93GQdxFKDbkd/lZCc\nVrucHC2+BpQM3R/alw5OsJ5SG5fOeinB+eb0TmHPNROO9HYTiur7yz+9IP2n\nRCELSpxSpGFwIkF1A6djLXP4nzWuAG7cUrMl+kA9Qa7TsNf6agbScmL7yfC0\nAdGeHZKDn2FQrhhz2TTkTJY/qBTKLdqKTLFx2/+42jRW1Y/CETIWlzBZplkZ\n0YNw9pI9oX/rN6KZyDfMKHhN2n4PBtEdw37ysZ4FSn7YeT4tfdRNEPiKdy4W\noI13\r\n=qyO3\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD+gE6Q8wAgzvwPBYuQRYyg1naihefFzxaT/m7iz+BC1QIgR799AgJq+Wlc2NPZajSqgMovRLb90IyOjc14PQNKthg="}],"size":3191,"noattachment":false,"key":"/egg-userrole/-/egg-userrole-2.1.0.tgz"},"maintainers":[{"email":"atian25@qq.com","name":"atian25"},{"email":"dead_horse@qq.com","name":"dead_horse"},{"email":"fengmk2@gmail.com","name":"fengmk2"},{"email":"sakura9515@gmail.com","name":"popomore"},{"email":"shaoshuai0102@gmail.com","name":"shaoshuai0102"},{"email":"whxaxes@gmail.com","name":"wanghx"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/egg-userrole_2.1.0_1544777395507_0.5779311320053058"},"_hasShrinkwrap":false,"readme":"# egg-userrole\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/egg-userrole.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/egg-userrole\n[travis-image]: https://img.shields.io/travis/eggjs/egg-userrole.svg?style=flat-square\n[travis-url]: https://travis-ci.org/eggjs/egg-userrole\n[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-userrole.svg?style=flat-square\n[codecov-url]: https://codecov.io/github/eggjs/egg-userrole?branch=master\n[david-image]: https://img.shields.io/david/eggjs/egg-userrole.svg?style=flat-square\n[david-url]: https://david-dm.org/eggjs/egg-userrole\n[snyk-image]: https://snyk.io/test/npm/egg-userrole/badge.svg?style=flat-square\n[snyk-url]: https://snyk.io/test/npm/egg-userrole\n[download-image]: https://img.shields.io/npm/dm/egg-userrole.svg?style=flat-square\n[download-url]: https://npmjs.org/package/egg-userrole\n\nProvide dynamic roles based authorisation. Use [koa-roles](https://github.com/koajs/koa-roles).\n\n## Install\n\n```bash\n$ npm i egg-userrole --save\n```\n\n## Usage\n```javascript\n// {app_root}/config/plugin.js\nexports.userrole = {\n  package: 'egg-userrole',\n};\n```\n\n> Recommend to use along with custom `userservice` plugin (which provide `ctx.user`).\n>\n> see [`egg-userservice`](https://github.com/eggjs/egg-userservice) for more info.\n\n### Build-in\n\n`Roles` build-in `failureHandler`:\n\n```javascript\nfunction failureHandler(ctx, action) {\n  const message = 'Forbidden, required role: ' + action;\n  if (ctx.acceptJSON) {\n    ctx.body = {\n      message: message,\n      stat: 'deny',\n    };\n  } else {\n    ctx.status = 403;\n    ctx.body = message;\n  }\n};\n```\n\nBuild-in `user` role define:\n\n```javascript\napp.role.use('user', ctx => !!ctx.user);\n```\n\n### How to custom `failureHandler`\n\nDefine `app.role.failureHandler(action)` method in `config/role.js`\n\n- `app/extend/context.js`\n\n```javascript\n// {app_root}/config/role.js or {framework_root}/config/role.js\nmodule.exports = app => {\n  app.role.failureHandler = function(ctx, action) {\n    if (ctx.acceptJSON) {\n      ctx.body = { target: loginURL, stat: 'deny' };\n    } else {\n      ctx.realStatus = 200;\n      ctx.redirect(loginURL);\n    }\n  };\n}\n```\n\n### How to custom role\n\n```javascript\n// {app_root}/config/role.js or {framework_root}/config/role.js\nmodule.exports = function(app) {\n  app.role.use('admin', ctx => {\n    return ctx.user && ctx.user.isAdmin;\n  });\n\n  app.role.use('can write', async ctx => {\n    const post = await ctx.service.post.fetch(ctx.request.body.id);\n    return ctx.user.name === post.author;\n  });\n};\n```\n\n## Questions & Suggestions\n\nPlease open an issue [here](https://github.com/eggjs/egg/issues).\n\n## License\n\n[MIT](https://github.com/eggjs/egg-userrole/blob/master/LICENSE)\n","publish_time":1544777395621,"_cnpm_publish_time":1544777395621,"dist-tags":{"latest":"2.1.0"}}