app-redirect-login.page.js
1.1 KB
((function() {
require('common/_app-auth.css');
let yohoApp = require('../yoho-app'),
$ = require('yoho-jquery'),
qs = require('yoho-qs'),
cookie = require('yoho-cookie');
let $refer = $('#refer');
let href = location.href;
if ($refer.length) {
href = $refer.val();
if (href.indexOf(location.host) < 0) {
href = `${location.protocol}//${location.host}${href}`;
}
}
let oldSessionKey = localStorage.getItem('oldSessionKey') || '';
let oldSessionKeyErr = parseInt(localStorage.getItem('oldSessionKeyErr') || -1, 10);
let sessionKey = cookie.get('app_session_key');
let uid = parseInt(cookie.get('app_uid') || qs.uid, 10);
if (!sessionKey && uid) {
return;
}
if (oldSessionKey === sessionKey) {
if (oldSessionKeyErr < 3) {
localStorage.setItem('oldSessionKeyErr', oldSessionKeyErr + 1);
} else {
localStorage.removeItem('oldSessionKeyErr');
return;
}
}
localStorage.setItem('oldSessionKey', sessionKey);
yohoApp.goLogin(href);
})());