Beispiel #1
0
        public async Task <IActionResult> Index(string mensaje)
        {
            try
            {
                var ListaAdscgrp = await apiServicio.Listar <Adscmenu>(new Uri(WebApp.BaseAddress), "api/Adscmenus/ListarMenu");

                if (mensaje == null)
                {
                    mensaje = "";
                }
                ViewData["Error"] = mensaje;
                return(View(ListaAdscgrp));
            }
            catch (Exception ex)
            {
                var responseLog = new EntradaLog
                {
                    ExceptionTrace       = ex.Message,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    ObjectPrevious       = null,
                    ObjectNext           = null,
                };
                await apiServicio.SalvarLog <entidades.Utils.Response>(HttpContext, responseLog);

                return(BadRequest());
            }
        }
        public async Task <IActionResult> CambiarContrasena(CambiarContrasenaViewModel cambiarContrasenaViewModel)
        {
            try
            {
                if (string.IsNullOrEmpty(cambiarContrasenaViewModel.ConfirmacionContrasena) || string.IsNullOrEmpty(cambiarContrasenaViewModel.ContrasenaActual) || string.IsNullOrEmpty(cambiarContrasenaViewModel.NuevaContrasena))
                {
                    ModelState.AddModelError("", "Debe introducir todos los datos por favor...");
                    return(View());
                }

                if (cambiarContrasenaViewModel.NuevaContrasena != cambiarContrasenaViewModel.ConfirmacionContrasena)
                {
                    ModelState.AddModelError("", "La contraseña nueva no coincide con la confirmación");
                    return(View());
                }

                var claim         = HttpContext.User.Identities.Where(x => x.NameClaimType == ClaimTypes.Name).FirstOrDefault();
                var token         = claim.Claims.Where(c => c.Type == ClaimTypes.SerialNumber).FirstOrDefault().Value;
                var NombreUsuario = claim.Claims.Where(c => c.Type == ClaimTypes.Name).FirstOrDefault().Value;


                Response response = new entidades.Utils.Response();

                cambiarContrasenaViewModel.Usuario = NombreUsuario;
                response = await apiServicio.ObtenerElementoAsync1 <Response>(cambiarContrasenaViewModel,
                                                                              new Uri(WebApp.BaseAddressSeguridad),
                                                                              "api/Adscpassws/CambiarContrasenaUsuariosExternos");

                if (response.IsSuccess)
                {
                    var responseLog = new EntradaLog
                    {
                        ExceptionTrace       = null,
                        LogCategoryParametre = Convert.ToString(LogCategoryParameter.Permission),
                        LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                        ObjectPrevious       = null,
                        ObjectNext           = JsonConvert.SerializeObject(response.Resultado),
                    };
                    await apiServicio.SalvarLog <entidades.Utils.Response>(HttpContext, responseLog);

                    return(RedirectToActionPermanent("Menu", "Homes"));
                }
                ModelState.AddModelError("", response.Message);
                return(View());
            }
            catch (Exception ex)
            {
                var responseLog = new EntradaLog
                {
                    ExceptionTrace       = ex.Message,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    ObjectPrevious       = null,
                    ObjectNext           = null,
                };
                await apiServicio.SalvarLog <entidades.Utils.Response>(HttpContext, responseLog);

                return(BadRequest());
            }
        }
        public async Task <IActionResult> Create(Adscbdd baseDato)
        {
            try
            {
                var response = new entidades.Utils.Response();
                if (ModelState.IsValid)
                {
                    response = await apiServicio.InsertarAsync(baseDato,
                                                               new Uri(WebApp.BaseAddress),
                                                               "api/BasesDatos/InsertarBaseDatos");

                    if (response.IsSuccess)
                    {
                        try
                        {
                            var responseLog = new EntradaLog
                            {
                                ExceptionTrace       = null,
                                LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create),
                                LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                                ObjectPrevious       = null,
                                ObjectNext           = JsonConvert.SerializeObject(response.Resultado),
                            };
                            await apiServicio.SalvarLog <entidades.Utils.Response>(HttpContext, responseLog);
                        }
                        catch (Exception)
                        {
                            return(RedirectToAction("Index"));

                            throw;
                        }

                        return(RedirectToAction("Index"));
                    }
                }
                InicializarMensaje(response.Message);
                return(View(baseDato));
            }
            catch (Exception ex)
            {
                var responseLog = new EntradaLog
                {
                    ExceptionTrace       = ex.Message,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    ObjectPrevious       = null,
                    ObjectNext           = null,
                };
                await apiServicio.SalvarLog <entidades.Utils.Response>(HttpContext, responseLog);

                return(BadRequest());
            }
        }
        public async Task <IActionResult> Create(Adscpassw adscpassw)
        {
            Response response = new Response();

            try
            {
                var claim         = HttpContext.User.Identities.Where(x => x.NameClaimType == ClaimTypes.Name).FirstOrDefault();
                var NombreUsuario = claim.Claims.Where(c => c.Type == ClaimTypes.Name).FirstOrDefault().Value;

                adscpassw.AdpsLoginAdm = NombreUsuario.ToUpper();
                response = await apiServicio.InsertarAsync(adscpassw,
                                                           new Uri(WebApp.BaseAddress),
                                                           "/api/Adscpassws/InsertarAdscPassw");

                if (response.IsSuccess)
                {
                    var responseLog = new EntradaLog
                    {
                        ExceptionTrace       = null,
                        LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create),
                        LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                        ObjectPrevious       = null,
                        ObjectNext           = JsonConvert.SerializeObject(response.Resultado),
                    };
                    await apiServicio.SalvarLog <entidades.Utils.Response>(HttpContext, responseLog);


                    return(RedirectToAction("Index"));
                }

                ViewData["Error"] = response.Message;
                return(View(adscpassw));
            }
            catch (Exception ex)
            {
                var responseLog = new EntradaLog
                {
                    ExceptionTrace       = ex.Message,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    ObjectPrevious       = null,
                    ObjectNext           = null,
                };
                await apiServicio.SalvarLog <entidades.Utils.Response>(HttpContext, responseLog);

                return(BadRequest());
            }
        }
        private async void UsuarioBloqueado(Response response, Login login)
        {
            if (!string.IsNullOrEmpty(response.Resultado.ToString()))
            {
                var estaBloquado = JsonConvert.DeserializeObject <UsuarioBloqueado>(response.Resultado.ToString());
                if (estaBloquado.EstaBloqueado)
                {
                    var responseLog = new EntradaLog
                    {
                        ExceptionTrace       = null,
                        LogCategoryParametre = Convert.ToString(LogCategoryParameter.Permission),
                        LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                        ObjectPrevious       = null,
                        ObjectNext           = null,
                    };

                    await apiServicio.SalvarLog <entidades.Utils.Response>("/Login/UsuarioBloqueado", HttpContext, responseLog, login);
                }
                ;
            }
            ;
        }
        /// <summary>
        /// Método que es invocado desde la aplicaciín de Login
        /// Donde se valida el token temporal que el generado por la aplicación de Login para el usuario actual
        /// Si el token temporal es válido se elimina sino lo enviá a la aplicación de Login
        /// Si todo es satisfactorio se autentica a la cookie...
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> Login()

        {
            try
            {
                var claim         = HttpContext.User.Identities.Where(x => x.NameClaimType == ClaimTypes.Name).FirstOrDefault();
                var token         = claim.Claims.Where(c => c.Type == ClaimTypes.SerialNumber).FirstOrDefault().Value;
                var NombreUsuario = claim.Claims.Where(c => c.Type == ClaimTypes.Name).FirstOrDefault().Value;

                var permiso = new PermisoUsuario
                {
                    Contexto = HttpContext.Request.Path,
                    Token    = token,
                    Usuario  = NombreUsuario,
                };

                /// <summary>
                /// Se valida que la información del usuario actual tenga permiso para acceder al path solicitado...
                /// </summary>
                /// <returns></returns>
                var respuesta = apiServicio.ObtenerElementoAsync1 <Response>(permiso, new Uri(WebApp.BaseAddress), "api/Adscpassws/TienePermiso");

                if (!respuesta.Result.IsSuccess)
                {
                    return(Redirect(WebApp.BaseAddressWebAppLogin));
                }

                if (Request.Query.Count != 2)
                {
                    return(Redirect(WebApp.BaseAddressWebAppLogin));
                }

                Adscpassw adscpassw    = new Adscpassw();
                var       queryStrings = Request.Query;
                var       qsList       = new List <string>();
                foreach (var key in queryStrings.Keys)
                {
                    qsList.Add(queryStrings[key]);
                }
                var adscpasswSend = new Adscpassw
                {
                    AdpsLogin     = qsList[0],
                    AdpsTokenTemp = qsList[1]
                };
                adscpassw = await GetAdscPassws(adscpasswSend);

                if (adscpassw != null)
                {
                    var response = await EliminarTokenTemp(adscpassw);

                    if (response.IsSuccess)
                    {
                        var responseLog = new EntradaLog
                        {
                            ExceptionTrace       = null,
                            LogCategoryParametre = Convert.ToString(LogCategoryParameter.Permission),
                            LogLevelShortName    = Convert.ToString(LogLevelParameter.INFO),
                            ObjectPrevious       = null,
                            ObjectNext           = JsonConvert.SerializeObject(response.Resultado),
                        };
                        await apiServicio.SalvarLog <entidades.Utils.Response>(HttpContext, responseLog);

                        return(RedirectToActionPermanent(nameof(HomeController.Index), "Home"));
                    }
                    else
                    {
                        return(Redirect(WebApp.BaseAddressWebAppLogin));
                    }
                }

                return(Redirect(WebApp.BaseAddressWebAppLogin));
            }
            catch (Exception ex)
            {
                var responseLog = new EntradaLog
                {
                    ExceptionTrace       = ex.Message,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    ObjectPrevious       = null,
                    ObjectNext           = null,
                };
                await apiServicio.SalvarLog <entidades.Utils.Response>(HttpContext, responseLog);

                return(Redirect(WebApp.BaseAddressWebAppLogin));
            }
        }
