Пример #1
0
        public ActionResult Crear(Usuario usuario)
        {
            var SecretKey       = ConfigurationManager.AppSettings["SecretKey"];
            var ClaveEncriptada = Seguridad.EncryptString(SecretKey, usuario.Clave);

            try
            {
                if (ObjUsuario.AgregarUsuario(usuario.IdInstitucion, usuario.IdTipoIdentificacion, usuario.Identificacion, usuario.Nombre, usuario.Apellido1, usuario.Apellido2, ClaveEncriptada, usuario.Telefono, usuario.Direccion, usuario.Correo, usuario.FechaNacimiento, usuario.Estado))
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.TipoIdentificacion = ConsultarTipoIdentificacion();
                    ViewBag.Institucion        = ConsultarInstitucion();

                    return(View());
                }
            }
            catch (Exception)
            {
                return(View());

                throw;
            }
        }
Пример #2
0
        public ActionResult Editar(Usuario usuario)
        {
            try
            {
                var claveSegura = Seguridad.EncryptString(Seguridad.SecureKey, usuario.Clave);
                if (ObjUsuario.ActualizaUsuario(usuario.IdUsuario, usuario.IdEmpresa, usuario.IdTipoIdentificacion, usuario.Identificacion,
                                                usuario.Nombre, usuario.Apellido1, usuario.Apellido2, usuario.Telefono, usuario.Correo, claveSegura, usuario.Estado, Session["Identificacion"].ToString()))
                {
                    ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Usuario", "Editar Usuario", "Se edita correctamente un usuario.", 1);
                    return(RedirectToAction("IndexUsuario"));
                }
                else
                {
                    ViewBag.Empresas             = ListaEmpresas().Where(x => x.Estado == true);
                    ViewBag.TipoIdentificaciones = ListaTipoIdentificacion().Where(x => x.Estado == true);
                    ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Usuario", "Editar Usuario", "Error al editar usuario.", 0);
                    return(View(usuario));
                }
            }
            catch (Exception)
            {
                ViewBag.Empresas             = ListaEmpresas().Where(x => x.Estado == true);
                ViewBag.TipoIdentificaciones = ListaTipoIdentificacion().Where(x => x.Estado == true);
                ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Usuario", "Editar Usuario", "Error al editar usuario.", 0);
                return(View(usuario));

                throw;
            }
        }
Пример #3
0
        public ActionResult Login(Login login)
        {
            var SecretKey = ConfigurationManager.AppSettings["SecretKey"];

            if (ModelState.IsValid)
            {
                var ClaveEncriptada = Seguridad.EncryptString(SecretKey, login.Clave);
                // var ClaveDesencriptada = Seguridad.DecryptString(SecretKey, ClaveEncriptada);
                var datos = objUsuario.validarUsuario(login.Correo, ClaveEncriptada);

                if (datos == null)
                {
                    return(View(login));
                }
                else
                {
                    //Roles del  Usuario
                    //var ListaRoles = ObjUsuario.ConsultarRolesUsuario(datos.IdUsuario);

                    //var roles = String.Join(",", ListaRoles.Select(x => x.Rol));

                    //Session["Identificacion"] = datos.Identificacion.ToString();
                    //Session["IdInstitucion"] = datos.IdInstitucion.ToString();
                    //Session["IdUsuario"] = datos.IdUsuario.ToString();
                    //Lo siguiente ya no sirve
                    //FormsAuthentication.SetAuthCookie(datos.Nombre + " " + datos.Apellido1 + " " +  datos.Apellido2, login.Recordarme);

                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, login.Correo, DateTime.Now, DateTime.Now.AddMinutes(30), login.Recordarme, /*, roles*/ FormsAuthentication.FormsCookiePath);
                    string     hash   = FormsAuthentication.Encrypt(ticket);
                    HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);

                    if (ticket.IsPersistent)
                    {
                        cookie.Expires = ticket.Expiration;
                    }
                    Response.Cookies.Add(cookie);
                    //Session["Identificacion"] = datos.Identificacion;
                    if (Request.Browser.IsMobileDevice)
                    {
                        return(RedirectToAction("Index", "Home"));//Aqui llamaba a carnet, pero por el momento se pone a la principal
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
            else
            {
                return(View(login));
            }
        }
Пример #4
0
        public ActionResult Login(Login login, string ReturnUrl)
        {
            var SecretKey = ConfigurationManager.AppSettings["SecretKey"];

            if (ModelState.IsValid)
            {
                var clavesegura = Seguridad.EncryptString(SecretKey, login.Clave);
                //var claveorigen = Seguridad.DecryptString(SecretKey, clavesegura);
                var datos = ObjUsuario.ValidaUsuario(login.Correo, clavesegura);
                if (datos == null)
                {
                    ViewBag.Error = "¡Correo o contraseña inválidos!";
                    ObjBitacora.RegistraBitacora(login.Correo, "Login", "Ingreso", "Credenciales de ingreso no válidas", 0);
                    return(View(login));
                }
                else
                {
                    var ListaRoles = ObjUsuario.UsuarioRoles(datos.IdUsuario);

                    var roles = String.Join(",", ListaRoles.Select(x => x.Rol));

                    Session["Identificacion"] = datos.Identificacion.ToString();
                    Session["Telefono"]       = datos.Telefono.ToString();
                    Session["Empresa"]        = datos.IdEmpresa;
                    Session["Nombre"]         = datos.Nombre;
                    Session["Roles"]          = roles;
                    //FormsAuthentication.SetAuthCookie(datos.Nombre + " " + datos.Apellido1 + " " +  datos.Apellido2, login.Recordarme);

                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, login.Correo, DateTime.Now, DateTime.Now.AddMinutes(30), login.Recordarme, roles, FormsAuthentication.FormsCookiePath);
                    string     hash   = FormsAuthentication.Encrypt(ticket);
                    HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);

                    if (ticket.IsPersistent)
                    {
                        cookie.Expires = ticket.Expiration;
                    }
                    Response.Cookies.Add(cookie);

                    Session["Identificacion"] = datos.Identificacion;
                    if (Request.Browser.IsMobileDevice)
                    {
                        ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Login", "Ingreso", "Ingreso en dispositivo móvil", 1);
                        return(RedirectToAction("Index", "Carnet"));
                    }
                    else
                    {
                        if (roles.Equals("Usuario"))
                        {
                            ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Login", "Ingreso", "Ingreso de usuario", 1);
                            return(RedirectToAction("IndexProductos", "Home", new { idEmp = datos.IdEmpresa }));
                        }
                        else if (roles.Equals("Administrador") || roles.Equals("Supervisor"))
                        {
                            ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Login", "Ingreso", "Ingreso de administrador o supervisor", 1);
                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            ViewBag.Error = "¡Usuario sin Rol asignado!";
                            ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Login", "Ingreso", "Usuario sin rol asignado", 0);
                            return(View(login));
                        }
                    }
                }
            }
            else
            {
                ViewBag.Error = "¡Correo o contraseña inválidos!";
                ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Login", "Ingreso", "Credenciales de ingreso no válidas", 0);
                return(View(login));
            }
        }
