Example #1
0
 public IActionResult RemoveCookie([FromBody] RemoveCookie removeCookie)
 {
     if (removeCookie.Name == null || removeCookie.Name == "")
     {
         foreach (var Cookie in Request.Cookies.Keys)
         {
             Response.Cookies.Delete(Cookie);
         }
     }
     else
     {
         Response.Cookies.Delete(removeCookie.Name);
     }
     return(Ok());
 }
        public async Task <IActionResult> RemoveCookie(RemoveCookie removeCookie)
        {
            var dic = _cacheService.Get <Dictionary <string, NewCookie> >(removeCookie.ClientId.ToString());

            if (dic == null)
            {
                return(BadRequest($"Нет кука {removeCookie.Name} для удаления"));
            }

            if (dic.ContainsKey(removeCookie.Name))
            {
                dic[removeCookie.Name] = null;
                _cacheService.Set(removeCookie.ClientId.ToString(), dic);
            }

            var emailClaim = User.Claims.Where(t => t.Type == ClaimsIdentity.DefaultNameClaimType).Single();
            var user       = await _userRepo.GetAsync(emailClaim.Value);

            // TODO: Раздаем всем куки кто подключен по сокету
            var channels = await _clientRepo.GetChannelsAsync(removeCookie.ClientId);

            var userIds = channels.Select(t => t.UserId);
            var users   = await _userRepo.GetByUserIdsAsync(userIds);

            var emails = users.Where(t => t.Email != user.Email).Select(t => t.Email);
            //var connection = _connectionMapping.GetConnections(user.Email);
            // получаем список всех пользователей текущего client и кроме текущего пользователя
            var connectionIds = _connectionMapping.GetConnectionsByKeys(emails);
            // TODO: а вот и ошибка - отправить всем кроме себя, а нужно отправить только своей подгруппе
            await _cookieHub.Clients.Clients(connectionIds.ToList()).SendAsync("RemoveCookie", new
            {
                name = removeCookie.Name,
                url  = removeCookie.Url
            });

            return(Ok("OK"));
        }