1234567891011121314151617181920212223242526 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose-free/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const _ = require('lodash');
- const assert = require('assert');
- // 代理机构
- class AgentMechService extends CrudService {
- constructor(ctx) {
- super(ctx, 'agent_mech');
- this.model = this.ctx.model.Patent.AgentMech;
- }
- async login({ phone, password }) {
- const object = await this.model.findOne({ phone }, '+password');
- if (!object) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到用户的信息');
- const { password: op } = object;
- const { secret } = op;
- if (secret !== password) throw new BusinessError(ErrorCode.BAD_PASSWORD, '密码错误');
- const data = _.omit(JSON.parse(JSON.stringify(object)), ['meta', 'password', '__v']);
- const { secret: secrets } = this.config.jwt;
- const jwt = require('jsonwebtoken');
- const token = jwt.sign(data, secrets);
- return token;
- }
- }
- module.exports = AgentMechService;
|