1.5.2 • Published 5 years ago

egg-full-utils v1.5.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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

1.5.2

5 years ago

1.5.1

5 years ago

1.4.1

5 years ago

1.3.1

5 years ago

1.2.1

5 years ago

1.1.1

5 years ago

1.0.0

5 years ago