egg-full-utils

1.5.2 • Public • Published

egg-full-utils

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Chinese 中文

Important

crypto-js@3.1.9-1 uuid@3.3.2

Install

$ npm i egg-full-utils --save

Usage

// {app_root}/config/plugin.js
exports.fullUtils = {
  enable: true,
  package: 'egg-full-utils',
};

Configuration

// {app_root}/config/config.default.js
exports.fullUtils = {
  /**
   * ctx.success() => { code: 'success', data: null }
   */
  success: 'success',
};

see config/config.default.js for more detail.

Example

'use strict';
 
module.exports = app => {
  class UserController extends app.Controller {
    /**
     * get: /login?name=xxx&password=123456
     * response: { code: success, data: { userId }}, status: 200
     */
    async login() {
      const result = this.service.user.verify();
      ctx.resp(result);
    }
  }
  return UserController;
};
 
module.exports = app => {
  class UserService extends app.Service {
    async verify() {
      const { ctx } = this;
 
      const payload = ctx.request.body || {};
 
      // get user from db or cache by payload.name
      const user = {
        userId: '10001',
        password: '07e38ba001d5df0dd4488cdf0d5ab8ea',
        salt: 'P7yRKQymchIZ5ZpP',
      };
 
      // check password
      if (user.password !== ctx.helper.md5(payload.password + salt)) {
        return ctx.failed('password error');
      }
 
      return ctx.success({ userId: user.userId });
    }
  }
  return UserService;
};

License

MIT

Package Sidebar

Install

npm i egg-full-utils

Weekly Downloads

2

Version

1.5.2

License

MIT

Unpacked Size

18.8 kB

Total Files

7

Last publish

Collaborators

  • hi.alex.happiness