private void AssignUser() { // Si existe un usuario logueado if (SessionCookie != null) { // Se captura un usuario string sUsuario = SessionCookie.Values["Usuario"]; string ruc = SessionCookie.Values["RUC"]; UserLogued = BUsuario.BuscarPorUsuario(sUsuario, ruc); string idsucursal = SessionCookie.Values["IdSucursal"]; string nombreSucursal = SessionCookie.Values["NombreSucursal"]; //if (idsucursal != null) //{ // UserLogued.Sucursal.IdSucursal = int.Parse(idsucursal); // UserLogued.Sucursal.Nombre = nombreSucursal; //} List <EMenu> lPermisos = BUsuario.ListarMenuPorUsuario(sUsuario, ruc); if (lPermisos.Count > 0) { UserLogued.Menu = lPermisos; } } }
public ActionResult Login(EUsuario Model) { try { if (!string.IsNullOrEmpty(Model.Usuario) && !string.IsNullOrEmpty(Model.Password)) { Authentication.UserLogued = BUsuario.Login(Model.Usuario, Model.Password); if (Authentication.UserLogued.Respuesta == 2) { Authentication.UserLogued.Menu = BUsuario.ListarMenuPorUsuario(Model.Usuario, Model.RUC); if (Authentication.UserLogued.Menu.Count > 0) { var now = DateTime.Now; // Guardado de actividad en sesión Authentication.SessionCookie = new HttpCookie("SessionCookie"); // Creación de cookie Authentication.SessionCookie.Expires = now.AddDays(1); //expire en 24H Authentication.SessionCookie.Values.Add("Usuario", Model.Usuario); // Guardado del usuario en sesión Authentication.SessionCookie.Values.Add("RUC", Model.RUC); // Guardado del ruc en sesión Debug.WriteLine(Authentication.SessionCookie.Values); Response.Cookies.Add(Authentication.SessionCookie); Session.Timeout = (int)Authentication.SessionCookie.Expires.Subtract(now).TotalMinutes; //monutos de Session["Usuario"] = Authentication.UserLogued; //if (Authentication.UserLogued.Id == 1) //{ // return RedirectToAction("Principal", "Seguridad"); //} //else //{ //} return(RedirectToAction("Principal", "Seguridad")); } else { ViewBag.Message = "El rol que usted posee asignado no tiene permisos asignados."; } } else { ViewBag.Message = "Credenciales Incorrectas"; } } else { ViewBag.Message = "Debe ingresar un usuario y contraseña."; } } catch (Exception Exception) { ViewBag.Message = Exception.Message; } return(View()); }