Пример #1
0
        public IdentityResult CreateAdminUser(User user, string password, List <string> roles)
        {
            //不是最佳做法,没有事务回滚
            user.UserType = UserType.Admin;
            var result = _userManager.Create(user, password);

            if (result.Succeeded)
            {
                if (roles == null)
                {
                    roles = new List <string>();
                }

                roles.Add("admin");
                foreach (var roleName in roles)
                {
                    result = _userManager.AddToRole(user.Id, roleName);
                    if (!result.Succeeded)
                    {
                        break;
                    }
                }

                Logger.Operation($"添加后台用户-{user.UserName}:{user.Id}", SystemUsersModule.Instance, SecurityLevel.Warning);
                //更新缓存
                _signals.Trigger(_userContainer.UserChangedSignalName);
            }

            return(result);
        }
Пример #2
0
        private void InitializeAuthentication()
        {
            var auth = new ApplicationAuthentication();

            var context = new ICIdentityDbContext(ConnectionFactory.Create(ConnectionFactory.GetConnectionString(typeof(ICIdentityDbContext).Name)));

            auth.AddProviders(new AspNetIdentityAuthenticationProvider(DefaultUserManager.Create(new UserStore <IdentityUser>(context))));

            GlobalContainer.AddInstance(auth);
        }
Пример #3
0
        public IdentityResult CreateMember(Member member, string password)
        {
            //不是最佳做法,没有事务回滚
            member.UserType     = UserType.Member;
            member.DynamicToken = KeyGenerator.GetGuidKey().ToString();
            var user   = member.GetUser();
            var result = _userManager.Create(user, password);

            if (result.Succeeded)
            {
                member.Id = user.Id;
                //插入扩展数据
                _currencyService.Create(member.GetMemberExtension());

                result = _userManager.AddToRole(member.Id, "member");
                Logger.Operation($"添加会员-{member.UserName}:{member.Id}", MemberBaseModule.Instance, SecurityLevel.Warning);
                //更新缓存
                _signals.Trigger(_userContainer.UserChangedSignalName);
                _signals.Trigger($"member_{member.Id}_changed");
            }

            return(result);
        }