示例#1
0
 public void SaveToCache(YnUser ynUser, int moduleId)
 {
     if (ynUser != null)
     {
         try
         {
             bool       isSaveToCache = false;
             YnWebRight ynWebRight    = new YnWebRight();
             ynWebRight.moduleId = moduleId;
             if (YnUserService.GetInstance().IsSuperAdministrator(ynUser.userId) || YnUserService.GetInstance().IsAdministrator(ynUser.userId))
             {
                 isSaveToCache          = true;
                 ynWebRight.rightManage = true;
                 ynWebRight.rightAdd    = true;
                 ynWebRight.rightEdit   = true;
                 ynWebRight.rightDelete = true;
                 ynWebRight.rightVerify = true;
             }
             else
             {
                 YnWebModuleUserLink ynWebModuleUserLink = YnWebModuleUserLinkService.GetInstance().Get(ynUser.userId, moduleId);
                 if (ynWebModuleUserLink != null)
                 {
                     isSaveToCache          = true;
                     ynWebRight.rightManage = ynWebModuleUserLink.rightManage;
                     ynWebRight.rightAdd    = ynWebRight.rightManage || ynWebModuleUserLink.rightAdd;
                     ynWebRight.rightEdit   = ynWebRight.rightManage || ynWebModuleUserLink.rightEdit;
                     ynWebRight.rightDelete = ynWebRight.rightManage || ynWebModuleUserLink.rightDelete;
                     ynWebRight.rightVerify = ynWebModuleUserLink.rightVerify;// ynWebRight.rightManage ||
                 }
                 string roleIds = GetRoleIds(ynUser.userId);
                 if (!string.IsNullOrEmpty(roleIds))
                 {
                     List <YnWebModuleRoleLink> listYnWebModuleRoleLink = YnWebModuleRoleLinkService.GetInstance().GetList(roleIds, moduleId);
                     if (listYnWebModuleRoleLink != null && listYnWebModuleRoleLink.Count > 0)
                     {
                         isSaveToCache = true;
                         foreach (YnWebModuleRoleLink ynWebModuleRoleLink in listYnWebModuleRoleLink)
                         {
                             ynWebRight.rightManage = ynWebModuleRoleLink.rightManage || ynWebRight.rightManage;
                             ynWebRight.rightAdd    = (ynWebRight.rightManage || ynWebModuleRoleLink.rightAdd) || ynWebRight.rightAdd;
                             ynWebRight.rightEdit   = (ynWebRight.rightManage || ynWebModuleRoleLink.rightEdit) || ynWebRight.rightEdit;
                             ynWebRight.rightDelete = (ynWebRight.rightManage || ynWebModuleRoleLink.rightDelete) || ynWebRight.rightDelete;
                             ynWebRight.rightVerify = (ynWebModuleRoleLink.rightVerify) || ynWebRight.rightVerify;//ynWebRight.rightManage ||
                         }
                     }
                 }
             }
             if (isSaveToCache)
             {
                 //SaveToCache(ynUser.userId, ynWebRight, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration);
                 SaveToCache(ynUser.userId + "_" + moduleId.ToString(), ynWebRight);
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
 }
示例#2
0
        public bool UserAuthentication(string userId, string userPwd, string hostIP, ref string message, ref string encryptTicket)
        {
            try
            {
                message = "";

                string         sql   = "from YnUser where userId='" + userId + "' or userName ='******'";
                IList <YnUser> ilist = YnDaoHelper.GetInstance().nHibernateHelper.Find <YnUser>(sql);
                if (ilist == null || ilist.Count() == 0)
                {
                    return(false);
                }
                YnFrame.Dal.Entities.YnUser ynUser = ilist[0];
                if (YnFrame.Services.YnUserService.GetInstance().ValidateUser(ynUser.userId, userPwd))
                {
                    //YnFrame.Dal.Entities.YnUser ynUser = YnFrame.Services.YnUserService.GetInstance().Get(userId);

                    string   sUserData = Newtonsoft.Json.JsonConvert.SerializeObject(ynUser.GetTicket());
                    bool     createPersistentCookie = false;
                    DateTime dt = createPersistentCookie ? DateTime.Now.AddMinutes(99999) : DateTime.Now.AddDays(365); //用一年看他还过不过期
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                        1,                                                                                             // 票据版本号
                        userId.ToString(),                                                                             // 票据持有者
                        DateTime.Now,                                                                                  //分配票据的时间
                        dt,                                                                                            // 失效时间
                        createPersistentCookie,                                                                        // 需要用户的 cookie
                        sUserData,                                                                                     // 用户数据,这里其实就是用户的角色
                        FormsAuthentication.FormsCookiePath);                                                          //cookie有效路径

                    //System.Web.Security.FormsAuthenticationTicket ticket = YnFrame.Web.FormsAuthenticationService.GetInstance().GetTicket(userId, 0, ynUser, false);
                    string     hash   = System.Web.Security.FormsAuthentication.Encrypt(ticket);
                    HttpCookie cookie = new HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, hash); //加密之后的cookie
                    if (ticket.IsPersistent)
                    {
                        cookie.Expires = ticket.Expiration;
                    }
                    encryptTicket = hash;
                    //添加cookie到页面请求响应中
                    HttpContext.Current.Response.Cookies.Add(cookie);


                    //写日志
                    ynUser.lastLoginIp   = hostIP;
                    ynUser.lastLoginDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    YnUserService.GetInstance().Update(ynUser);

                    return(true);
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(false);
        }
示例#3
0
        public List <YnWebAccMenuTree> GetYnWebAccMenuTreeList(YnUser ynUser)
        {
            try
            {
                List <YnWebAccMenuTree> listYnWebAccMenuTree = null;
                if (YnUserService.GetInstance().IsSuperAdministrator(ynUser.userId) || YnUserService.GetInstance().IsAdministrator(ynUser.userId))
                {
                    listYnWebAccMenuTree = YnWebAccMenuTreeService.GetInstance().GetList(string.Empty, string.Empty, string.Empty);
                }
                else
                {
                    listYnWebAccMenuTree = YnWebAccMenuTreeService.GetInstance().GetListByUser(ynUser);
                }
                return(listYnWebAccMenuTree);

                /*if(listYnWebAccMenuTree!=null){
                 *              //根据tree获取accmenu
                 *              List<YnWebAccMenu> listYnWebAccMenu = new List<YnWebAccMenu>();
                 *              foreach(YnWebAccMenuTree ynWebAccMenuTree in listYnWebAccMenuTree){
                 *                      if(ynWebAccMenuTree.getYnWebAccMenu()!=null){
                 *                              YnWebAccMenu ynWebAccMenu=null;
                 *                              for(YnWebAccMenu _ynWebAccMenu :listYnWebAccMenu){
                 *                                      if(ynWebAccMenuTree.getYnWebAccMenu().getId().equals(_ynWebAccMenu.getId())){
                 *                                              ynWebAccMenu=_ynWebAccMenu;
                 *                                              break;
                 *                                      }
                 *                              }
                 *                              if(ynWebAccMenu==null){
                 *                                      listYnWebAccMenu.add(ynWebAccMenuTree.getYnWebAccMenu());
                 *                              }
                 *                      }
                 *              }
                 *              GenerationMenu( listYnWebAccMenu, listYnWebAccMenuTree);*/
                /*//根据accmenu生成菜单
                 * for(YnWebAccMenu _ynWebAccMenu :listYnWebAccMenu){
                 *  if(ynWebAccMenuTree.getYnWebAccMenu().getId()==_ynWebAccMenu.getId()){
                 *      ynWebAccMenu=_ynWebAccMenu;
                 *      break;
                 *  }
                 * }*/
                //}
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(null);
        }
示例#4
0
 public void DeleteUser(string ticket, string userId, ref string message)
 {
     try
     {
         message = "";
         if (!IsTicketValid(ticket))
         {
             throw new Exception("票证验证失败!");
         }
         YnUserService.GetInstance().Delete(userId);
     }
     catch (Exception ex)
     {
         message = ex.Message;
     }
 }
示例#5
0
        public bool IsAdministrator(string ticket, string userId, ref string message)
        {
            try
            {
                message = "";
                if (!IsTicketValid(ticket))
                {
                    throw new Exception("票证验证失败!");
                }

                return(YnUserService.GetInstance().IsAdministrator(userId));
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(false);
        }
示例#6
0
        public string GetUserListNotInModuleFunction(string ticket, int functionId, string whereOther, ref string message)
        {
            try
            {
                message = "";
                if (!IsTicketValid(ticket))
                {
                    throw new Exception("票证验证失败!");
                }

                List <YnUser> listYnUser = YnUserService.GetInstance().GetListNotInModuleFunction(functionId, whereOther);
                return(YnBaseClass2.Helper.ObjectHelper.Serialize(listYnUser));
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(null);
        }
示例#7
0
        public bool UpdateUser(string ticket, string _ynUser, ref string message)
        {
            try
            {
                message = "";
                if (!IsTicketValid(ticket))
                {
                    throw new Exception("票证验证失败!");
                }

                YnUser ynUser = (YnUser)YnBaseClass2.Helper.ObjectHelper.Deserialize(typeof(YnUser), _ynUser);
                //ynUser.lastLoginDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                YnUserService.GetInstance().Update(ynUser);
                return(true);
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(false);
        }
示例#8
0
        public string GetUserList(string ticket, string _ynPage, string whereOther, ref string message)
        {
            try
            {
                message = "";
                if (!IsTicketValid(ticket))
                {
                    throw new Exception("票证验证失败!");
                }


                YnBaseDal.YnPage ynPage = (YnBaseDal.YnPage)YnBaseClass2.Helper.ObjectHelper.Deserialize(typeof(YnBaseDal.YnPage), _ynPage);

                List <YnUser> listYnUser = listYnUser = YnUserService.GetInstance().GetList("", ynPage, "", "", "", whereOther);
                return(YnBaseClass2.Helper.ObjectHelper.Serialize(listYnUser));
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return(null);
        }
示例#9
0
        public List <YnWebAccMenuTree> GetYnWebAccMenuTreeList_Old(string userId)
        {
            List <YnWebAccMenuTree> listYnWebAccMenuTree = null;

            if (!string.IsNullOrEmpty(userId))
            {
                if (YnUserService.GetInstance().IsSuperAdministrator(userId) || YnUserService.GetInstance().IsAdministrator(userId))
                {
                    try
                    {
                        listYnWebAccMenuTree = YnWebAccMenuTreeService.GetInstance().GetList(string.Empty, string.Empty, string.Empty);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                else
                {
                    #region 非管理员
                    List <int>         listModuleId          = null;
                    List <YnWebModule> listYnWebModuleByUser = GetYnWebModuleListByUser(userId);
                    if (listYnWebModuleByUser != null)
                    {
                        listModuleId = new List <int>();
                        foreach (YnWebModule ynWebModule in listYnWebModuleByUser)
                        {
                            listModuleId.Add(ynWebModule.id);
                        }
                    }
                    string             roleIds = GetRoleIds(userId);
                    List <YnWebModule> listYnWebModuleByRole = GetYnWebModuleListByRole(roleIds);
                    if (listYnWebModuleByRole != null)
                    {
                        listModuleId = listModuleId ?? new List <int>();
                        foreach (YnWebModule ynWebModule in listYnWebModuleByRole)
                        {
                            if (!listModuleId.Contains(ynWebModule.id))
                            {
                                listModuleId.Add(ynWebModule.id);
                            }
                        }
                    }
                    if (listModuleId != null && listModuleId.Count > 0)
                    {
                        string moduleIds = string.Empty;
                        foreach (int moduleId in listModuleId)
                        {
                            if (!string.IsNullOrEmpty(moduleIds))
                            {
                                moduleIds += ",";
                            }
                            moduleIds += moduleId.ToString();
                        }
                        try
                        {
                            listYnWebAccMenuTree = YnWebAccMenuTreeService.GetInstance().GetListByModule(moduleIds);
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    #endregion
                }
            }
            return(listYnWebAccMenuTree);
        }