Beispiel #1
0
        public async Task UpdateManagerAsync(CreateOrUpdateManagerInputDto input)
        {
            //获取管理员信息
            var manager = await _managerManage.GetManagerByIdAsync(input.Id, new List <string> {
                "UserBase.Roles", "UserBase.UserClaims"
            });

            //不能修改登录用户名,密码
            input.UserBase.PasswordHash = manager.UserBase.PasswordHash;
            input.UserBase.UserName     = manager.UserBase.UserName;

            //不是超级管理员不能进行主帐号修改操作
            if (manager.UserBase.UserClaims.Any(x => x.ClaimValue == AccountTypeEnum.主帐号.ToString()) && AprilSession.AccountType != AccountTypeEnum.超级管理员)
            {
                throw new UserFriendlyException("运营主帐号不能进行修改操作");
            }

            //自动转换一下用户基础表
            input.UserBase.MapTo(manager.UserBase);

            //用户角色
            var roles = await _roleManage.GetRoleListByIdsAsync(input.RoleIds);

            manager.UserBase.Roles?.Clear();

            manager.UserBase.Roles = roles;

            await _managerManage.UpdateManagerAsync(manager);
        }
Beispiel #2
0
        public async Task InsertManagerAsync(CreateOrUpdateManagerInputDto input)
        {
            if (string.IsNullOrEmpty(input.UserBase.PasswordHash))
            {
                throw new UserFriendlyException("密码不能为为空!");
            }

            //自动转换一下用户基础表
            var userBase = input.UserBase.MapTo <UserBase>();

            userBase.PasswordHash           = new PasswordHasher().HashPassword(userBase.PasswordHash);
            userBase.SecurityStamp          = Guid.NewGuid().ToString();
            userBase.IsEmailComfirmed       = true;
            userBase.IsLockoutEnaled        = false;
            userBase.IsPhoneNumberComfirmed = true;
            userBase.AccessFailedCount      = 0;

            //用户角色
            var roles = await _roleManage.GetRoleListByIdsAsync(input.RoleIds);

            userBase.Roles = roles;

            //获取当前帐号类型
            var currentAccountType = (AccountTypeEnum)Convert.ToInt32(ClaimTypeExtensions.GetClaimValue(ClaimTypeExtensions.AccountType));

            //需要赋予的帐号类型
            var accountType = AccountTypeEnum.子帐号;

            if (currentAccountType == AccountTypeEnum.超级管理员)
            {
                accountType = AccountTypeEnum.主帐号;
            }

            //用户申明
            userBase.UserClaims = new List <UserClaim> {
                new UserClaim {
                    ClaimType  = "AccountType",
                    ClaimValue = Convert.ToInt32(accountType).ToString()
                }
            };

            //实例化管理员
            userBase.Managers = new List <Manager>
            {
                new Manager()
            };


            var userId = await _userBaseManage.CreateUserBaseAndGetIdAsync(userBase);

            //如果管理员创建主帐号则将所属Id设置成当前自己的Id
            userBase.BelongUserId = currentAccountType == AccountTypeEnum.超级管理员 ? userId : AprilSession.BelongUserId;
            await _userBaseManage.UpdateUserBaseAsync(userBase);
        }
Beispiel #3
0
 public async Task CreateOrUpdateManager(CreateOrUpdateManagerInputDto input)
 {
     if (input.Id > 0)
     {
         await UpdateManagerAsync(input);
     }
     else
     {
         await InsertManagerAsync(input);
     }
 }
 public async Task UpdateManagerAsync(CreateOrUpdateManagerInputDto input)
 {
     await _managerAppService.UpdateManagerAsync(input);
 }