示例#1
0
        public async Task <Adscpassw> GetAdscPassws(Adscpassw adscpassw)
        {
            try
            {
                if (!adscpassw.Equals(null))
                {
                    var respuesta = await apiServicio.ObtenerElementoAsync1 <Response>(adscpassw, new Uri(WebApp.BaseAddressSeguridad),
                                                                                       "api/Adscpassws/SeleccionarMiembroLogueado");



                    if (respuesta.IsSuccess)
                    {
                        var obje = JsonConvert.DeserializeObject <Adscpassw>(respuesta.Resultado.ToString());
                        return(obje);
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        private async Task <Response> AutenticarBDD(Adscpassw usuario, Login login)
        {
            var salida = CodificarHelper.SHA512(new Codificar {
                Entrada = login.Contrasena
            }).Salida;
            var existeLogin = db.Adscpassw.Where(x => x.AdpsLogin.ToUpper() == login.Usuario.ToUpper() && x.AdpsPasswPoint == salida).FirstOrDefault();

            if (existeLogin == null)
            {
                usuario.AdpsIntentos    = usuario.AdpsIntentos + 1;
                db.Entry(usuario).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.UsuariooContrasenaIncorrecto,
                    Resultado = "",
                });
            }

            usuario.AdpsIntentos    = 0;
            db.Entry(usuario).State = EntityState.Modified;
            return(new Response
            {
                IsSuccess = true,
                Message = "Ok",
                Resultado = existeLogin,
            });
        }
示例#3
0
        private async Task <entidades.Utils.Response> EliminarToken(Adscpassw adscpassw)
        {
            entidades.Utils.Response response = new entidades.Utils.Response();
            try
            {
                if (!string.IsNullOrEmpty(adscpassw.AdpsLogin))
                {
                    response = await apiServicio.EditarAsync <entidades.Utils.Response>(adscpassw, new Uri(WebApp.BaseAddressSeguridad), "api/Adscpassws/EliminarToken");

                    if (response.IsSuccess)
                    {
                        await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppRM), EntityID = string.Format("{0} : {1}", "Sistema", adscpassw.AdpsLogin), LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit), LogLevelShortName = Convert.ToString(LogLevelParameter.ADV), Message = "Se ha actualizado un estado civil", UserName = "******" });

                        return(response);
                    }
                }
                return(null);
            }
            catch (Exception)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer { ApplicationName = Convert.ToString(Aplicacion.WebAppRM), Message = "Editando un estado civil", LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit), LogLevelShortName = Convert.ToString(LogLevelParameter.ERR), UserName = "******" });

                return(null);
            }
        }
