@using Microsoft.Extensions.Options
@inject IOptions<CookieKeyDefine> CKD
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - FAuth</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
    <header>
        <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
            <div class="container">
                <a class="navbar-brand" asp-controller="Home" asp-action="Index">FAuth统一认证登录平台（SSO）</a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                        aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
                    <ul class="navbar-nav flex-grow-1">
                        <li class="nav-item">
                            <a class="nav-link text-dark" fajax-updata="main" asp-controller="App" asp-action="Index">应用管理</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" fajax-updata="main" asp-controller="RoleGroup" asp-action="Index">角色组管理</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" fajax-updata="main" asp-controller="Role" asp-action="Index">角色管理</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" fajax-updata="main" asp-controller="User" asp-action="Index">用户管理</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-dark" target="_blank" href="/api">接口文档</a>
                        </li>
                    </ul>
                </div>
                <div id="userBar">
                    <div id="login">
                        <a asp-controller="user" asp-action="login" fajax-updata="main">登录</a>
                    </div>
                    <div id="logout">
                        <span>欢迎： <span id="userName"></span></span>
                        <a asp-controller="user" asp-action="ResetPassword" fajax-updata="main">修改密码</a>
                        <a href="#" id="logOut">退出</a>
                    </div>
                </div>
            </div>
        </nav>
    </header>
    <div class="container">
        <main role="main" class="pb-3">
            @RenderBody()
        </main>
    </div>

    <footer class="border-top footer text-muted">
        <div class="container">
            &copy; 2020 - FAuth - <a target="_blank" href="http://39.105.71.191/Falcon/FalconSSO/issues">技术支持</a>
        </div>
    </footer>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/lib/vue/vue.min.js"></script>
    <script src="~/lib/jquery.cookie/jquery.cookie-1.4.1.min.js"></script>
    <script src="~/lib/jquery.unobtrusive-ajax/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="~/js/site.js" asp-append-version="true"></script>
    <script type="text/javascript">

    //设置用户key
    myJs.userKey = "@CKD.Value.UserKey";

    //刷新用户条
    function RefreshUserBar() {
        var ticket =myJs.getTicket();
        if (!ticket) {
            $("#logout").hide();
            $("#login").show();
        }
        if (ticket) {
            var url = "/api/User/GetUserByTicket";
            var data = { ticket: ticket };
            myJs.get(url, data, function (d) {
                $("#userName").html(d.Name);
                $("#logout").show();
                $("#login").hide();
            }, function (c,i,m) {
                $("#logout").hide();
                $("#login").show();
                myJs.msg(m);
                myJs.removeTicket();
            });
        }
    }

    function logOut() {
    var ticket = myJs.getTicket();
    var url = "/api/User/Logout";
    var data = { ticket: ticket };
    myJs.post(url, data, function (d) {
        myJs.removeTicket(ticket);
        RefreshUserBar();
    }, function (s,i,m) {
        myJs.msg(m);
    });
    }
    $(function () {
        RefreshUserBar();
        $("#logOut").click(function () {
            logOut();
            return false;
        });
    });
    </script>
    @RenderSection("Scripts",required: false)
</body>
</html>
