1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 'use strict';
- /**
- * 登录页面控制器
- *
- * @author CaiAoLin
- * @date 2017/11/15
- * @version
- */
- const SSO = require('../lib/sso');
- module.exports = app => {
- class LoginController extends app.BaseController {
- /**
- * 登录页面
- *
- * @param {Object} ctx - egg全局页面
- * @return {void}
- */
- async index(ctx) {
- const renderData = {};
- await ctx.render('login/login.ejs', renderData);
- }
- /**
- * 登录操作
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- async login(ctx) {
- let loginType = ctx.request.body.type;
- try {
- let result = false;
- loginType = parseInt(loginType);
- if (loginType === 1) {
- // 演示版登陆
- const username = ctx.request.body.username;
- const password = ctx.request.body.password;
- const sso = new SSO(ctx);
- result = await sso.loginValid(username, password);
- } else {
- // 项目版登陆
- result = await ctx.service.projectAccount.accountLogin(ctx.request.body);
- }
- if (!result) {
- throw '登录失败';
- }
- } catch (error) {
- console.log(error);
- }
- ctx.body = 'success';
- }
- }
- return LoginController;
- };
|