zoukankan      html  css  js  c++  java
  • 完成注销 登录限制过滤 添加用户

    完成注销 登录限制过滤 添加用户

    前面视频 文章地址

     
    这节课 我们要实现 一个登录的限制

    如果用户没有登录 就访问我们的管理页面 那么 直接跳转到登录 当然 可以可以给一个中间的页面 对用户进行友好的提示 

    我们首先找到 管理页的action
     
    复制代码
            public ActionResult Index()
            {
                return View();
            }
    复制代码

    我们编写一个过滤器 要继承和实现一个接口

    复制代码
        public class CheckLoginFilter : FilterAttribute, IActionFilter
        {
    
            public void OnActionExecuted(ActionExecutedContext filterContext)
            {
                if (HttpContext.Current.Session["user"] == null)
                {
                    filterContext.HttpContext.Response.Write("-1");
                }
            }
    
            public void OnActionExecuting(ActionExecutingContext filterContext)
            {
                if (HttpContext.Current.Session["user"] == null)
                {
                   //filterContext.HttpContext.Response.Write("-1");
                    try
                    {
                        filterContext.Result = new RedirectResult("/Account/Login");
                    }
                    catch (Exception)
                    {
                        filterContext.Result = new RedirectResult("/Common/Error");
                    }
                }
            }
        }
    复制代码

    然后 为管理员打上标记

    复制代码
            [CheckLoginFilter()]
            public ActionResult Index()
            {
                return View();
            }
    复制代码

    用户添加页面的设计

    复制代码
    <div id="tb" style="padding:5px;height:auto">
    
                    <div style="margin-bottom:5px">
                            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"></a>
                            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true"></a>
                            <a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true"></a>
                            <a href="#" class="easyui-linkbutton" iconCls="icon-cut" plain="true"></a>
                            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true"></a>
                    </div>
    
                    <div>
                            用户名: <input type="text" id="name" style="80px">
                            密 码: <input type="text" id="pwd" style="80px">
                            技 术: 
                            <select id="tec" class="easyui-combobox" panelHeight="auto" style="100px">
                                    <option value="java">Java</option>
                                    <option value="c">C</option>
                                    <option value="basic">Basic</option>
                                    <option value="perl">Perl</option>
                                    <option value="python">Python</option>
                            </select>
                            <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="AddUser();">添加</a>
                    </div>
    
            </div>
    复制代码

    添加提交事件

    复制代码
    function AddUser() {
        //$.messager.alert('Warning', '你真的添加吗!');
        var name = $('#name').val();
        var pwd = $('#pwd').val();
        var tec = $('#tec').val();
    
        if (name == '' || pwd == '') {
            $.messager.alert('Warning', '用户名或者密码为空!');
        }
        else {
            $.post("/Account/AddUser", { name: name, name: pwd },
               function (data) {
                   //alert("Data Loaded: " + data);
                   if (data == '0') {
                       $.messager.alert('Warning', '添加失败!');
                   }
                   else {
                       $.messager.alert('Warning', '添加成功!');
                   }
               });
        }
    }
    复制代码

    高清录屏下载地址

    18-19节

    http://pan.baidu.com/share/link?shareid=1882807484&uk=1731339785

    20节

    http://pan.baidu.com/share/link?shareid=473445811&uk=36858893

    21-23节

    http://pan.baidu.com/share/link?shareid=1857442884&uk=1731339785

    需要源码的:http://www.bamn.cn/thread-64-1-1.html?usersystem.rar

  • 相关阅读:
    数据结构小总结(成都磨子桥技工学校数据结构前12题)
    Scrum 冲刺博客第二篇
    Scrum 冲刺博客第一篇
    centos部署keepalived服务
    第四周作业
    Svelte 中怎样做双向数据绑定
    Svelte 中多层组件事件转发
    Svelte 中的事件修饰符
    怎样在 Svelte 中设置自定义事件
    怎样使用 Svelte 中的异步块
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/3259423.html
Copyright © 2011-2022 走看看