Пример #1
0
        /// <summary>
        /// Saas后台管理登录
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <(string Error, User User)> SaasLoginAsync(string account, string password, string ip = "")
        {
            User user = await UserRep.FindSingleAsync(o => o.Account == account);

            if (user == null)
            {
                return($"帐号不存在", null);
            }
            if (user.State == 0)
            {
                return($"帐号禁止登录", null);
            }
            if (user.Password != password)
            {
                return($"密码不正确", null);
            }
            CurrentUser curUser = new CurrentUser
            {
                Id             = user.Id,
                RealName       = user.Account,
                LoginIPAddress = ip
            };
            await OperateLogApp.CustomLogAsync(curUser, "用户登录", user.RealName + "进行了登录操作");

            await UserRep.UpdateAsync(o => o.Id == user.Id, o => new User()
            {
                LastLoginTime = DateTime.Now
            });

            return(string.Empty, user);
        }
Пример #2
0
        /// <summary>
        /// 添加管理人员
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <R> InsertAsync(User entity, CurrentUser curUser)
        {
            entity.Id            = entity.CreateId();
            entity.UserSecretkey = "";
            entity.CreatorTime   = DateTime.Now;
            entity.CreatorUserId = curUser.Id;
            var r = await InsertAsync(entity);

            if (!string.IsNullOrEmpty(r.Error))
            {
                return(R.Err(msg: r.Error));
            }
            await OperateLogApp.InsertLogAsync <User>(curUser, "添加用户", entity);

            return(R.Suc());
        }
Пример #3
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public async Task <(bool s, string msg)> DeleteAsync(long Id, CurrentUser currentUser)
        {
            var entity = await RoleRep.FindSingleAsync(o => o.Id == Id);

            if (entity == null)
            {
                return(false, "数据不存在");
            }
            await RoleRep.DeleteAsync(o => o.Id == Id);

            if (currentUser != null)
            {
                await OperateLogApp.RemoveLogAsync <Role>(currentUser, "删除角色", entity);
            }
            await RemoveCacheAsync(Id);

            return(true, "操作成功");
        }
Пример #4
0
 /// <summary>
 /// 用户退出操作
 /// </summary>
 /// <param name="curUser">登录用户信息</param>
 /// <returns></returns>
 public async Task LogOffAsync(CurrentUser curUser)
 {
     await OperateLogApp.CustomLogAsync(curUser, "用户退出", curUser.RealName + "进行了退出操作");
 }
Пример #5
0
        /// <summary>
        /// 角色添加
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public async Task <R> CreateAsync(Role entity, List <long> permissionIds, CurrentUser currentUser)
        {
            entity.Id          = entity.CreateId();
            entity.CreatorTime = DateTime.Now;
            var moduledata = await ModuleApp.GetSaasModuleListAsync();

            var buttondata = await ModuleButtonApp.GetSaasModuleListAsync();

            List <long> allpermissionIds = new List <long>();

            foreach (long id in permissionIds)
            {
                allpermissionIds.Add(id);
                if (moduledata.Count(o => o.Id == id) > 0)
                {
                    var md = moduledata.Where(o => o.Id == id).FirstOrDefault();
                    if (md.ParentId != 0)
                    {
                        allpermissionIds.AddRange(await Fibonacci(md.ParentId));
                    }
                }
                else if (buttondata.Count(o => o.Id == id) > 0)
                {
                    var md = buttondata.Where(o => o.Id == id).FirstOrDefault();
                    if (md.ModuleId != 0)
                    {
                        allpermissionIds.AddRange(await Fibonacci(md.ModuleId));
                    }
                }
            }
            allpermissionIds = allpermissionIds.Distinct().ToList();
            List <RoleAuthorize> ras = new List <RoleAuthorize>();

            foreach (long id in allpermissionIds)// permissionIds
            {
                int itemType = 0;
                if (moduledata.Count(o => o.Id == id) > 0)
                {
                    itemType = 1;
                }
                else if (buttondata.Count(o => o.Id == id) > 0)
                {
                    itemType = 2;
                }
                if (itemType > 0)
                {
                    RoleAuthorize ra = new RoleAuthorize
                    {
                        ObjectId    = entity.Id,
                        ObjectType  = 1,
                        ItemId      = id,
                        ItemType    = itemType,
                        CreatorTime = DateTime.Now
                    };
                    ra.Id = ra.CreateId();
                    ras.Add(ra);
                }
            }

            UnitWork.Add <Role>(entity);
            UnitWork.BatchAdd <RoleAuthorize>(ras.ToArray());
            UnitWork.Save();


            if (currentUser != null)
            {
                await OperateLogApp.InsertLogAsync <Role>(currentUser, "添加角色", entity);
            }
            return(R.Suc(entity));
        }