mirror of
https://github.com/YMFE/yapi.git
synced 2025-03-07 14:16:52 +08:00
opti: qsso
This commit is contained in:
parent
5e7c6fbcd8
commit
1c4c93152e
64
client/components/Qsso/Qsso.js
Normal file
64
client/components/Qsso/Qsso.js
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -7,6 +7,7 @@ import PropTypes from "prop-types";
|
|||||||
import { withRouter } from 'react-router';
|
import { withRouter } from 'react-router';
|
||||||
import { logoSVG, getImgPath } from '../../common.js';
|
import { logoSVG, getImgPath } from '../../common.js';
|
||||||
import { changeMenuItem } from '../../reducer/modules/menu'
|
import { changeMenuItem } from '../../reducer/modules/menu'
|
||||||
|
import Qsso from '../../components/Qsso/Qsso.js'
|
||||||
|
|
||||||
const HomeGuest = () => (
|
const HomeGuest = () => (
|
||||||
<div className="g-body">
|
<div className="g-body">
|
||||||
@ -180,7 +181,7 @@ class Home extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
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 = {
|
static propTypes = {
|
||||||
introList: PropTypes.array,
|
introList: PropTypes.array,
|
||||||
|
@ -6,6 +6,7 @@ import { loginActions } from '../../reducer/modules/user';
|
|||||||
import { withRouter } from 'react-router'
|
import { withRouter } from 'react-router'
|
||||||
const FormItem = Form.Item;
|
const FormItem = Form.Item;
|
||||||
import './Login.scss'
|
import './Login.scss'
|
||||||
|
import Qsso from '../../components/Qsso/Qsso.js'
|
||||||
|
|
||||||
const formItemStyle = {
|
const formItemStyle = {
|
||||||
marginBottom: '.16rem'
|
marginBottom: '.16rem'
|
||||||
@ -53,7 +54,7 @@ class Login extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if(window.QSSO) window.QSSO.attach('qsso-login','/api/user/login_by_token')
|
Qsso.attach('qsso-login','/api/user/login_by_token')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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/lib@dev.js"></script>
|
||||||
<script src="http://127.0.0.1:4000/prd/index@dev.js"></script>
|
<script src="http://127.0.0.1:4000/prd/index@dev.js"></script>
|
||||||
|
|
||||||
<script src="/lib/qsso-auth.js"></script>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -35,6 +35,5 @@
|
|||||||
document.write('<script src="/prd/' + window.WEBPACK_ASSETS['index.js'].js + '"><\/script>');
|
document.write('<script src="/prd/' + window.WEBPACK_ASSETS['index.js'].js + '"><\/script>');
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script src="/lib/qsso-auth.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user