l1017340371
liweiboy
2016-06-12 12:03
采纳率: 0%
浏览 3.7k

单点登录如何实现一个网站登录,另一个网站自动登录

这是项目一的登录方法
function zjlogin() {
var username = $("#username").val();
var password = $("#password").val();
var yzm1 = $('#gryzm').val();
var rand = $('#rand1').val();

        if (username == null || $.trim(username) == "") {
            alert("用户名不能为空!");
            return;
        }
        if (password == null || $.trim(password) == "") {
            alert("密码不能为空!");
            return;
        }
        if (yzm1 == null || $.trim(yzm1) == "") {
            alert("验证码不能为空!");
            return;
        }
        if (yzm1 != null || $.trim(yzm1) != ""){
                if(yzm1.toLowerCase()!=rand.toLowerCase()){
                    alert("验证码错误!");
                    $('#gryzm').val("");
                    return ;
                }
            var reg = /^\d{11}$/ig;
    //验证用户输入是否是手机号
    if (reg.test(username)) {

        //如果是手机登录

          $.ajax({ 
               type: "post", 
               data:{ username: username, pwd:password},
               url: "${ctx}/userController/toCheckPhone.do",
                 success: function (meg) { 
                  if(""==meg){            
                      alert("手机号不存在!请重新登录");
                      return ;
                  }else{
                        window.location.href = "${ssoUrl}/sso/remoteLogin?username="
                            + meg
                            + "&password="
                            + password
                            + "&service=${localUrl}/home/home.do&submit=true&loginUrl=${localUrl}/home/home.do";

                  }
                    }, 
                     error: function (XMLHttpRequest, textStatus, errorThrown) { 
                         alert("hhsfhghsdh");
                      alert(errorThrown); 
                     } 
                });


    }else{


        $.ajax({ 
               type: "post", 
               data:{ username: username, pwd:password},
               url: "${ctx}/userController/toCheckUserName.do", 
                dataType: "json", 
                 success: function (meg) { 
                  if(false == meg){               
                      alert("用户名或密码错误!请重新登录");
                      return ;
                  }else{
                        window.location.href = "${ssoUrl}/sso/remoteLogin?username="
                            + username
                            + "&password="
                            + password
                            + "&service=${localUrl}/home/home.do?&submit=true&loginUrl=${localUrl}/home/home.do";

                  }
                    }, 
                     error: function (XMLHttpRequest, textStatus, errorThrown) { 
                      alert(errorThrown); 
                     } 
                });
            }

    }



            }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • l1017340371
    liweiboy 2016-06-12 12:04

    项目二的登录方法:
    function login() {
    var username = $('#username').val();
    var password = $('#password').val();
    var callBack = $('#callback').val();
    var yzm = $('#gryzm').val();
    if (username == null || $.trim(username) == "") {
    $("#message").text("用户名不能为空!");
    $("#message").css({
    "display" : "inline"
    });
    return;
    }
    if (password == null || $.trim(password) == "") {
    $("#message").text("密码不能为空!");
    $("#message").css({
    "display" : "inline"
    });
    return;
    }
    if (yzm == null || $.trim(yzm) == "") {
    $("#message").text("验证码不能为空!");
    $("#message").css({
    "display" : "inline"
    });
    return;
    }
    if (callBack == "") {

                //callBack = "http://58.221.147.12:80/rdwebup/zz.jsp";
    
                callBack = "http://zwdt.rdzw.gov.cn/";
                //现场
                //callBack ="http://58.221.147.13:7980/rdwebup/showMatterProce.do?flag=bsdt";
            }
    
            var reg = /^\d{11}$/ig;
            var loginType;
            var url;
    
            //验证用户输入是否是手机号
            if (reg.test(username)) {
                //如果是手机号登录
                //现场webconsole地址http://58.221.147.34:8080/webconsole/
                url = "${wcUrl}/userAction_moblieLogin.action?mobile="
                        + username
                        + "&pwd="
                        + password
                        + "&callBack="
                        + callBack + "&failUrl=${cbUrl}/bsdt/login.jsp";
                loginType = 0;
            } else {
    
                var as = "&service="
                        + callBack
                        + "&submit=true&loginUrl=${cbUrl}/bsdt/login.jsp";
    
                var bs = "${ssoUrl}/sso/remoteLogin?username=" + username
                        + "&password=" + password;
                var cs = bs + as;
    
                //console.log(cs);
                url = cs;
                loginType = 1;
            }
            $.post("${ctx}/login.do",{username:username,password:password,loginType:loginType,yzm:yzm},function(mes){
    
                if(mes == "success"){
                    document.getElementById("iframe1").src="http://zjxx.rdzw.gov.cn/ms/bz/login.do?username="+username+"&password="+password;
                    setTimeout("location.href =url;",500);
    
    
                }else if(mes=="yzmerror"){
                    alert("验证码错误!");
                }else if(mes=="")
                {
                    location.href =url; 
                }
                else
                {                   
                    alert("用户名或密码错误!");                   
                }
            });
    
        }
    
    点赞 评论
  • l1017340371
    liweiboy 2016-06-12 12:04

    求大神看看哪儿错了!明明是单点登录,调用的同一个方法!

    点赞 评论
  • cbaxt
    cbaxt 2016-06-12 14:08

    SSO登录后,其它子应用就只需要获取票据,验证通过后才可以取到用户信息
    你第二个项目就不需要再进行登录了
    可以使用iframe 重新请求
    http://sso地址/login.do?service=http://你的子项目地址/bsdt/login.jsp
    如果SSO已经登录的话,就会自动跳转到http://你的子项目地址/bsdt/login.jsp这个地址

    点赞 评论

相关推荐