Beispiel #7
0
        public async Task <IActionResult> Login()
        {
            try
            {
                if (Request.Query.Count != 2)
                {
                    return(Redirect(WebApp.BaseAddressWebAppLogin));
                }

                Adscpassw adscpassw    = new Adscpassw();
                var       queryStrings = Request.Query;
                var       qsList       = new List <string>();
                foreach (var key in queryStrings.Keys)
                {
                    qsList.Add(queryStrings[key]);
                }
                var adscpasswSend = new Adscpassw
                {
                    AdpsLogin     = qsList[0],
                    AdpsTokenTemp = qsList[1]
                };
                adscpassw = await GetAdscPassws(adscpasswSend);

                if (adscpassw != null)
                {
                    var response = await EliminarTokenTemp(adscpassw);

                    if (response.IsSuccess)
                    {
                        var responseLog = new EntradaLog
                        {
                            ExceptionTrace       = null,
                            LogCategoryParametre = Convert.ToString(LogCategoryParameter.Permission),
                            LogLevelShortName    = Convert.ToString(LogLevelParameter.INFO),
                            ObjectPrevious       = null,
                            ObjectNext           = JsonConvert.SerializeObject(response.Resultado),
                        };
                        await apiServicio.SalvarLog <entidades.Utils.Response>(HttpContext, responseLog);

                        return(RedirectToActionPermanent(nameof(HomesController.Index), "Homes"));
                    }
                    else
                    {
                        return(Redirect(WebApp.BaseAddressWebAppLogin));
                    }
                }
                return(Redirect(WebApp.BaseAddressWebAppLogin));
            }
            catch (Exception ex)
            {
                var responseLog = new EntradaLog
                {
                    ExceptionTrace       = ex.Message,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    ObjectPrevious       = null,
                    ObjectNext           = null,
                };
                await apiServicio.SalvarLog <entidades.Utils.Response>(HttpContext, responseLog);

                return(Redirect(WebApp.BaseAddressWebAppLogin));
            }
        }