Esempio n. 1
0
        /// <summary>
        /// 校验权限
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="controller">控制器</param>
        /// <param name="action">方法</param>
        /// <returns></returns>
        public MsgResult HasPermission(int userId, string controller, string action)
        {
            MsgResult result = new MsgResult();

            try
            {
                controller = controller.ToUpper();
                action     = action.ToUpper();
                var model = AdminUsersDal.GetModel(x => x.Id == userId).FirstOrDefault();
                if (model != null)
                {
                    List <T_SysOperations> list = new List <T_SysOperations>();
                    //foreach (var role in model.T_UserRoles)
                    //{
                    //    var tempList = SysOperationsDal.GetSysOperationListByRoleId(role.RoleId);
                    //    list.AddRange(tempList);
                    //}

                    var cache = CacheHelper.GetCache("SysOp" + model.Id) as List <T_SysOperations>;
                    if (cache == null || cache.Count <= 0)
                    {
                        foreach (var role in model.T_UserRoles)
                        {
                            var tempList = SysOperationsDal.GetSysOperationListByRoleId(role.RoleId);
                            if (tempList.Count > 0)
                            {
                                list.AddRange(tempList);
                            }
                        }
                        CacheHelper.SetCache("SysOp" + model.Id, list);
                    }
                    else
                    {
                        list = cache;
                    }

                    if (list.Any(x => x.ContronllerName.ToUpper() == controller & x.ActionName.ToUpper() == action))
                    {
                        result.IsSuccess = true;
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message   = "无权限访问当前方法";
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message   = "当前用户不存在";
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message   = ex.Message;
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 校验登陆
        /// </summary>
        /// <param name="userName">账户</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public MsgResult CheckLogin(string userName, string pwd)
        {
            MsgResult result = new MsgResult();

            try
            {
                var       model = AdminUsersDal.GetModel(x => x.Phone == userName).FirstOrDefault();
                AdminUser user  = Mapper.Map <AdminUser>(model);
                if (model != null)
                {
                    string pwdHush = EncryptHelper.GetMd5(pwd.Trim() + model.Salt);
                    if (string.Equals(pwdHush, model.PwdHush))
                    {
                        result.IsSuccess = true;
                        result.Message   = "登陆成功";
                        result.Data      = JsonConvert.SerializeObject(user);
                    }
                    else
                    {
                        result.IsSuccess = false;
                        result.Message   = "用户名或者密码错误";
                    }
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message   = "用户名或者密码错误";
                }
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message   = "系统异常:" + ex.Message;
            }

            return(result);
        }