示例#4
0
        public async Task <Response> PostAdscpassw([FromBody] Adscpassw adscpassw)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.ModeloInvalido
                    });
                }

                var respuesta = Existe(adscpassw);
                if (!respuesta.IsSuccess)
                {
                    adscpassw.AdpsFechaCambio           = DateTime.Now;
                    adscpassw.AdpsFechaVencimiento      = DateTime.Now.AddMonths(3);
                    adscpassw.AdpsIntentos              = 0;
                    adscpassw.AdpsPasswCg               = adscpassw.AdpsLogin;
                    adscpassw.AdpsPreguntaRecuperacion  = Mensaje.UsuarioSinConfirmar;
                    adscpassw.AdpsRespuestaRecuperacion = Mensaje.UsuarioSinConfirmar;
                    adscpassw.AdpsPassword              = Codificar.SHA512(adscpassw.AdpsLogin);
                    db.Adscpassw.Add(adscpassw);
                    await db.SaveChangesAsync();

                    return(new Response
                    {
                        IsSuccess = true,
                        Message = Mensaje.Satisfactorio
                    });
                }

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.ExisteRegistro
                });
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.SwSeguridad),
                    ExceptionTrace       = ex,
                    Message              = Mensaje.Excepcion,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "",
                });

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Error,
                });
            }
        }
        public async Task <Response> GetAdscPassws([FromBody] Adscpassw adscpassw)
        {
            //try
            //{
            //    if (!ModelState.IsValid)
            //    {
            //        return new Response
            //        {
            //            IsSuccess = false,
            //            Message = Mensaje.ModeloInvalido,
            //        };
            //    }

            var adscgrpSeleccionado = await db.Adscpassw.Where(m => m.AdpsLogin.ToUpper() == adscpassw.AdpsLogin.ToUpper() && m.AdpsTokenTemp == adscpassw.AdpsTokenTemp).FirstOrDefaultAsync();

            return(new Response {
                IsSuccess = true, Resultado = adscgrpSeleccionado
            });
            //    if (adscgrpSeleccionado == null)
            //    {
            //        return new Response
            //        {
            //            IsSuccess = false,
            //            Message = Mensaje.RegistroNoEncontrado,
            //        };
            //    }

            //    return new Response
            //    {
            //        IsSuccess = true,
            //        Message = Mensaje.Satisfactorio,
            //        Resultado = adscgrpSeleccionado,
            //    };
            //}
            //catch (Exception ex)
            //{
            //    await GuardarLogService.SaveLogEntry(new LogEntryTranfer
            //    {
            //        ApplicationName = Convert.ToString(Aplicacion.SwSeguridad),
            //        ExceptionTrace = ex,
            //        Message = Mensaje.Excepcion,
            //        LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
            //        LogLevelShortName = Convert.ToString(LogLevelParameter.ERR),
            //        UserName = "",

            //    });
            //    return new Response
            //    {
            //        IsSuccess = false,
            //        Message = Mensaje.Error,
            //    };
            //}
        }
 private Response ValidarFechaCaducidad(Adscpassw usuario)
 {
     if (usuario.AdpsFechaVencimiento < DateTime.Now)
     {
         return(new Response
         {
             IsSuccess = false,
         });
     }
     return(new Response {
         IsSuccess = true
     });
 }
        public async Task <IActionResult> Edit(string id, Adscpassw adscpassw)
        {
            Response response = new Response();

            try
            {
                if (!string.IsNullOrEmpty(id))
                {
                    var respuestaActualizar = await apiServicio.SeleccionarAsync <Response>(id, new Uri(WebApp.BaseAddress),
                                                                                            "api/Adscpassws");

                    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.EditarAsync(id, adscpassw, new Uri(WebApp.BaseAddress),
                                                             "api/Adscpassws");

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

                        return(RedirectToAction("Index"));
                    }
                }
                return(BadRequest());
            }
            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());
            }
        }
示例#8
0
        private async Task <entidades.Utils.Response> EliminarTokenTemp(Adscpassw adscpassw)
        {
            entidades.Utils.Response response = new entidades.Utils.Response();
            if (!string.IsNullOrEmpty(adscpassw.AdpsLogin))
            {
                response = await apiServicio.EditarAsync <entidades.Utils.Response>(adscpassw, new Uri(WebApp.BaseAddressSeguridad), "api/Adscpassws/EliminarTokenTemp");

                if (response.IsSuccess)
                {
                    return(response);
                }
            }
            return(null);
        }
示例#9
0
        public async Task <IActionResult> Salir()
        {
            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 adscpasswSend = new Adscpassw
                {
                    AdpsLogin = NombreUsuario,
                    AdpsToken = token
                };

                Adscpassw adscpassw = new Adscpassw();
                adscpassw = await GetAdscPassws(adscpasswSend);

                var response = await EliminarToken(adscpassw);

                if (response.IsSuccess)
                {
                    await HttpContext.Authentication.SignOutAsync("Cookies");

                    foreach (var cookie in HttpContext.Request.Cookies.Keys)
                    {
                        HttpContext.Response.Cookies.Delete(cookie);
                    }
                    var responseLog = new EntradaLog
                    {
                        ExceptionTrace       = null,
                        LogCategoryParametre = Convert.ToString(LogCategoryParameter.Permission),
                        LogLevelShortName    = Convert.ToString(LogLevelParameter.INFO),
                        ObjectPrevious       = null,
                        ObjectNext           = null,
                    };
                    await apiServicio.SalvarLog <entidades.Utils.Response>(HttpContext, responseLog);

                    return(RedirectPermanent(WebApp.BaseAddressWebAppLogin));
                }
                return(RedirectPermanent(WebApp.BaseAddressWebAppLogin));
            }
            catch (Exception)
            {
                foreach (var cookie in HttpContext.Request.Cookies.Keys)
                {
                    HttpContext.Response.Cookies.Delete(cookie);
                }
                return(RedirectToAction(nameof(LoginController.Index), "Login"));
            }
        }
        public IActionResult GetToken()
        {
            Adscpassw adscpassw    = new Adscpassw();
            var       queryStrings = Request.Query;
            var       qsList       = new List <string>();

            foreach (var key in queryStrings.Keys)
            {
                qsList.Add(queryStrings[key]);
            }
            adscpassw = GetAdscPassws(qsList[0], qsList[1]);

            return(View());
        }
        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 Response ValidarNumeroIntentos(Adscpassw usuario)
        {
            if (usuario.AdpsIntentos >= 3)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.UsuarioBloqueado,
                    Resultado = new UsuarioBloqueado {
                        EstaBloqueado = true
                    }
                });
            }

            return(new Response {
                IsSuccess = true
            });
        }
