smapsso.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  5. <meta charset="UTF-8">
  6. <title>登录中...</title>
  7. <script src="../o2_core/o2.min.js"></script>
  8. <script src="../o2_lib/Decimal.js"></script>
  9. <script>
  10. function getServiceAddress(config, callback){
  11. if (typeOf(config.center)=="object"){
  12. getServiceAddressConfigObject(callback);
  13. }else if (typeOf(config.center)=="array"){
  14. var center = chooseCenter(config);
  15. if (center){
  16. getServiceAddressConfigObject(callback, center);
  17. }else{
  18. getServiceAddressConfigArray(config, callback);
  19. }
  20. //this.getServiceAddressConfigArray(callback);
  21. }
  22. }
  23. function chooseCenter(config){
  24. var host = window.location.host;
  25. var center = null;
  26. for (var i=0; i<config.center.length; i++){
  27. var ct = config.center[i];
  28. if (ct.webHost==host){
  29. center = ct;
  30. break;
  31. }
  32. }
  33. return center;
  34. }
  35. function getServiceAddressConfigArray(config, callback) {
  36. var requests = [];
  37. config.center.each(function(center){
  38. requests.push(
  39. getServiceAddressConfigObject(function(address){
  40. requests.each(function(res){
  41. if (res.isRunning()){res.cancel();}
  42. });
  43. if (callback) callback(address);
  44. }.bind(this), center)
  45. );
  46. }.bind(this));
  47. }
  48. function getServiceAddressConfigObject(callback, center){
  49. var centerConfig = center;
  50. var host = centerConfig.host || window.location.hostname;
  51. var port = centerConfig.port;
  52. var uri = "";
  53. var locate = window.location;
  54. var protocol = locate.protocol;
  55. if (!port || port=="80"){
  56. uri = protocol+"//"+host+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  57. }else{
  58. uri = protocol+"//"+host+":"+port+"/x_program_center/jaxrs/distribute/assemble/source/{source}";
  59. }
  60. var currenthost = window.location.hostname;
  61. uri = uri.replace(/{source}/g, currenthost);
  62. //var uri = "http://"+layout.config.center+"/x_program_center/jaxrs/distribute/assemble";
  63. return MWF.restful("get", uri, null, function(json){
  64. var serviceAddressList = json.data;
  65. var addressObj = serviceAddressList["x_organization_assemble_authentication"];
  66. var address = protocol+"//"+addressObj.host+(addressObj.port==80 ? "" : ":"+addressObj.port)+"/z_sso_control/jaxrs/sso/smplogin";
  67. if (callback) callback(address);
  68. }.bind(this));
  69. }
  70. o2.addReady(function(){
  71. o2.JSON.get("res/config/config.json", function(config){
  72. getServiceAddress(config, function(address){
  73. var uri = new URI(window.location.toString());
  74. var xtoken = uri.getData("SMAP_SESSION_DATA");
  75. var appID = uri.getData("appID");
  76. var redirect = uri.getData("redirect");
  77. if (xtoken){
  78. var res = new Request.JSON({
  79. url: address+"?SMAP_SESSION_DATA="+encodeURIComponent(xtoken)+"&appID="+appID+"&date="+(new Date()).getTime(),
  80. secure: false,
  81. method: "GET",
  82. noCache: true,
  83. withCredentials: true,
  84. onSuccess: function(responseJSON, responseText){
  85. var result = responseJSON.data.value;
  86. if(result){
  87. if (redirect){
  88. window.location = redirect;
  89. }else{
  90. window.location = "/";
  91. }
  92. }else{
  93. $("ssoerror").set("html","单点失败!"+responseJSON.message);
  94. $("ssoerror").show();
  95. }
  96. }.bind(this),
  97. onFailure: function(xhr){
  98. $("ssoerror").show();
  99. }.bind(this),
  100. onError: function(text, error){
  101. $("ssoerror").show();
  102. }.bind(this)
  103. });
  104. res.send();
  105. }else{
  106. $("ssoerror").set("html","单点失败,认证token为空!");
  107. $("ssoerror").show();
  108. }
  109. });
  110. });
  111. });
  112. </script>
  113. </head>
  114. <body style="background: rgb(239, 239, 244);">
  115. <div id="ssoerror" style="text-align:center;display:none;">单点失败,请联系管理员!</div>
  116. </body>
  117. </html>