opti: qsso

This commit is contained in:
suxiaoxin 2017-09-04 09:55:14 +08:00
parent 5e7c6fbcd8
commit 1c4c93152e
5 changed files with 68 additions and 4 deletions

View File

@ -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();
}
}
};

View File

@ -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 = () => (
<div className="g-body">
@ -180,7 +181,7 @@ class Home extends Component {
}
componentDidMount() {
if (window.QSSO && document.getElementById('qsso-login')) window.QSSO.attach('qsso-login', '/api/user/login_by_token')
Qsso.attach('qsso-login', '/api/user/login_by_token')
}
static propTypes = {
introList: PropTypes.array,

View File

@ -6,6 +6,7 @@ import { loginActions } from '../../reducer/modules/user';
import { withRouter } from 'react-router'
const FormItem = Form.Item;
import './Login.scss'
import Qsso from '../../components/Qsso/Qsso.js'
const formItemStyle = {
marginBottom: '.16rem'
@ -53,7 +54,7 @@ class Login extends Component {
}
componentDidMount() {
if(window.QSSO) window.QSSO.attach('qsso-login','/api/user/login_by_token')
Qsso.attach('qsso-login','/api/user/login_by_token')
}

View File

@ -15,7 +15,6 @@
<script src="http://127.0.0.1:4000/prd/lib@dev.js"></script>
<script src="http://127.0.0.1:4000/prd/index@dev.js"></script>
<script src="/lib/qsso-auth.js"></script>

View File

@ -35,6 +35,5 @@
document.write('<script src="/prd/' + window.WEBPACK_ASSETS['index.js'].js + '"><\/script>');
</script>
<script src="/lib/qsso-auth.js"></script>
</body>
</html>