示例#13
0
        public async Task <IActionResult> Create(Adscpassw adscpassw)
        {
            Response response = new Response();

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

                if (response.IsSuccess)
                {
                    var responseLog = await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                    {
                        ApplicationName      = Convert.ToString(Aplicacion.WebAppSeguridad),
                        ExceptionTrace       = null,
                        Message              = "Se ha creado un sistema",
                        UserName             = "******",
                        LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create),
                        LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                        EntityID             = string.Format("{0} {1}", "Sistema:", adscpassw.AdpsLogin),
                    });

                    return(RedirectToAction("Index"));
                }

                ViewData["Error"] = response.Message;
                return(View(adscpassw));
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.WebAppSeguridad),
                    Message              = "Creando Base de Datos",
                    ExceptionTrace       = ex,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "******"
                });

                return(BadRequest());
            }
        }
示例#14
0
        public async Task <IActionResult> Edit(string id, Adscpassw adscpassw)
        {
            Response response = new Response();

            try
            {
                if (!string.IsNullOrEmpty(id))
                {
                    response = await apiServicio.EditarAsync(id, adscpassw, new Uri(WebApp.BaseAddress),
                                                             "/api/Adscpassws");

                    if (response.IsSuccess)
                    {
                        await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                        {
                            ApplicationName      = Convert.ToString(Aplicacion.WebAppSeguridad),
                            EntityID             = string.Format("{0} : {1}", "Sistema", id),
                            LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit),
                            LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                            Message  = "Se ha actualizado un registro sistema",
                            UserName = "******"
                        });

                        return(RedirectToAction("Index"));
                    }
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.WebAppSeguridad),
                    Message              = "Editando una base de datos",
                    ExceptionTrace       = ex,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "******"
                });

                return(BadRequest());
            }
        }
        public async Task <IActionResult> Salir()
        {
            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 adscpasswSend = new Adscpassw
                {
                    AdpsLoginAdm = NombreUsuario,
                    AdpsToken    = token
                };

                Adscpassw adscpassw = new Adscpassw();
                adscpassw = await GetAdscPassws(adscpasswSend);

                var response = await EliminarToken(adscpassw);

                if (response.IsSuccess)
                {
                    await HttpContext.Authentication.SignOutAsync("Cookies");

                    foreach (var cookie in HttpContext.Request.Cookies.Keys)
                    {
                        HttpContext.Response.Cookies.Delete(cookie);
                    }
                    return(RedirectToAction(nameof(LoginController.Index), "Login"));
                }
                return(RedirectToAction(nameof(HomesController.Menu), "Homes"));
            }
            catch (Exception)
            {
                await HttpContext.Authentication.SignOutAsync("Cookies");

                foreach (var cookie in HttpContext.Request.Cookies.Keys)
                {
                    HttpContext.Response.Cookies.Delete(cookie);
                }
                return(RedirectToAction(nameof(LoginController.Index), "Login"));
            }
        }
