user.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. 'use strict';
  2. const _ = require('lodash');
  3. const meta = require('./.user.js');
  4. const Controller = require('egg').Controller;
  5. const { CrudController } = require('naf-framework-mongoose/lib/controller');
  6. const TLSSigAPIv2 = require('tls-sig-api-v2');
  7. const qiniu = require('qiniu');
  8. class UserController extends Controller {
  9. constructor(ctx) {
  10. super(ctx);
  11. this.service = this.ctx.service.user;
  12. }
  13. async uppasswd() {
  14. const res = await this.service.uppasswd(this.ctx.request.body);
  15. this.ctx.ok({ data: res });
  16. }
  17. async querymenus() {
  18. const res = await this.service.querymenus(this.ctx.query);
  19. this.ctx.ok({ data: res });
  20. }
  21. async updatebyuid() {
  22. const res = await this.service.updatebyuid(this.ctx.params, this.ctx.request.body);
  23. this.ctx.ok({ data: res });
  24. }
  25. async bind() {
  26. const res = await this.service.bind(this.ctx.request.body);
  27. this.ctx.ok({ data: res });
  28. }
  29. async gensign() {
  30. const api = new TLSSigAPIv2.Api(this.app.config.sdkappid, this.app.config.secretkey);
  31. const res = api.genSig(this.ctx.request.body.userid, 86400 * 180);
  32. console.log('sig ' + res);
  33. // sig = api.genSigWithUserbuf(this.ctx.request.body.userid, 86400 * 180, this.ctx.request.body.name);
  34. // console.log('sig with userbuf ' + sig);
  35. this.ctx.ok({ data: res });
  36. }
  37. async gensignqili() {
  38. const ak = 'CNOr-D4vAG3bNP3uXfwsL_n2FMXFm5C-MUof3goK';
  39. const sk = 'GL5k-Hc-MPM1ZPlRPYfNhMgN-pPGRTuua8gTc2Pj';
  40. const credentials = new qiniu.Credentials(ak, sk);
  41. const roomToken = await qiniu.room.getRoomToken({
  42. appId: 'f3m2e54ms',
  43. roomName: this.ctx.request.body.roomname,
  44. userId: this.ctx.request.body.userid,
  45. expireAt: Date.now() + (1000 * 60 * 60 * 3), // token 的过期时间默认为当前时间之后 3 小时
  46. permission: 'user',
  47. }, credentials);
  48. console.log('sig ' + roomToken);
  49. // sig = api.genSigWithUserbuf(this.ctx.request.body.userid, 86400 * 180, this.ctx.request.body.name);
  50. // console.log('sig with userbuf ' + sig);
  51. this.ctx.ok({ data: roomToken });
  52. }
  53. }
  54. module.exports = CrudController(UserController, meta);