调整小程序跨h5登录问题

dev_video
杨树明 6 years ago
parent 7e3062001e
commit 6ee46dda3b

@ -56,6 +56,43 @@ if (isDev) {
//debugType="teacher"; //debugType="teacher";
// 学生 // 学生
//debugType="student"; //debugType="student";
function setpostcookie() {
try {
const str =window.location.pathname;
let newdomain=".educoder.net"
if(window.location.origin==="https://www.educoder.net"){
newdomain=".educoder.net";
}else{
newdomain="test-newweb.educoder.net";
}
if(str.indexOf("/wxcode") !== -1){
// console.log("开始重写cookis");
const _params = window.location.search;
// console.log("1111");
if (_params) {
// console.log("22222");
let _search = _params.split('?')[1];
_search.split('&').forEach(item => {
const _arr = item.split('=');
if(_arr[0]==='_educoder_session'){
console.log(newdomain)
cookie.save('_educoder_session',_arr[1],{ path: '/' });
cookie.save('_educoder_session',_arr[1], { domain: newdomain, path: '/'});
}else{
console.log(newdomain)
cookie.save('autologin_trustie',_arr[1],{ path: '/' });
cookie.save('autologin_trustie',_arr[1], { domain: newdomain, path: '/'});
}
});
}
}
}catch (e) {
}
}
function railsgettimes(proxy) { function railsgettimes(proxy) {
@ -63,6 +100,7 @@ if (isDev) {
$.ajax({url:proxy,async:false,success:function(data){ $.ajax({url:proxy,async:false,success:function(data){
if(data.status===0){ if(data.status===0){
timestamp=data.message; timestamp=data.message;
setpostcookie();
} }
}}) }})
checkSubmitFlg=true checkSubmitFlg=true
@ -73,6 +111,7 @@ if (isDev) {
$.ajax({url:proxy,async:false,success:function(data){ $.ajax({url:proxy,async:false,success:function(data){
if(data.status===0){ if(data.status===0){
timestamp=data.message; timestamp=data.message;
setpostcookie();
} }
}}) }})
checkSubmitFlg=true checkSubmitFlg=true
@ -81,6 +120,11 @@ if (isDev) {
}, 2000); }, 2000);
} }
} }
window._debugType = debugType; window._debugType = debugType;
export function initAxiosInterceptors(props) { export function initAxiosInterceptors(props) {
initOnlineOfflineListener() initOnlineOfflineListener()
@ -100,31 +144,7 @@ export function initAxiosInterceptors(props) {
// proxy="https://test-newweb.educoder.net" // proxy="https://test-newweb.educoder.net"
// proxy="https://test-jupyterweb.educoder.net" // proxy="https://test-jupyterweb.educoder.net"
//proxy="http://192.168.2.63:3001" //proxy="http://192.168.2.63:3001"
try {
const str =window.location.pathname;
if(str.indexOf("/wxcode") !== -1){
// console.log("开始重写cookis");
const _params = window.location.search;
// console.log("1111");
if (_params) {
// console.log("22222");
let _search = _params.split('?')[1];
_search.split('&').forEach(item => {
const _arr = item.split('=');
if(_arr[0]==='_educoder_session'){
cookie.save('_educoder_session',_arr[1],{ path: '/' });
cookie.save('_educoder_session',_arr[1], { domain: '.educoder.net', path: '/'});
}else{
cookie.save('autologin_trustie',_arr[1],{ path: '/' });
cookie.save('autologin_trustie',_arr[1], { domain: '.educoder.net', path: '/'});
}
});
}
}
}catch (e) {
}
// 在这里使用requestMap控制避免用户通过双击等操作发出重复的请求 // 在这里使用requestMap控制避免用户通过双击等操作发出重复的请求
// 如果需要支持重复的请求考虑config里面自定义一个allowRepeat参考来控制 // 如果需要支持重复的请求考虑config里面自定义一个allowRepeat参考来控制

@ -45,22 +45,22 @@ const App = (props) => {
const {identifier} = props.match.params; const {identifier} = props.match.params;
// 获取路径参数 // 获取路径参数
const setCookier = () => { const setCookier = () => {
const _params = window.location.search; // const _params = window.location.search;
if (_params) { // if (_params) {
let _search = _params.split('?')[1]; // let _search = _params.split('?')[1];
_search.split('&').forEach(item => { // _search.split('&').forEach(item => {
// console.log(item); // // console.log(item);
const _arr = item.split('='); // const _arr = item.split('=');
cookie.remove(_arr[0], { // cookie.remove(_arr[0], {
path: '/', // path: '/',
domain: '.educoder.net' // domain: '.educoder.net'
}); // });
cookie.save(_arr[0], _arr[1], { // cookie.save(_arr[0], _arr[1], {
path: '/', // path: '/',
domain: '.educoder.net' // domain: '.educoder.net'
}); // });
}); // });
} // }
} }
setCookier(); setCookier();
const [isActive, setIsActive] = useState(-1); const [isActive, setIsActive] = useState(-1);

@ -1,7 +1,7 @@
/* /*
* @Description: * @Description:
* @Author: tangjiang * @Author: tangjiang
* @Github: * @Github:
* @Date: 2020-01-15 15:41:10 * @Date: 2020-01-15 15:41:10
* @LastEditors : tangjiang * @LastEditors : tangjiang
* @LastEditTime : 2020-01-18 11:43:43 * @LastEditTime : 2020-01-18 11:43:43
@ -37,21 +37,22 @@ export const getWXCodeTestCase = (identifier, params) => {
// console.log('加载测试集: ====>>>>>>', res); // console.log('加载测试集: ====>>>>>>', res);
try{ try{
const {data = {}} = res; const {data = {}} = res;
console.log(data.test_sets); if(data.test_sets){
const _path = data.challenge.path; const _path = data.challenge.path;
dispatch({ dispatch({
type: types.GET_WXCODE_TEST_CASE, type: types.GET_WXCODE_TEST_CASE,
payload: { payload: {
test_sets: data.test_sets || [], test_sets: data.test_sets || [],
game_id: data.game && data.game.id, game_id: data.game && data.game.id,
myIdentifier: data.myshixun.identifier, myIdentifier: data.myshixun.identifier,
exec_time: data.challenge.exec_time, exec_time: data.challenge.exec_time,
path: _path.split('')[0] || _path.split(';')[0] || _path, path: _path.split('')[0] || _path.split(';')[0] || _path,
last_compile_output: data.last_compile_output, last_compile_output: data.last_compile_output,
test_sets_count: data.test_sets_count, test_sets_count: data.test_sets_count,
sets_error_count: data.sets_error_count sets_error_count: data.sets_error_count
} }
}); });
}
} catch(err) { } catch(err) {
console.log(err); console.log(err);
}; };
@ -123,7 +124,7 @@ export const evaluateWxCode = (identifier, path) => {
sets_error_count sets_error_count
} = getState().wxcodeReducer; } = getState().wxcodeReducer;
updateWxCode(path, myIdentifier, userCode, game_id, 1).then(res => { updateWxCode(path, myIdentifier, userCode, game_id, 1).then(res => {
// build // build
// const {} = res; // const {} = res;
console.log(res); console.log(res);
const _resubmit = res.data.resubmit; const _resubmit = res.data.resubmit;
@ -176,7 +177,7 @@ export const evaluateWxCode = (identifier, path) => {
type: types.SHOW_WX_CODE_DIALOG, type: types.SHOW_WX_CODE_DIALOG,
payload: true payload: true
}); });
} else { } else {
dispatch({ dispatch({
type: types.IS_SHOW_WXCODE_TEST_CASES, type: types.IS_SHOW_WXCODE_TEST_CASES,
@ -211,7 +212,7 @@ export const evaluateWxCode = (identifier, path) => {
} }
}) })
}, 50); }, 50);
}).catch(err => { }).catch(err => {
dispatch({ dispatch({
type: types.SHOW_WX_CODE_LOADING, type: types.SHOW_WX_CODE_LOADING,

Loading…
Cancel
Save