Exemple #1
0
        public virtual ActionResult Index(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication;
            var authService          = new AdAuthenticationService(authenticationManager);
            var authenticationResult = authService.SignIn(model.Username, model.Password);
            // var authenticationResult = authService.SignIn("Steven Villalobos", "svch1996");
            string user;

            if (authenticationResult.IsSuccess)
            {
                user = authService.GetUsername(model.Username, model.Password);
                string rolU;

                try
                {
                    tablaGeneralBLL = new TablaGeneralBLLImpl();
                    usuarioBLL      = new UsuarioBLLImpl();
                    rolU            = String.Concat(usuarioBLL.gerRolForUser(usuarioBLL.getUsuario(user).nombre));
                }
                catch (Exception)
                {
                    return(View());
                }
                if (usuarioBLL.getUsuario(model.Username) == null)
                {
                    Usuario usuario = new Usuario();
                    usuario.idEstado = tablaGeneralBLL.getIdTablaGeneral("usuarios", "estado", "activo");
                    usuario.nombre   = model.Username;
                    usuario.usuario1 = user;
                    usuarioBLL.Add(usuario);
                }
                if (rolU == "DBA")
                {
                    if (crearRoles("DBA"))
                    {
                        Roles.AddUserToRole(model.Username, "DBA");
                    }
                }
                else if (rolU == "Abogado")
                {
                }
                else
                {
                }
                return(RedirectToLocal(returnUrl));
            }

            ModelState.AddModelError("", authenticationResult.ErrorMessage);
            return(View(model));
        }