Exemple #1
0
        public ActionResult Login(LoginModel usuarioViewModel)
        {
            if (ModelState.IsValid)
            {
                Usuario usuario = new Usuario();
                usuario.UserName   = usuarioViewModel.UserName;
                usuario.Password   = usuarioViewModel.Password;
                usuario.Recordarme = usuarioViewModel.Recordarme;

                if (usuarioRepository.IsValid(usuario))
                {
                    var user = usuarioRepository.GetUserByUserName(usuario.UserName);

                    if (user.RolesEmpresa.Any(i => i.Rol_Id == 25))
                    {
                        if (!usuarioRepository.IsClienteActivo(usuario))
                        {
                            //vClientes cliente = new vClientes();
                            //string filtro = string.Format("Cuit = '{0}'", user.UserName);
                            //var dtcliente = cliente.GetByFilter(filtro);
                            //string rs = dtcliente.Rows[0][1].ToString();
                            string aviso = string.Format(" El Cliente {0} se encuentra inactivo, solicite su activacion", user.NombreApellido);
                            ModelState.AddModelError("", aviso);
                        }
                        else if (user.CambiarPass != true)
                        {
                            var authenticationService = AuthenticationFactory.CreateAuthentication();

                            var serializeModel = new CustomPrincipalSerializeModel();
                            serializeModel.UserID    = user.Id;
                            serializeModel.FirstName = user.NombreApellido;
                            serializeModel.UserName  = user.UserName;


                            var serializer = new JavaScriptSerializer();
                            var userData   = serializer.Serialize(serializeModel);

                            authenticationService.Login(user.UserName, user.Password, usuario.Recordarme, userData);

                            user.FechaUltimoAcceso = DateTime.Now;
                            usuarioRepository.Modify(user, user.Id);
                            AppSession.Init_Session(user.Id);
                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            return(UsuarioCambioPassword(usuario));
                        }
                    }
                    else if (user.CambiarPass != true)
                    {
                        var authenticationService = AuthenticationFactory.CreateAuthentication();

                        var serializeModel = new CustomPrincipalSerializeModel();
                        serializeModel.UserID    = user.Id;
                        serializeModel.FirstName = user.NombreApellido;
                        serializeModel.UserName  = user.UserName;


                        var serializer = new JavaScriptSerializer();
                        var userData   = serializer.Serialize(serializeModel);

                        authenticationService.Login(user.UserName, user.Password, usuario.Recordarme, userData);

                        user.FechaUltimoAcceso = DateTime.Now;
                        usuarioRepository.Modify(user, user.Id);
                        AppSession.Init_Session(user.Id);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        return(UsuarioCambioPassword(usuario));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Error al validar datos ingresados, intente nuevamente");
                }
            }
            return(View(usuarioViewModel));
        }
Exemple #2
0
        public static IHtmlString DrawMenuItems(this HtmlHelper html)
        {
            StringBuilder sb = new StringBuilder();

            var currenUser   = AuthenticationFactory.CreateAuthentication().GetUser();
            var currenModulo = GetBaseController(html).GetCurrenModulo();

            currenUser.RolesEmpresa = AppSession.RolesEmpresa;
            //  currenUser.UsuarioRolClientes = AppSession.RolesCliente;
            //var listModulosSistema = moduloRepository.GetFiltered(o=>o.Visible, p=>p.Parent).OrderBy(o=>o.Descripcion);
            var listModulosSistema = moduloRepository.GetModulosUser(currenUser.RolesEmpresa, AppSession.Modulos);
            var menuVM             = MenuViewModel.CreateVM(null, listModulosSistema.ToList());

            //   var listModulosPermiso = usuarioRepository.GetRolesEmpresaByUsuarioId(currenUser.UserID).Select(o=>o.Rol.ModulosPermiso);

            //foreach (var ob in listModulosPermiso)
            //{
            //    foreach (var modulo in ob.GroupBy(o => o.Modulo_Id).Select(group => group.First()))
            //    {

            //  //      menuVM.Where(o => o.Children.se == modulo.Modulo_Id).Any();

            //    }
            //}

            string classExpand        = "class='hasSub current'";
            string classAExpand       = "class='expand rotateOut'";
            string classSubExpandShow = "class='sub expand show'";
            string classCurrent       = "class='current'";

            foreach (var menuItem in menuVM)
            {
                if (IsInCurrentModulo(currenModulo, menuItem.MenuId))
                {
                    sb.Append("<li " + classExpand + ">");

                    sb.Append("<a href='#' " + classAExpand + ">");
                }
                else
                {
                    sb.Append("<li >");
                    sb.Append("<a href='#'>");
                }
                sb.Append(" <span class='icon'><i class='" + menuItem.Class + "'></i></span>");
                sb.Append(" <span class='txt'>" + menuItem.Descripcion + "</span>");
                sb.Append("</a>");

                if (menuItem.Children.Count() > 0)
                {
                    if (IsInCurrentModulo(currenModulo, menuItem.MenuId))
                    {
                        sb.Append("<ul " + classSubExpandShow + " >");
                    }
                    else
                    {
                        sb.Append("<ul class='sub'>");
                    }

                    #region Sub Menu 1° Nivel
                    foreach (var child in menuItem.Children)
                    {
                        if (currenModulo.Id == menuItem.MenuId)
                        {
                            sb.Append("<li " + classCurrent + " >");
                        }
                        else
                        {
                            sb.Append("<li>");
                        }

                        if (child.URL != string.Empty && child.URL != null)
                        {
                            if (child.URL.ToUpper().StartsWith("HTTP"))
                            {
                                if (IsInCurrentModulo(currenModulo, child.MenuId))
                                {
                                    sb.Append("<a href='" + child.URL + "' " + classExpand + " >");
                                }
                                else
                                {
                                    sb.Append("<a href='" + child.URL + "'>");
                                }
                            }
                            else
                            {
                                if (IsInCurrentModulo(currenModulo, child.MenuId))
                                {
                                    sb.Append("<a href='/" + child.URL + "' " + classExpand + " >");
                                }
                                else
                                {
                                    sb.Append("<a href='/" + child.URL + "'>");
                                }
                            }
                        }
                        else
                        if (IsInCurrentModulo(currenModulo, child.MenuId))
                        {
                            sb.Append("<a href='#'>");
                        }
                        else
                        {
                            sb.Append("<a href='#' " + classExpand + " >");
                        }

                        sb.Append("<span class='icon'><i class='" + (child.Class != null && child.Class != string.Empty ? child.Class : "") + "'></i></span>");
                        sb.Append(" <span class='txt'>" + child.Descripcion + "</span>");
                        sb.Append("</a>");

                        //if(child.Children.Count() > 0)
                        //    sb.Append("<ul class='sub'>");

                        if (child.Children.Count() > 0)
                        {
                            if (IsInCurrentModulo(currenModulo, child.MenuId))
                            {
                                sb.Append("<ul " + classSubExpandShow + " >");
                            }
                            else
                            {
                                sb.Append("<ul class='sub'>");
                            }
                        }

                        #region Sub Menu 2° Nivel
                        foreach (var subchild in child.Children)
                        {
                            //   sb.Append("<li>");
                            if (currenModulo.Id == menuItem.MenuId)
                            {
                                sb.Append("<li " + classCurrent + " >");
                            }
                            else
                            {
                                sb.Append("<li>");
                            }

                            if (subchild.URL != string.Empty && subchild.URL != null)
                            {
                                if (subchild.URL.ToUpper().StartsWith("HTTP"))
                                {
                                    if (IsInCurrentModulo(currenModulo, subchild.MenuId))
                                    {
                                        sb.Append("<a href='" + subchild.URL + "' " + classExpand + " >");
                                    }
                                    else
                                    {
                                        sb.Append("<a href='" + subchild.URL + "'>");
                                    }
                                }
                                else
                                {
                                    if (IsInCurrentModulo(currenModulo, subchild.MenuId))
                                    {
                                        sb.Append("<a href='/" + subchild.URL + "' " + classExpand + " >");
                                    }
                                    else
                                    {
                                        sb.Append("<a href='/" + subchild.URL + "'>");
                                    }
                                }
                            }
                            else
                            if (IsInCurrentModulo(currenModulo, subchild.MenuId))
                            {
                                sb.Append("<a href='#'>");
                            }
                            else
                            {
                                sb.Append("<a href='#' " + classExpand + " >");
                            }

                            sb.Append("<span class='icon'><i class='" + (subchild.Class != null && subchild.Class != string.Empty ? subchild.Class : "") + "'></i></span>");
                            sb.Append(" <span class='txt'>" + subchild.Descripcion + "</span>");
                            sb.Append("</a>");

                            //if (subchild.Children.Count() > 0)
                            //    sb.Append("<ul class='sub'>");

                            if (subchild.Children.Count() > 0)
                            {
                                if (IsInCurrentModulo(currenModulo, subchild.MenuId))
                                {
                                    sb.Append("<ul " + classSubExpandShow + " >");
                                }
                                else
                                {
                                    sb.Append("<ul class='sub'>");
                                }
                            }

                            #region Sub Menu 3° Nivel
                            foreach (var subsubchild in subchild.Children)
                            {
                                //   sb.Append("<li>");
                                if (currenModulo.Id == subsubchild.MenuId)
                                {
                                    sb.Append("<li " + classCurrent + " >");
                                }
                                else
                                {
                                    sb.Append("<li>");
                                }

                                if (subsubchild.URL != string.Empty && subsubchild.URL != null)
                                {
                                    if (subsubchild.URL.ToUpper().StartsWith("HTTP"))
                                    {
                                        if (IsInCurrentModulo(currenModulo, subsubchild.MenuId))
                                        {
                                            sb.Append("<a href='" + subsubchild.URL + "' " + classExpand + " >");
                                        }
                                        else
                                        {
                                            sb.Append("<a href='" + subsubchild.URL + "'>");
                                        }
                                    }
                                    else
                                    {
                                        if (IsInCurrentModulo(currenModulo, subsubchild.MenuId))
                                        {
                                            sb.Append("<a href='/" + subsubchild.URL + "' " + classExpand + " >");
                                        }
                                        else
                                        {
                                            sb.Append("<a href='/" + subsubchild.URL + "'>");
                                        }
                                    }
                                }

                                else
                                if (IsInCurrentModulo(currenModulo, subsubchild.MenuId))
                                {
                                    sb.Append("<a href='#'>");
                                }
                                else
                                {
                                    sb.Append("<a href='#' " + classExpand + " >");
                                }

                                sb.Append("<span class='icon'><i class='" + (subsubchild.Class != null && subsubchild.Class != string.Empty ? subsubchild.Class : "") + "'></i></span>");
                                sb.Append(" <span class='txt'>" + subsubchild.Descripcion + "</span>");
                                sb.Append("</a>");

                                sb.Append("</li>");
                            }
                            #endregion

                            if (subchild.Children.Count() > 0)
                            {
                                sb.Append("</ul>");
                            }
                            sb.Append("</li>");
                        }

                        #endregion

                        if (child.Children.Count() > 0)
                        {
                            sb.Append("</ul>");
                        }
                        sb.Append("</li>");
                    }
                    #endregion

                    if (menuItem.Children.Count() > 0)
                    {
                        sb.Append("</ul>");
                    }
                    sb.Append("</li>");
                }
            }

            //foreach (var ob in listRolEmpresa.Select(o => o.Rol.ModulosPermiso))
            //{
            //    foreach (var modulo in ob.GroupBy(o=>o.Modulo_Id).Select(group => group.First()))
            //    {
            //       var moduloSistema= listModulosSistema.Where(o => o.Id == modulo.Modulo_Id).FirstOrDefault();
            //       var result = moduloSistema.Parent.
            //    }
            //}

            return(new HtmlString(sb.ToString()));
        }
Exemple #3
0
 public ActionResult Logout()
 {
     AuthenticationFactory.CreateAuthentication().Logout();
     return(RedirectToAction("Login", "Usuario"));
 }
Exemple #4
0
        public ActionResult UsuarioCambioPassword([Bind(Include = "UserName,Password,NuevaPassword,NuevaPasswordAgain")] ChangePasswordModel changeUsuario)
        {
            ViewBag.FirstTime = null;
            if (ModelState.IsValid)
            {
                Usuario user = new Usuario();
                user.UserName = changeUsuario.UserName;
                user.Password = changeUsuario.Password;

                if (usuarioRepository.IsValid(user))
                {
                    if (changeUsuario.NuevaPassword.Trim().Equals(changeUsuario.NuevaPasswordAgain.Trim()))
                    {
                        if (changeUsuario.NuevaPassword.Length >= 4)
                        {
                            var usuario = usuarioRepository.GetUserByUserName(changeUsuario.UserName);

                            usuario.Password          = changeUsuario.NuevaPassword;
                            usuario.FechaUltimoAcceso = DateTime.Now;
                            usuario.CambiarPass       = false;

                            usuarioRepository.Modify(usuario, user.Id);

                            var authenticationService = AuthenticationFactory.CreateAuthentication();

                            var serializeModel = new CustomPrincipalSerializeModel();
                            serializeModel.UserID    = usuario.Id;
                            serializeModel.FirstName = usuario.NombreApellido;
                            serializeModel.UserName  = usuario.UserName;

                            var serializer = new JavaScriptSerializer();
                            var userData   = serializer.Serialize(serializeModel);

                            authenticationService.Login(usuario.UserName, usuario.Password, usuario.Recordarme, userData);

                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "La nueva Password debe contener más de 3 caracteres");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Las Password no coinciden");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Error al validar datos ingresados, intente nuevamente");
                }
            }
            else
            {
                changeUsuario.Password           = null;
                changeUsuario.NuevaPassword      = null;
                changeUsuario.NuevaPasswordAgain = null;
            }

            return(View("UsuarioCambioPassword", changeUsuario));
        }
Exemple #5
0
 public Startup(IConfiguration configuration)
 {
     Configuration = configuration;
     AuthenticationFactory.CreateAuthentication(AuthenticationFactory.CustomAuthType.Jwt, new TimeSpan(0, 30, 0));
 }
Exemple #6
0
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            if (HttpContext.Current.User != null)
            {
                return;
            }

            HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (authCookie != null)
            {
                if (!string.IsNullOrEmpty(authCookie.Value))
                {
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
                    if (ticket == null)
                    {
                        return;
                    }


                    try
                    {
                        Business.DAL.UsuarioRepository usuarioRepo = new Business.DAL.UsuarioRepository();
                        var authenticationService = AuthenticationFactory.CreateAuthentication();
                        var user           = usuarioRepo.GetUserByUserName(ticket.Name, true);
                        var serializeModel = new CustomPrincipalSerializeModel();
                        serializeModel.UserID    = user.Id;
                        serializeModel.FirstName = user.NombreApellido;
                        serializeModel.UserName  = user.UserName;


                        var serializer = new JavaScriptSerializer();
                        var userData   = serializer.Serialize(serializeModel);

                        authenticationService.Login(user.NombreApellido, user.Password, user.Recordarme, userData);

                        user.FechaUltimoAcceso = DateTime.Now;
                        usuarioRepo.Modify(user, user.Id);
                        // AppSession.Init_Session(user.Id);
                        //    u = uow.LoginWithTicket(ticket.Name);
                    }
                    catch (Exception)
                    {
                        HttpContext.Current.User = null;
                        return;
                    }

                    //  HttpContext.Current.User = new Business.UserPrincipal(u);
                }
            }

            /*else
             * {
             * Business.UnitOfWork uow = new Business.UnitOfWork();
             * Business.User u         = null;
             * try
             * {
             *     u = uow.LoginAsAnonymous();
             * }
             * catch (Exception)
             * {
             *     HttpContext.Current.User = null;
             *     return;
             * }
             *
             * HttpContext.Current.User = new Business.UserPrincipal(u);
             * }*/
        }
Exemple #7
0
 protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
 {
     AuthenticationFactory.CreateAuthentication().PostAuthenticateRequest();
 }