示例#16
0
        public async Task <entidades.Utils.Response> CrearAsync(Adscpassw adscpassw)
        {
            entidades.Utils.Response response = new entidades.Utils.Response();
            try
            {
                response = await apiservicio.InsertarAsync(adscpassw,
                                                           new Uri(WebApp.BaseAddress),
                                                           "/api/BasesDatos/InsertarBaseDatos");

                if (response.IsSuccess)
                {
                    var responseLog = await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                    {
                        ApplicationName      = Convert.ToString(Aplicacion.WebAppSeguridad),
                        ExceptionTrace       = null,
                        Message              = "Se ha creado una base de datos",
                        UserName             = "******",
                        LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create),
                        LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                        EntityID             = string.Format("{0} {1}", "Base de Datos:", adscpassw.AdpsLogin),
                    });
                }

                return(response);
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.WebAppSeguridad),
                    Message              = "Creando Base de Datos",
                    ExceptionTrace       = ex,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Create),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "******"
                });

                response.IsSuccess = false;
                response.Message   = ex.Message;
                return(response);
            }
        }
示例#17
0
        public async Task <entidades.Utils.Response> EditarAsync(string id, Adscpassw Adscpassw)
        {
            entidades.Utils.Response response = new entidades.Utils.Response();
            try
            {
                if (!string.IsNullOrEmpty(id))
                {
                    response = await apiservicio.EditarAsync(id, Adscpassw, new Uri(WebApp.BaseAddress),
                                                             "/api/BasesDatos");

                    if (response.IsSuccess)
                    {
                        await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                        {
                            ApplicationName      = Convert.ToString(Aplicacion.WebAppSeguridad),
                            EntityID             = string.Format("{0} : {1}", "Base de Datos", id),
                            LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit),
                            LogLevelShortName    = Convert.ToString(LogLevelParameter.ADV),
                            Message  = "Se ha actualizado un registro",
                            UserName = "******"
                        });
                    }
                }
                return(response);
            }
            catch (Exception ex)
            {
                await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                {
                    ApplicationName      = Convert.ToString(Aplicacion.WebAppSeguridad),
                    Message              = "Editando una base de datos",
                    ExceptionTrace       = ex,
                    LogCategoryParametre = Convert.ToString(LogCategoryParameter.Edit),
                    LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                    UserName             = "******"
                });

                response.IsSuccess = false;
                response.Message   = ex.Message;
                return(response);
            }
        }
        public Response Existe(Adscpassw adscpassw)
        {
            var bdd = adscpassw.AdpsLogin.ToUpper().TrimEnd().TrimStart();
            var loglevelrespuesta = db.Adscpassw.Where(p => p.AdpsLogin.ToUpper().TrimStart().TrimEnd() == bdd).FirstOrDefault();

            if (loglevelrespuesta != null)
            {
                return(new Response
                {
                    IsSuccess = true,
                    Message = Mensaje.Excepcion,
                    Resultado = null,
                });
            }

            return(new Response
            {
                IsSuccess = false,
                Resultado = loglevelrespuesta,
            });
        }
        private async Task <Response> EliminarToken(Adscpassw adscpassw)
        {
            Response response = new Response();

            try
            {
                if (!string.IsNullOrEmpty(adscpassw.AdpsLogin))
                {
                    response = await apiServicio.EditarAsync <Response>(adscpassw, new Uri(WebApp.BaseAddress),
                                                                        "api/Adscpassws/EliminarToken");

                    if (response.IsSuccess)
                    {
                        return(response);
                    }
                }
                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
        }
示例#20
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));
            }
        }
