yunjiuye.js 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. class YunjiuyeController extends Controller {
  4. constructor(ctx) {
  5. super(ctx);
  6. this.service = this.ctx.service.yunjiuye;
  7. }
  8. // http://127.0.0.1:7001/api/train/y/login?code=中心&org=0
  9. async login() {
  10. const query = this.ctx.query;
  11. const { code, org } = query;
  12. const res = await this.service.checkUserIsConnect(query);
  13. const { toBindPage, toDealTokenPage } = this.app.config.yunjiuye;
  14. // 没关联,转到登录页面
  15. if (!res) {
  16. this.ctx.redirect(`${toBindPage}?code=${code}&org=${org}`);
  17. } else {
  18. // 已关联,转到加载token页面
  19. const token = await this.service.userToken(res);
  20. this.ctx.redirect(`${toDealTokenPage}?token=${token}`);
  21. }
  22. }
  23. async userBind() {
  24. const body = this.ctx.request.body;
  25. // 成功返回suid
  26. const res = await this.service.userBind(body);
  27. // 请求token,返回token
  28. const token = await this.service.userToken(res);
  29. this.ctx.ok({ data: token });
  30. }
  31. }
  32. module.exports = YunjiuyeController;