Commit 93092b65 authored by lvweichao's avatar lvweichao

update: login redirct pandora

parent f0407c55
......@@ -7,6 +7,12 @@ const LOGIN_URI = {
'production': "http://web-rest.int.yidian-inc.com"
}
const PANDORA_URI = {
'development': "http://pandora.yidian-inc.com",
'test': "http://pandora.yidian-inc.com",
'production': "http://pandora.yidian-inc.com"
}
const API_INTERNAL_URI = {
'development': "bp-test.ini.yidian-inc.com ",
'test': "bp-test.ini.yidian-inc.com ",
......@@ -17,5 +23,6 @@ module.exports = {
env: env,
port: port,
LOGIN_URI: LOGIN_URI[env],
API_INTERNAL_URI: API_INTERNAL_URI[env]
API_INTERNAL_URI: API_INTERNAL_URI[env],
PANDORA_URI: PANDORA_URI[env]
};
const LOGIN_URI = require('../config.js').LOGIN_URI
const PANDORA_URI = require('../config.js').PANDORA_URI
const req = require('../utils/request').httpReq
exports.login = async (ctx, next) => {
var url = `${LOGIN_URI}/api/v1/pandora/auth`;
var opts = {
// exports.login = async (ctx, next) => {
// const url = `${LOGIN_URI}/api/v1/pandora/auth`;
// const opts = {
// url: url,
// method: 'POST',
// json: true,
// body : ctx.request.body
// }
// console.log("koa login:::::", ctx.request)
// ctx.body = await req(ctx, opts)
// }
exports.fetch_user = async (ctx, next) => {
const url = `${PANDORA_URI}/api/user/getuser`;
const cookie = ctx.request.header.cookie;
const opts = {
url: url,
method: 'POST',
json: true,
timeout: 8000,
body : ctx.request.body
method: 'GET',
headers: {
'Cookie': ctx.request.header.cookie
}
}
console.log("fetch_user:::::", ctx.request)
ctx.body = await req(ctx, opts)
}
}
\ No newline at end of file
const { API_INTERNAL_URI } = require('../config.js')
const API_INTERNAL_URI = require('../config.js').API_INTERNAL_URI
const req = require('../utils/request').httpReq
var query = {
async get_permissions(ctx, next) {
......@@ -18,12 +19,13 @@ var query = {
exports.query = async (ctx, next) => {
var type = ctx.params.type
console.log("koa user::::::", type)
if (query[type]) {
try {
ctx.set('Content-Type', 'application/json; charset=utf-8')
await query[type](ctx, next)
} catch (e) {
console.error('/home/q error', e, ctx.url, ctx.headers['cookie'])
console.error('/api/v1 error', e, ctx.url, ctx.headers['cookie'])
ctx.body = { status: 'failed', reason: 'Internal Server Error' }
}
} else {
......
......@@ -6,6 +6,9 @@ const router = Router();
const API_VERSION = "/api/v1";
router.post(`${API_VERSION}/login`, system.login);
router.get(`${API_VERSION}/fetch_user`, system.fetch_user);
router.get(`${API_VERSION}/user/:type`, user.query)
module.exports = router;
......@@ -9,27 +9,28 @@
<script>
// Layout 为布局组件,控制页面基础布局,通过 slot 实现
// import Layout from '@/layouts';
// import { fetchCurrentUser } from './services/user';
import { fetchCurrentUser } from './service/user';
// async function isUserLogged() {
// return (await fetchCurrentUser()).status === 'success';
// }
async function isUserLogged() {
const res = await fetchCurrentUser()
return res.status === 'success';
}
// function redirectToLogin() {
// const loginUrl = '//pandora.yidian-inc.com/tools/admin/login';
// const cbUrl = location.href;
// location.href = `${loginUrl}?callback=${cbUrl}`;
// }
function redirectToLogin() {
const loginUrl = '//pandora.yidian-inc.com/tools/admin/login';
const cbUrl = location.href;
location.href = `${loginUrl}?callback=${cbUrl}`;
}
export default {
// components: {
// Layout,
// },
// async mounted() {
// if (!(await isUserLogged())) {
// redirectToLogin();
// }
// },
async mounted() {
// http://dev.yidian-inc.com:8081/home
if (!(await isUserLogged())) {
redirectToLogin();
} else {
}
},
};
</script>
......
......@@ -7,6 +7,10 @@ export async function login(email, password) {
return res.data;
}
export async function getPermissions() {
return await axios.post("api/home/user/get_permissions")
export async function fetchCurrentUser() {
return await axios.get("api/v1/fetch_user");
}
export async function getPermissions(email) {
return await axios.get("api/v1/user/get_permissions", { email });
}
\ No newline at end of file
......@@ -2,25 +2,26 @@
* axios封装
*/
import axios from "axios";
import { ElMessage } from "element-plus";
// import { ElMessage } from "element-plus";
// import { APP_URI } from "../config/app.config";
/**
* show error tip
* @param mgs
*/
const showErrorMessage = mgs => {
ElMessage({
message: mgs,
type: "error",
showClose: true
});
};
// const showErrorMessage = mgs => {
// ElMessage({
// message: mgs,
// type: "error",
// showClose: true
// });
// };
/**
* default axios config
*/
export const defaultConfig = {
// baseURL: APP_URI,
withCredentials: true,
timeout: 10000
};
......@@ -71,52 +72,26 @@ instance.interceptors.request.use(
instance.interceptors.response.use(
function (response) {
const { data = {} } = response;
const code = data.code ?? -1;
if (code !== 0) {
const msg = data.reason || "未定义错误";
showErrorMessage(data.reason);
return Promise.reject({ code, msg });
}
if (data.message) {
ElMessage({
message: data.reason,
type: "info",
showClose: true
});
}
// const code = data.code ?? -1;
// if (code !== 0) {
// const msg = data.reason || "未定义错误";
// showErrorMessage(data.reason);
// return Promise.reject({ code, msg });
// }
// if (data.message) {
// ElMessage({
// message: data.reason,
// type: "info",
// showClose: true
// });
// }
return data;
},
function (error) {
if (!(error.code && error.code === -1)) error.message = "接口请求错误";
showErrorMessage(error.message);
return Promise.reject(error);
}
// function (error) {
// if (!(error.code && error.code === -1)) error.message = "接口请求错误";
// showErrorMessage(error.message);
// return Promise.reject(error);
// }
);
// /**
// * Get
// * @param {*} url
// * @param {*} params
// */
// export const get = ({url, params, headers}) => {
// return instance.request({
// url,
// method: "get",
// params
// });
// };
// /**
// * Post
// * @param {*} url
// * @param {*} params
// */
// export const post = ({url, data, headers}) => {
// return instance.request({
// url,
// method: "post",
// data
// });
// };
export default instance;
......@@ -16,7 +16,9 @@ module.exports = {
// changeOrigin: true,
// },
// },
proxy: 'http://localhost:8055'
proxy: 'http://localhost:8055',
hot: true,
disableHostCheck: true,
},
},
chainWebpack: config => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment