• Asp.net MVC + AngularJS 统一权限管理系统(一)


    背景:

    之前公司内部做了不少系统,但是权限管理都是分开的;一直都想能够有一套统一管理的权限管理系统;有的时间都是一直在计划,随着时间的流逝,计划始终没有实现,也随着项目的增多而这权限管理也变得版本多样了;终于最近能够狠下心来挤出时间来实施这个计划;

    计划

    多系统统一权限管理(在这里我定义成UPMS);实现多个系统的权限统一配置管理;还有统一登录接口,来完成最终的权限认证,因为有了统一配置,肯否定就要有同意登陆认证,要不也是空谈;

    开发环境

    OS:win10

    IDE:VS2015

    DB:mysql

    运行环境:iis6以上

    framework:net4.5

    Begin

    首先,先把界面放出来给大家看看;这种都是因人而异的,ui是在网上download的一个后台管理系统模板,另外加上自己的修改而成;还有用到分页组件,也是开源组件加以修改的,以上所说的后边全部都会开源出来。

    登陆功能目前是采用from认证方式

    [HttpPost]
            public void Login(LoginOnModel collection)
            {
                bool isPersistent = true;
                var obj = loginRepository.GetOne("select * from UserInfo where UserName=@UserName and UserPassword=@Password and IsDel=0;", collection).FirstOrDefault();
                if (obj != null)
                {
                    SetFormAuthentication(isPersistent, obj);
                    //GetCurrentUserPermissions(obj.ID);
                    Response.Redirect("~/Home/Index");
                }
            }
     
    
     private void SetFormAuthentication(bool isPersistent, LoginOnModel user)
     {
          #region
          ////////////////////////////////////////////////////////////////////
          DateTime utcNow = DateTime.Now;
          DateTime cookieUtc = isPersistent ? utcNow.AddDays(7) : utcNow.Add(FormsAuthen
          tication.Timeout);
          FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.
          UserName,
                    utcNow,
                    cookieUtc,
                    isPersistent,
                    user.UserName.ToString(), FormsAuthentication.FormsCookiePath);
          string ticketEncrypted = FormsAuthentication.Encrypt(ticket);
                if (string.IsNullOrEmpty(ticketEncrypted))
                {
                    throw new InvalidOperationException("FormsAuthentication.
                    Encrypt failed.");
                }
                HttpCookie httpCookie = new HttpCookie(FormsAuthentication.
                FormsCookieName, ticketEncrypted)
                {
                    Domain = FormsAuthentication.CookieDomain,
                    HttpOnly = true,
                    Secure = FormsAuthentication.RequireSSL,
                    Path = FormsAuthentication.FormsCookiePath,
                };
                var name = Uri.EscapeDataString(user.UserName);
                HttpCookie nameCookie = new HttpCookie("name", name)
                {
                    Domain = FormsAuthentication.CookieDomain,
                    HttpOnly = true,
                    Secure = FormsAuthentication.RequireSSL,
                    Path = FormsAuthentication.FormsCookiePath,
                };
                //if (isPersistent)
                {
                    httpCookie.Expires = utcNow.AddDays(7);
                    nameCookie.Expires = utcNow.AddDays(7);
                }
                // FormsAuthentication.SetAuthCookie(name, false);
                HttpContext.Response.Cookies.Add(httpCookie);
                HttpContext.Response.Cookies.Add(nameCookie);
                ////////////////////////////////////////////////////////////
                #endregion
                //ViewBag.aaa = Request.Cookies[".FA"].Value;
            }

    html

    @model Com.Test.UPMS.Web.Areas.Admin.Models.LoginOnModel
    @{
        Layout = "~/Areas/Admin/Views/Shared/_LayoutLogin.cshtml";
        ViewBag.SystemName = "统一用户权限管理系统";
        ViewBag.CompanyName = "公司";
    }
    <div class="main-content">
        <div class="row">
            <div class="col-sm-10 col-sm-offset-1">
                <div class="login-container">
                    <div class="center">
                        <h1>
                            <i class="ace-icon fa fa-leaf green"></i>
                            @*<span class="red">Ace</span>*@
                            <span class="white" id="id-text2">@ViewBag.SystemName</span>
                        </h1>
                        <h4 class="blue" id="id-company-text">© @ViewBag.CompanyName</h4>
                    </div>
                    <div class="space-6"></div>
                    <div class="position-relative">
                        <div id="login-box" class="login-box visible widget-box no-border">
                            <div class="widget-body">
                                <div class="widget-main">
                                    <h4 class="header blue lighter bigger">
                                        <i class="ace-icon fa fa-user green"></i>
                                        登陆
                                    </h4>
                                    <div class="space-6"></div>
                                    @using (Html.BeginForm("Login", "Login", FormMethod.Post))
                                    {
                                        <fieldset>
                                            <label class="block clearfix">
                                                <span class="block input-icon input-icon-right">
                                                    <input type="text" class="form-control" name="UserName" placeholder="用户名" />
                                                    <i class="ace-icon fa fa-user"></i>
                                                </span>
                                            </label>
                                            <label class="block clearfix">
                                                <span class="block input-icon input-icon-right">
                                                    <input type="password" class="form-control" name="Password" placeholder="密码" />
                                                    <i class="ace-icon fa fa-lock"></i>
                                                </span>
                                            </label>
                                            <div class="space"></div>
                                            <div class="clearfix">
                                                <label class="inline">
                                                    <input type="checkbox" class="ace" />
                                                    <span class="lbl"> 记住我</span>
                                                </label>
                                                <button type="submit" class="width-35 pull-right btn btn-sm btn-primary">
                                                    <i class="ace-icon fa fa-key"></i>
                                                    <span class="bigger-110">登陆</span>
                                                </button>
                                            </div>
                                            <div class="space-4"></div>
                                        </fieldset>
                                    }
                                </div><!-- /.widget-main -->
                            </div><!-- /.widget-body -->
                        </div><!-- /.login-box -->
                    </div><!-- /.position-relative -->
                    <div class="navbar-fixed-top align-right">
                        <br />
                         
                        <a id="btn-login-dark" href="#">Dark</a>
                         
                        <span class="blue">/</span>
                         
                        <a id="btn-login-blur" href="#">Blur</a>
                         
                        <span class="blue">/</span>
                         
                        <a id="btn-login-light" href="#">Light</a>
                             
                    </div>
                </div>
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div>
    

      

    UI效果:

    login.png

    其他功能UI

    UI效果:

    homeindex.png

    作者:zhangwenjian
    出处:http://www.cnblogs.com/zhangwenjian 或 http://www.zhangwj.com

    本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    如何退出天擎
    git彻底删除或变更子模块
    湖北校园网PC端拨号算法逆向
    PPPoE中间人拦截以及校园网突破漫谈
    vscode打开django项目pylint提示has not "object" member
    从客户端取到浏览器返回的oauth凭证
    教程视频如何压制体积更小
    windows中的软链接硬链接等
    关于博客园和独立博客的一些打算
    拉勾抓职位简单小爬虫
  • 原文地址:https://www.cnblogs.com/zhangwenjian/p/5507916.html
Copyright © 2020-2023  润新知