app-redirect-login.page.js 1 KB
((function() {
    require('common/_app-auth.css');
    let yohoApp = require('../yoho-app'),
        $ = require('yoho-jquery'),
        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');

    if (!sessionKey) {
        return;
    }
    if (oldSessionKey === sessionKey) {
        if (oldSessionKeyErr < 3) {
            localStorage.setItem('oldSessionKeyErr', oldSessionKeyErr + 1);
        } else {
            localStorage.removeItem('oldSessionKeyErr');
            return;
        }
    }
    localStorage.setItem('oldSessionKey', sessionKey);
    yohoApp.goLogin(href);
})());