Set login page by user profile

Asked

Viewed 46 times

0

Good afternoon guys, I need a little help from you.

I have two access profiles to my system. "Master-IT" and "Developer"

This is my system login controller

[HttpPost]
        public ActionResult Index(Usuario usr)
        {
            if (ModelState.IsValid)
            {
                usr = _usuarioService.GetUsuarioCentroNaoRemovido(usr.Email, usr.Senha);

                if (usr != null)
                {

                    if (usr.Removido == 1)
                    {
                        var hhospitais = _hospitalService.GetAll().Select(s => new { HosppitalId = s.CentroId, Descricao = $"{s.CentroId} - {s.Nome}" });
                        ViewBag.Hospitais = new SelectList(hhospitais, "HospitalId", "Descricao", "0");

                        ModelState.AddModelError("UserNotFound", "Usuário bloqueado.");
                        return View();
                    }

                    var hospitaisLista = UsuarioCentroService.GetUsuarioCentrosByUsuario(usr.UsuarioId);
                    usr.Centros = hospitaisLista.ToList();
                    var permissoes = _permissoesService.GetPermissaoByUser(usr.UsuarioId).Select(s => s.Nome).ToList();
                    CriarCookie(usr);
                    CreateTicket(usr, permissoes);

                    _usuarioService.Dispose();
                    return RedirectToAction("Index", "Cadastro", new { area = "Formulario" });
                }
            }

            var hospitais = _hospitalService.GetAll().Select(s => new { HospitalId = s.CentroId, Descricao = $"{s.CentroId} - {s.Nome}" });
            ViewBag.Hospitais = new SelectList(hospitais, "HospitalId", "Descricao", "0");

            ModelState.AddModelError("UserNotFound", "Usuario não encontrado!");
            return View();
        }

My cry for help is this: I need to check which profile you’re accessing

If it is Master-IT enters this Return view RedirectToAction("Index", "Cadastro", new { area = "Formulario" });

If you are a Developer please log in to this view RedirectToAction("Desenvolvimento", "Cadastro", new { area = "Formulario" });

I tried using User.Isinrole("Master-TI") doing an if in Return only it didn’t work

1 answer

0

I’ve already solved.

public async Task<ActionResult> Index()
        {
            if (!Cookies.Exists("hid"))
                return RedirectToAction("Index", "Login", new { area = "Entrar" });

            var hospitalId = int.Parse(Cookies.GetCookie("hid"));
            var lista = await _cadastroService.GetLista(hospitalId);
            if (User.IsInRole("Genérico"))
            {
                return RedirectToAction("Cadastro", "Cadastro", new { area = "Formulario" });
            }
            else
            {
                return View(lista);
            }
        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.