Esempio n. 1
0
        public ActionResult SubirArchivo(HttpPostedFileBase file, string persona)
        {
            try
            {
                string token        = HttpContext.Request.Cookies["userID"].Value;
                int    cifradoValue = Int16.Parse(HttpContext.Request.Cookies["cifrado"].Value);

                //Subir archivo al servidor
                string path = Path.Combine(Directories.directorioUploads, Path.GetFileName(file.FileName) ?? "");
                UploadFile(path, file);

                //Comprimir
                string rutaComprimido = LZW.comprimirArchivo(path, Directories.directorioTemporal);

                //Cifrar
                SDES   cipher      = new SDES();
                string rutaCifrado = cipher.CifrarArchivo(rutaComprimido, Directories.directorioArchivos, cifradoValue);

                //Pasar ruta como parametro
                string rutaAmigable = rutaCifrado.Replace("/", "~");
                rutaAmigable = rutaAmigable.Replace(@"\", "~");

                string mensaje = $"<a href=\"/Chat/Descargar?path={rutaAmigable}\" onclick=\"clickAndDisable(this);\">{file.FileName}</a>";

                MensajeModelo nuevo = new MensajeModelo();
                nuevo.mensaje   = cipher.CifrarTexto(mensaje, cifradoValue);
                nuevo.receptor  = persona;
                nuevo.receptor  = nuevo.receptor.Replace(" ", "");
                nuevo.esArchivo = true;

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("https://localhost:44316/api/chat");
                    client.DefaultRequestHeaders.Authorization =
                        new AuthenticationHeaderValue("Bearer", token);

                    var postJob = client.PostAsJsonAsync <MensajeModelo>("chat", nuevo);
                    postJob.Wait();

                    var postResult = postJob.Result;
                    if (postResult.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        return(RedirectToAction("Login", "Login"));
                    }
                }

                return(RedirectToAction("Index", "Chat"));
            }
            catch (Exception e)
            {
                return(RedirectToAction("Login", "Login"));
            }
        }
Esempio n. 2
0
        public ActionResult <Chat> NewMessage(MensajeModelo received)
        {
            var claimsIdentity = User.Identity as ClaimsIdentity;

            string emisor = claimsIdentity.Name;
            string id     = emisor + received.receptor;
            string id2    = received.receptor + emisor;

            try
            {
                //Post en el chat de ambas personas
                _ChatService.Post(new Message(id, false, received.mensaje, received.esArchivo, ""));
                _ChatService.Post(new Message(id2, true, received.mensaje, received.esArchivo, ""));
                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
Esempio n. 3
0
        public ActionResult Index(string persona, string mensaje)
        {
            try
            {
                string token        = HttpContext.Request.Cookies["userID"].Value;
                int    cifradoValue = Int16.Parse(HttpContext.Request.Cookies["cifrado"].Value);

                SDES   cipher         = new SDES();
                string mensajeCifrado = cipher.CifrarTexto(mensaje, cifradoValue);

                MensajeModelo nuevo = new MensajeModelo();
                nuevo.mensaje   = mensajeCifrado;
                nuevo.receptor  = persona;
                nuevo.receptor  = nuevo.receptor.Replace(" ", "");
                nuevo.esArchivo = false;

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("https://localhost:44316/api/chat");
                    client.DefaultRequestHeaders.Authorization =
                        new AuthenticationHeaderValue("Bearer", token);

                    var postJob = client.PostAsJsonAsync <MensajeModelo>("chat", nuevo);
                    postJob.Wait();

                    var postResult = postJob.Result;
                    if (postResult.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        return(RedirectToAction("Login", "Login"));
                    }
                }
            }
            catch (Exception e)
            {
                return(RedirectToAction("Login", "Login"));
            }
        }