'use strict'; const Controller = require('egg').Controller; class YunjiuyeController extends Controller { constructor(ctx) { super(ctx); this.service = this.ctx.service.yunjiuye; } async login() { const body = this.ctx.request.body; const { code, org } = body; const res = await this.service.checkUserIsConnect(body); const { toBindPage, toDealTokenPage } = this.app.config.yunjiuye; // 没关联,转到登录页面 if (!res) { this.ctx.redirect(`${toBindPage}?code=${code}&org=${org}`); } else { // 已关联,转到加载token页面 const token = await this.service.userToken(res); this.ctx.redirect(`${toDealTokenPage}?token=${token}`); } } async userBind() { const body = this.ctx.request.body; // 成功返回suid const res = await this.service.userBind(body); // 请求token,返回token const token = await this.service.userToken(res); this.ctx.ok({ data: token }); } } module.exports = YunjiuyeController;