<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>

<script>
    var signin = {
        init:function () {
            //判断是否自动登录
            var tenantName = '${tenantName}';
            var hash = window.location.hash;
            if(hash.indexOf("#access_token")>=0)
            {
                //获取accrss_token
                var tokenString =hash.substring(1,hash.indexOf("&"));
                debugger
                var token = tokenString.substr(hash.indexOf("="));
                //自动登录
                $.ajax({
                    url: "${contextRoot}/oauth2/autoLogin",
                    type: 'POST',
                    dataType: 'json',
                    data:{
                        "token":token
                    },
                    success: function (data) {
                        if(data.successFlg){
                            debugger
                            window.localStorage.setItem("ehrUser", token);

                            location.href = '${contextRoot}/'+tenantName + '/oauth2/index?loginName='+data.obj.user;
                        }else{
                            location.href = '${contextRoot}/oauth2/tokenValidFail';
                        }
                    },
                    error: function (data) {
                        location.href = '${contextRoot}/oauth2/tokenValidFail';
                    }
                });
                return;
            }
        }
    }

    $(function() {
        signin.init();
    });

</script>