zoukankan      html  css  js  c++  java
  • cookis

    /// <summary>
    /// 登录
    /// </summary>
    /// <param name="ACount"></param>
    /// <param name="Pwd"></param>
    /// <returns></returns>
    [HttpGet]
    public UsersInfo Login(string ACount = "", string Pwd = "")
    {
    var list = myContext.UsersInfos.Where(s => s.ACount == ACount && s.Pwd == Pwd).ToList();
    if (list != null || list.Count > 0)
    {
    return list.FirstOrDefault();
    }
    else
    {
    return null;
    }
    }

    -------------------------

    @{
    Layout = null;
    }

    <!DOCTYPE html>

    <html>
    <head>
    <meta name="viewport" content="width=device-width" />
    <title>LoginIndex</title>
    <link href="~/Content/bootstrap.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-3.4.1.js"></script>
    <script>
    //文档加载函数
    $(function () {
    if (getCookie("UsersInfo") == null) {
    setCookie("UsersInfo", "[]");
    }
    else {
    var list = JSON.parse(getCookie("UsersInfo"));
    var obj = {
    ACount: list[0].ACount,
    Pwd: list[0].Pwd
    }
    Aj(obj);
    }
    })
    function Login() {
    var obj = {
    ACount: $("#ACount").val(),
    Pwd: $("#Pwd").val(),
    }
    Aj(obj);

    }
    function Aj(obj) {
    $.ajax({
    url: "http://localhost:57190/api/Sale/Login",
    data: obj,
    type: "get",
    dataType: "json",
    success: function (d) {
    if (d != null) {
    var list = JSON.parse(getCookie("UsersInfo"));
    var st = {
    ACount: $("#ACount").val(),
    Pwd: $("#Pwd").val(), UId: d.UId
    };
    list.push(st);
    var data = JSON.stringify(list);
    setCookie("UsersInfo", data);
    alert('登录成功');
    location.href = '/Sale/OrdersInfoIndex?UId=' + d.UId;
    }
    else {
    alert('账号或密码输入错误');
    }
    }
    })
    }


    /* cookie中存值
    */
    function setCookie(name, value) {
    if (value) {
    var days = 1; //定义一天
    var exp = new Date();
    exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
    // 写入Cookie, toGMTString将时间转换成字符串
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString;
    }
    };

    /**
    * cookie中取值
    * */
    function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //匹配字段
    if (arr = document.cookie.match(reg)) {
    return unescape(arr[2]);
    } else {
    return null;
    }
    };
    </script>
    </head>
    <body>
    @using()
    <table class="table" style="margin:0 auto;85%;height:85%;text-align:center">
    <tr>
    <td>账号:</td>
    <td><input id="ACount" type="text" placeholder="请输入您的账号" /></td>
    </tr>
    <tr>
    <td>密码:</td>
    <td><input id="Pwd" type="password" placeholder="请输入您的密码" /></td>
    </tr>
    <tr>
    <td colspan="2"><input id="Button1" type="button" value="登录" onclick="Login()" /></td>
    </tr>
    </table>
    </body>
    </html>

  • 相关阅读:
    设置页面标题title
    路由跳转,页面位置不在顶部
    PyTorch深度学习入门
    删除ubuntu后开机进入grub的解决办法
    研一上英语
    python中常用的几个函数的正确用法-lambda/filter/map/reduce
    【Python教程】 re 模块中findall() 函数返回值展现方式的用法详解
    【Python教程】5种常见字符串去除空格的操作方法
    对python中浅拷贝和深拷贝分析详细介绍
    Git使用
  • 原文地址:https://www.cnblogs.com/gc1229/p/13276198.html
Copyright © 2011-2022 走看看