Esempio n. 1
0
        protected string GetManageHospitalIDs()
        {
            var roleName = ((UserIdentity)this.Context.CurrentUser).RoleName;

            if (string.IsNullOrEmpty(roleName))
            {
                return(null);
            }
            return(RoleBll.GetDataByName(roleName)?.ManageHospital);
        }
Esempio n. 2
0
        public RoleModule() : base("Role")
        {
            this.RequiresAuthentication();

            Get["RoleManage"] = _ => ValidPermission("RoleManage") ? View["RoleManage", RoleBll.GetData()] : View["NoPermissions"];
            Post["QueryRole"] = p =>
            {
                string name     = Request.Form["RoleName"];
                var    roleList = RoleBll.RoleLikeQuery(name);
                return(View["RoleManage", roleList]);
            };
            Post["CheckRoleName/{Name}"] = p => RoleBll.GetDataByName(p.Name) != null;
            Get["RoleAdd"]  = _ => ValidPermission("RoleAdd") ? View["RoleAdd"] : View["NoPermissions"];
            Post["RoleAdd"] = p =>
            {
                var roleModel = new RoleModel
                {
                    Name           = Request.Form["RoleName"].ToString(),
                    CreateTime     = DateTime.Now.ToString(),
                    CreateUer      = Context.CurrentUser.UserName,
                    Permission     = $"{Request.Form["Node"]},{Request.Form["group"]}",
                    Status         = Request.Form["Status"].ToString(),
                    ManageHospital = string.IsNullOrEmpty(Request.Form["HospitalText"]) ? ConstFile.ALL : Request.Form["HospitalText"].ToString()
                };
                RoleBll.Insert(roleModel);
                return(Response.AsRedirect("RoleManage"));
            };
            Get["RoleEdit/{Name}"] = p =>
            {
                var model = RoleBll.GetDataByName(p.Name);
                return(this.ValidPermission("RoleEdit") ? View["RoleEdit", model] : View["NoPermissions"]);
            };
            Post["RoleEdit"] = _ =>
            {
                var roleModel = new RoleModel
                {
                    Name           = Request.Form["Name"].ToString(),
                    CreateTime     = DateTime.Now.ToString(),
                    CreateUer      = Context.CurrentUser.UserName,
                    Permission     = $"{Request.Form["Node"]},{Request.Form["group"]}",
                    Status         = Request.Form["Status"].ToString(),
                    ManageHospital = string.IsNullOrEmpty(Request.Form["HospitalText"]) ? ConstFile.ALL : Request.Form["HospitalText"].ToString()
                };
                RoleBll.Update(roleModel);
                return(Response.AsRedirect("RoleManage"));
            };
            Post["RoleDelete/{Name}"] = p =>
            {
                return(RoleBll.Delete(p.Name));
            };
            Get["GetRolesToJson"] = _ =>
            {
                return(Response.AsJson(RoleBll.GetBuiCheckBoxJson()));
            };
        }
Esempio n. 3
0
        public WelcomeModule()
        {
            #region LoginRemote
            Get["/"] = _ =>
            {
                return(View["Login"]);
            };
            Get["Login"] = _ =>
            {
                //生成CSRF token.
                this.CreateNewCsrfToken();
                return(View["Login"]);
            };
            Post["Login"] = p =>
            {
                //CSRF token 检验
                this.ValidateCsrfToken();
                var loginModel = this.Bind <LoginModel>();
                var model      = LoginBll.Verify(UserBll.GetData(), loginModel.Username, loginModel.Password);
                if (model != null && !string.IsNullOrEmpty(model.RoleName))
                {
                    var role = RoleBll.GetDataByName(model.RoleName);
                    if (role != null && role.Status != "0")
                    {
                        Guid guid = Guid.NewGuid();
                        //注意 nancy的session实际用的是cookie,所以最大4K字节
                        Context.Request.Session[guid.ToString()] = model;
                        return(this.LoginAndRedirect(guid, fallbackRedirectUrl: "/index"));
                    }
                }
                return(View["Login", "false"]);
            };
            Get["LoginOut"] = _ =>
            {
                Session.DeleteAll();
                return(this.LogoutAndRedirect("~/"));
            };
            #endregion

            #region ClientUpdate

            Get["api/RequestNewestPackageUrl/{HopitalID}/{OldNumber}"] = p =>
            {
                RequestNewestPackageUrlResponseModel res = ClientUpdateBll.RequestNewestPackageUrl(p.HopitalID, p.OldNumber);
                return(Response.AsJson(res));
            };

            Get["api/RequestNewestAutoupdater/{OldVersion}"] = p =>
            {
                RequestNewestPackageUrlResponseModel res = ClientUpdateBll.RequestNewestAutoupdater(p.OldNumber);
                return(Response.AsJson(res));
            };
            #endregion
        }
Esempio n. 4
0
        protected bool ValidPermission(string action)
        {
            var roleName = ((UserIdentity)this.Context.CurrentUser).RoleName;

            if (string.IsNullOrEmpty(roleName))
            {
                return(false);
            }
            var permisson = RoleBll.GetDataByName(roleName)?.Permission;

            if (string.IsNullOrEmpty(permisson))
            {
                return(false);
            }
            return(PermissionHelper.Validation(permisson, action));
        }