Пример #5
0
        public ActionResult Crear(Usuario usuario)
        {
            try
            {
                var user   = "";
                var estado = true;
                if (!Request.IsAuthenticated)
                {
                    user = "******";
                }
                else
                {
                    user   = Session["Identificacion"].ToString();
                    estado = usuario.Estado;
                }
                var claveSegura = Seguridad.EncryptString(Seguridad.SecureKey, usuario.Clave);
                if (ObjUsuario.AgregaUsuarior(usuario.IdEmpresa, usuario.IdTipoIdentificacion, usuario.Identificacion,
                                              usuario.Nombre, usuario.Apellido1, usuario.Apellido2, usuario.Telefono, usuario.Correo, claveSegura,
                                              estado, user))
                {
                    if (Request.IsAuthenticated)
                    {
                        ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Usuario", "Crear Usuario", "Se registra un usuario desde administrador.", 1);
                        if (objRoluser.TRAgregaUsuarioRol(1, user))
                        {
                            ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Usuario", "Asignar Rol automático", "Se asigna rol de usuario al nuevo usuario.", 1);
                        }
                        return(RedirectToAction("IndexUsuario"));
                    }
                    else
                    {
                        ObjBitacora.RegistraBitacora("new user", "Usuario", "Crear Usuario", "Se realiza un autoregistro de un nuevo usuario.", 1);
                        if (objRoluser.TRAgregaUsuarioRol(1, user))
                        {
                            ObjBitacora.RegistraBitacora("new user", "Usuario", "Asignar Rol automático", "Se asigna rol de usuario al nuevo usuario.", 1);
                        }
                        return(RedirectToAction("Login", "Login"));
                    }
                }
                else
                {
                    if (Request.IsAuthenticated)
                    {
                        ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Usuario", "Crear Usuario", "Error al crear nuevo usuario.", 0);
                    }
                    else
                    {
                        ObjBitacora.RegistraBitacora("new user", "Usuario", "Crear Usuario", "Error al crear nuevo usuario.", 0);
                    }
                    ViewBag.Empresas             = ListaEmpresas().Where(x => x.Estado == true);
                    ViewBag.TipoIdentificaciones = ListaTipoIdentificacion().Where(x => x.Estado == true);
                    return(View(usuario));
                }
            }
            catch (Exception)
            {
                if (Request.IsAuthenticated)
                {
                    ObjBitacora.RegistraBitacora(Session["Identificacion"].ToString(), "Usuario", "Crear Usuario", "Error al crear nuevo usuario.", 1);
                }
                else
                {
                    ObjBitacora.RegistraBitacora("new user", "Usuario", "Crear Usuario", "Error al crear nuevo usuario.", 1);
                }
                ViewBag.TipoIdentificaciones = ListaTipoIdentificacion().Where(x => x.Estado == true);
                ViewBag.Empresas             = ListaEmpresas().Where(x => x.Estado == true);
                return(View(usuario));

                throw;
            }
        }