Loading

MVC登录

前言
最近没什么好写的,准备把MVC的登录再写一下,巩固一下
HTML

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>登录 - 瑰园美食</title>
    <link rel="icon" href="~/Content/Images/Icon/Logo.png" />
    <link href="~/Plugin/layui/css/layui.css" rel="stylesheet" />
    <link href="~/Content/Css/LoginStyle.css" rel="stylesheet" />
</head>
<body>
    <h1>

        <span>瑰园美食</span>
        <span>享受美食带来的欢乐~</span>
    </h1>
    <div class="LoginFrom">
        <h2>登录</h2>
        <div class="LoginFrom_Input">
            <input spellcheck="false" class="Input_User" type="text" placeholder="账号" />
            <input class="Input_Pass" type="password" placeholder="密码" />
            <input class="SuccessButton" type="button" value="点我登录" />
            <div class="OAO_YC"><span></span><p>自动登录</p></div>
            <input class="ForgetPass" type="button" value="忘记密码" />
            <input class="RegisterUser" onclick="window.location.href='/Main/Register'" type="button" value="注册账户" />
        </div>
    </div>
    <footer>
        <p>©2019 Yolx</p>
    </footer>
    <script src="~/Plugin/layui/layui.all.js"></script>
    <script>
        var User = document.querySelectorAll(".Input_User")[0];
        var Pass = document.querySelectorAll(".Input_Pass")[0];
        var xhr1 = new XMLHttpRequest();
        var SuccessButton = document.querySelectorAll(".SuccessButton")[0]
        SuccessButton.onclick = function () {
            if (User.value == "" || Pass.value == "") {
                alert("请填写完整!")
            } else {


                xhr1.open("Get", "/Main/UserLogin?User=" + User.value + "&Pass=" + Pass.value + "");
                xhr1.responseType = "json";
                xhr1.send();
                xhr1.onreadystatechange = function () {
                    if (xhr1.status == 200 && xhr1.readyState == 4) {
                        if (xhr1.response.MsgState == true) {
                            window.location.href = "/Main/Index"
                        } else {
                            alert(xhr1.response.MsgText);
                        }
                    }
                }
            }
        }

        //控件
        document.querySelectorAll(".OAO_YC")[0].onclick = function () {
            if (this.className.indexOf("OAO_YC_On") == -1) {
                //开启
                this.classList.add("OAO_YC_On");

            } else {
                //关闭
                this.classList.remove("OAO_YC_On");
            }
        }
    </script>
</body>
</html>

CSS

body {
    margin: 0;
    padding: 0;
    background-image: url('../Images/LoginBG.jpg');
    background-repeat: no-repeat;
    background-size: 100%;
}

h1 {
    position: fixed;
    top: 50%;
    left: 10%;
    transform: translateY(-50%);
    color: #fff;
}

    h1 span {
        display: block;
        font-size: 3vh;
    }

        h1 span:nth-child(1) {
            font-size: 5vh;
            position: relative;
            padding: 0.5vh 0px 1vh;
        }

            h1 span:nth-child(1):after {
                content: '';
                position: absolute;
                left: 0;
                top: 0;
                width: 9.8vh;
                height: 0.35vh;
                background: #fff;
            }



.LoginFrom {
    width: 24vw;
    height: 40vh;
    position: fixed;
    top: 50%;
    right: 10%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, .8);
    border-radius: 0.5vh;
    overflow: hidden;
    
}

    .LoginFrom h2 {
        text-align: center;
        padding: 2vh;
        background: #fff;
        font-size: 2vh;
    }

    .LoginFrom .LoginFrom_Input {
        width: 100%;
        padding: 2vh 0px;
    }

        .LoginFrom .LoginFrom_Input input {
            border: 0;
            width: 80%;
            height: 5vh;
            display: block;
            padding: 0 1vh;
            font-size: 2vh;
            margin: 1vh auto;
            box-sizing: content-box;
            position: relative;
        }

.ForgetPass, .RegisterUser {
    font-size: 1vh !important;
    position: absolute !important;
    background: none;
    width: auto !important;
    height: auto !important;
    bottom: 0px;
}
.SuccessButton {
    background:#fff;
}

.SuccessButton:after {
    content:'';
    position:absolute;
    left:0px;
    bottom:0px;
    height:2px;
    width:10px;
    background:#67b968;
}
/*.SuccessButton:hover {
    border-bottom:1vh solid #67b968;
}*/

.ForgetPass {
    left:0px;
}

.RegisterUser {
    right:0px;
}

footer {
    position: fixed;
    bottom: 0px;
    left: 0px;
    width: 100%;
}

    footer p {
        text-align: center;
        color: rgba(255, 255, 255, 0.8);
        padding: 1.5vh 0px;
        font-size: 1.5vh;
    }

/*开关组*/
.OAO_YC {
    width: 7vh;
    height: 3vh;
    background: #fff;
    border-radius: 1vh;
    padding: .5vh;
    transition: all ease 0.5s;
    position: relative;
    overflow: hidden;
    margin: 1vh 3.8vh;
}

    .OAO_YC p {
        position: absolute;
        top: 0px;
        left: 0px;
        margin: 0;
        padding: 0;
        font-size: 1.5vh;
        height: 100%;
        width: 8vh;
        text-align: center;
        line-height: 2.7em;
        opacity: 0;
        transition: all ease 0.5s;
    }

    .OAO_YC:hover p {
        opacity: 1;
    }

    .OAO_YC:hover span {
        opacity: 0.3;
    }

    .OAO_YC span {
        height: 100%;
        background: #e47575;
        border-radius: 1vh;
        display: block;
        width: 3.7vh;
        transition: all ease 0.5s;
    }

.OAO_YC_On {
    transition: all ease 0.5s;
}

    .OAO_YC_On span {
        transform: translateX(3vh);
        background: #67b968;
}

页面效果
在这里插入图片描述
控制器代码
//用户登录

public ActionResult UserLogin(string User, string Pass)
{

    msg.MsgState = false;
    try
    {
        var listUser = (from tbUser in MyModel.PW_User
                        where tbUser.UserName == User.Trim() && tbUser.UserPass == Pass.Trim()
                        select tbUser).Single();
        Session["UserName"] = User;
        Session["UserID"] = listUser.UserID;
        msg.MsgState = true;
        msg.MsgText = "登录成功";
    }
    catch (Exception e)
    {
        msg.MsgText = "信息错误";
    }

    return Json(msg, JsonRequestBehavior.AllowGet); ;
}

登录效果
在这里插入图片描述
在这里插入图片描述
后言
本文结束了,如果觉得本技术文章对你有帮助请给我点个赞,如果有什么不足的地方,给我提意见,让我加以改进

posted @ 2019-06-09 19:05  LRolinx  阅读(67)  评论(0编辑  收藏  举报