yunjiuye.js 1015 B

12345678910111213141516171819202122232425262728293031323334
  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. async login() {
  9. const body = this.ctx.request.body;
  10. const { code, org } = body;
  11. const res = await this.service.checkUserIsConnect(body);
  12. const { toBindPage, toDealTokenPage } = this.app.config.yunjiuye;
  13. // 没关联,转到登录页面
  14. if (!res) {
  15. this.ctx.redirect(`${toBindPage}?code=${code}&org=${org}`);
  16. } else {
  17. // 已关联,转到加载token页面
  18. const token = await this.service.userToken(res);
  19. this.ctx.redirect(`${toDealTokenPage}?token=${token}`);
  20. }
  21. }
  22. async userBind() {
  23. const body = this.ctx.request.body;
  24. // 成功返回suid
  25. const res = await this.service.userBind(body);
  26. // 请求token,返回token
  27. const token = await this.service.userToken(res);
  28. this.ctx.ok({ data: token });
  29. }
  30. }
  31. module.exports = YunjiuyeController;