Exemple #1
0
        public UserDto CheckUser(string userName, string password)
        {
            _logger.LogInformation("CheckUser: username:{0}", userName);
            if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(password))
            {
                return(null);
            }

            //get from indexs,get radom id to get url for balanced solrcloud
            var readindex  = _indexReadFactory.CreateIndex <UserIndexs, IUserIndexsIndexRead>(Guid.NewGuid().ToString(), "authcore1");
            var userindexs = readindex.FirstOrDefault(new List <KeyValuePair <string, string> >(2)
            {
                new KeyValuePair <string, string>("name", userName), new KeyValuePair <string, string>("keywords", password)
            });
            UserIndex userindex = null;

            if (userindexs == null)
            {
                userindex = _userrepositoryread.CheckUserIndex(userName, password);
                if (userindex != null)//write to indexs
                {
                    var writeuserindexs = Mapper.Map <UserIndexs>(userindex);
                    var writeindex      = _indexFactory.CreateIndex <UserIndexs, IUserIndexsIndex>(writeuserindexs.Id.ToString(), "authcore1");
                    writeindex.Insert(writeuserindexs);
                }
            }
            else
            {
                userindex = Mapper.Map <UserIndex>(userindexs);
            }

            var user = _repositoryReadFactory.CreateRepository <User, IUserRepositoryRead>(userindex.UserId.ToString()).CheckUser(userName, password);//

            return(Mapper.Map <UserDto>(user));
        }
        private void UpdateUserRole(user_update_userroles_normal msg)
        {
            UserRoleMsg bodys = ByteConvertHelper.Bytes2Object <UserRoleMsg>(msg.MessageBodyByte);

            if (bodys == null)
            {
                return;
            }
            List <UserRole>           userRoles    = new List <UserRole>();
            Dictionary <Guid, string> userRoleStrs = new Dictionary <Guid, string>(bodys.userIds.Count);

            bodys.userIds.ForEach(uid => {
                StringBuilder roleStrs = new StringBuilder();
                bodys?.roleIds.ForEach(rid => { userRoles.Add(new UserRole()
                    {
                        UserId = uid, RoleId = rid
                    }); roleStrs.Append(rid).Append(","); });
                roleStrs.Remove(roleStrs.Length - 1, 1);
                userRoleStrs.Add(uid, roleStrs.ToString());
            });

            lock (normalLocker)
            {
                bodys.userIds.ForEach(id => {
                    var up = _repository.CreateRepository <User, IUserRepository>(id.ToString());
                    up.Execute(() =>
                    {
                        //get from indexs
                        var readindex = _indexReadFactory.CreateIndex <UserIndexs, IUserIndexsIndexRead>(id.ToString(), "authcore1");
                        var userindex = readindex.FirstOrDefault(new List <KeyValuePair <string, string> >(1)
                        {
                            new KeyValuePair <string, string>("id", id.ToString())
                        });
                        if (userindex != null)
                        {
                            userindex.roles = userRoleStrs[id];
                            //update indexs
                            var objindex = _indexFactory.CreateIndex <UserIndexs, IUserIndexsIndex>(id.ToString(), "authcore1");
                            objindex.Insert(userindex);
                        }

                        // Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction
                        up.RemoveUserRoles(id);
                        up.UnitOfWork.SaveChange();
                        up.BatchAddUserRoles(userRoles);
                        up.UnitOfWork.SaveChange();
                    });
                });
            }
        }