diff --git a/client/components/Qsso/Qsso.js b/client/components/Qsso/Qsso.js new file mode 100644 index 00000000..aa748d7c --- /dev/null +++ b/client/components/Qsso/Qsso.js @@ -0,0 +1,64 @@ +// file_id:2D7ABF69-3BC0-4175-98C9-5C3D5CB00158 -- nerver change this !! + +/* + * file: qsso-auth.js + * URL: https://qsso.corp.qunar.com/lib/qsso-auth.js + * written by zhibin.ning + * version: 0.1 + * + */ + + + + +var AUTH_SERVER = 'https://qsso.corp.qunar.com', + LOGIN_PAGE = '/login.php', + SORRY_PAGE = '/sorry.html'; + +if (location.hostname.match(/qunar\.ctripgroup\.com$/i)) { + AUTH_SERVER = 'https://qunar.ctripgroup.com/sec/qsso/api'; +} + +var qualifyURL = function (url, encode) { + url = url || ''; + var ret = location.protocol + '//' + location.host + (url.substr(0, 1) === '/' ? '' : location.pathname.match(/.*\//)) + url; + if (encode) { + ret = encodeURIComponent(ret); + } + return ret; +}; + +var URLStringify = function (o) { + var ret = []; + for (var i in o) { + // ret.push( encodeURIComponent(i) + '=' + encodeURIComponent(o[i]) ); + ret.push(i + '=' + o[i]); + } + return ret.join('&'); +}; +var qsso; +module.exports = qsso = { + 'auth': function (loginURI, opt_ext) { + if (!location.hostname.match(/\.qunar(man|ops)?\.com$|\.qunarman\.com$|qunar\.it$|\.928383\.com$|^928383\.com$|qunar\.ctripgroup\.c(om|n)$|\.ctrip(corp)?\.com$|^opsdata\.me$|\.mofun\.com$/i)) { + location.href = AUTH_SERVER + SORRY_PAGE + '?host=' + qualifyURL('', true); + return; + } + var ret = qualifyURL(loginURI, true); + + var redirectURL = AUTH_SERVER + LOGIN_PAGE + '?ret=' + ret + (opt_ext ? '&ext=' + encodeURIComponent(URLStringify(opt_ext)) : ''); + // console.log(redirectURL); + location.href = redirectURL; + }, + + 'attach': function (eid, loginURI, opt_ext) { + var login = function () { + qsso.auth(loginURI, opt_ext); + + }; + document.getElementById(eid).onclick = login; + if (location.hash.match('qsso-auto-login')) { + login(); + } + } +}; + diff --git a/client/containers/Home/Home.js b/client/containers/Home/Home.js index 5f29d283..f97bf5d5 100644 --- a/client/containers/Home/Home.js +++ b/client/containers/Home/Home.js @@ -7,6 +7,7 @@ import PropTypes from "prop-types"; import { withRouter } from 'react-router'; import { logoSVG, getImgPath } from '../../common.js'; import { changeMenuItem } from '../../reducer/modules/menu' +import Qsso from '../../components/Qsso/Qsso.js' const HomeGuest = () => (