示例#21
0
        public async Task <IActionResult> Login()
        {
            var user = HttpContext.User;

            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
            {
                AdpsLoginAdm  = qsList[0],
                AdpsTokenTemp = qsList[1]
            };

            adscpassw = await GetAdscPassws(adscpasswSend);

            var a = HttpContext.Items.Count;

            if (adscpassw != null)
            {
                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 claims = new[]
                {
                    new Claim(ClaimTypes.Name, NombreUsuario),
                    new Claim(ClaimTypes.SerialNumber, token)
                };



                var principal = new ClaimsPrincipal(new ClaimsIdentity(claims, "Cookies"));

                // var esto= ClaimsPrincipal.Current.Identities;

                await HttpContext.Authentication.SignInAsync("Cookies", principal, new Microsoft.AspNetCore.Http.Authentication.AuthenticationProperties {
                    IsPersistent = true
                });

                var response = await EliminarTokenTemp(adscpassw);

                if (response.IsSuccess)
                {
                    return(RedirectToAction(nameof(HomesController.Index), "Homes"));
                }
                else
                {
                    return(Redirect(WebApp.BaseAddressWebAppLogin));
                }
            }

            return(Redirect(WebApp.BaseAddressWebAppLogin));
        }
        public async Task <Response> PutAdscpassw([FromRoute] string id, [FromBody] Adscpassw adscpassw)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.ModeloInvalido
                    });
                }

                var adscPsswActualizar = await db.Adscpassw.Where(x => x.AdpsLogin.ToUpper() == id.ToUpper()).FirstOrDefaultAsync();

                if (adscPsswActualizar != null)
                {
                    try
                    {
                        adscPsswActualizar.AdpsIdContacto            = adscpassw.AdpsIdContacto;
                        adscPsswActualizar.AdpsTipoUso               = adscpassw.AdpsTipoUso;
                        adscPsswActualizar.AdpsLoginAdm              = adscpassw.AdpsLoginAdm;
                        adscPsswActualizar.AdpsIdEntidad             = adscpassw.AdpsIdEntidad;
                        adscPsswActualizar.AdpsCodigoEmpleado        = adscpassw.AdpsCodigoEmpleado;
                        adscPsswActualizar.AdpsPreguntaRecuperacion  = adscpassw.AdpsPreguntaRecuperacion;
                        adscPsswActualizar.AdpsRespuestaRecuperacion = adscpassw.AdpsRespuestaRecuperacion;
                        db.Adscpassw.Update(adscPsswActualizar);
                        await db.SaveChangesAsync();

                        return(new Response
                        {
                            IsSuccess = true,
                            Message = Mensaje.Satisfactorio,
                        });
                    }
                    catch (Exception ex)
                    {
                        await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                        {
                            ApplicationName      = Convert.ToString(Aplicacion.SwSeguridad),
                            ExceptionTrace       = ex,
                            Message              = Mensaje.Excepcion,
                            LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                            LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                            UserName             = "",
                        });

                        return(new Response
                        {
                            IsSuccess = false,
                            Message = Mensaje.Error,
                        });
                    }
                }

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.ExisteRegistro
                });
            }
            catch (Exception)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Excepcion
                });
            }
        }
        public async Task <Response> EliminarToken([FromBody] Adscpassw adscpassw)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(new Response
                    {
                        IsSuccess = false,
                        Message = Mensaje.ModeloInvalido
                    });
                }

                var adscPsswActualizar = await db.Adscpassw.Where(x => x.AdpsLogin.ToUpper() == adscpassw.AdpsLogin.ToUpper()).FirstOrDefaultAsync();

                if (adscPsswActualizar != null)
                {
                    try
                    {
                        adscPsswActualizar.AdpsToken = null;
                        db.Adscpassw.Update(adscPsswActualizar);
                        await db.SaveChangesAsync();

                        return(new Response
                        {
                            IsSuccess = true,
                            Message = Mensaje.Satisfactorio,
                        });
                    }
                    catch (Exception ex)
                    {
                        await GuardarLogService.SaveLogEntry(new LogEntryTranfer
                        {
                            ApplicationName      = Convert.ToString(Aplicacion.SwSeguridad),
                            ExceptionTrace       = ex,
                            Message              = Mensaje.Excepcion,
                            LogCategoryParametre = Convert.ToString(LogCategoryParameter.Critical),
                            LogLevelShortName    = Convert.ToString(LogLevelParameter.ERR),
                            UserName             = "",
                        });

                        return(new Response
                        {
                            IsSuccess = false,
                            Message = Mensaje.Error,
                        });
                    }
                }

                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.ExisteRegistro
                });
            }
            catch (Exception)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Mensaje.Excepcion
                });
            }
        }
        /// <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));
            }
        }