Ejemplo n.º 1
0
 public void OnAuthorization(AuthorizationContext filterContext)
 {
     if (filterContext.RequestContext.HttpContext.Request.IsAuthenticated)
     {
         IUserDAL us   = new UserDALImp();
         User     user = us.Get_User(Convert.ToInt32(filterContext.RequestContext.HttpContext.User.Identity.Name));
         if (user != null)
         {
             if (!user.active)
             {
                 //ViewBag.Desactivado = true;
                 filterContext.RequestContext.HttpContext.RedirectLocal("/Home/Index");
             }
             else
             {
                 UserViewModel userV = UserViewModel.Converter(user);
                 Assistance    a     = loadAssistance(user.idUser);
                 if (a != null)
                 {
                     userV.assistance = a;
                 }
                 filterContext.RequestContext.HttpContext.Session["User"] = userV;
             }
         }
         else
         {
             if (!filterContext.RequestContext.HttpContext.Request.Url.AbsolutePath.Equals("/Home/Index"))
             {
                 filterContext.Result = new RedirectToRouteResult("/Home/Index", null);
                 //filterContext.RequestContext.HttpContext.Response.Redirect("/Home/Index");
             }
         }
     }
 }
Ejemplo n.º 2
0
        public ActionResult Details(int id)
        {
            User       us;
            UserDALImp imp = new UserDALImp();

            us = imp.Get_User(id);
            return(View(UserViewModel.Converter(us)));
        }
Ejemplo n.º 3
0
 public override Task OnDisconnected(bool stopCalled)
 {
     if (Context.User.Identity.IsAuthenticated)
     {
         IUserDAL us   = new UserDALImp();
         User     user = us.Get_User(Convert.ToInt32(Context.Request.User.Identity.Name));
         if (UserConnections.TryGetValue(user.idUser, out WsUserModel usu))
         {
             usu.connectionsId = usu.connectionsId.FindAll(o => !o.Equals(Context.ConnectionId));
             if (usu.connectionsId.Count == 0)
             {
                 UserConnections.Remove(usu.user.idUser);
             }
         }
     }
     return(base.OnDisconnected(stopCalled));
 }
Ejemplo n.º 4
0
        public ActionResult Edit(int id)
        {
            if (TempData["msg"] != null)
            {
                ViewBag.msg = TempData["msg"].ToString();
                TempData.Remove("msg");
            }
            User       us;
            UserDALImp imp = new UserDALImp();

            us          = imp.Get_User(id);
            us.password = "******";
            if (!us.rol.Equals("C"))
            {
                us.height = 10;
                us.weight = 10;
            }
            return(View(UserViewModel.Converter(us)));
        }
Ejemplo n.º 5
0
        private WsUserModel GetCurUser()
        {
            IUserDAL us   = new UserDALImp();
            User     user = us.Get_User(Convert.ToInt32(Context.Request.User.Identity.Name));

            if (UserConnections.TryGetValue(user.idUser, out WsUserModel usu))
            {
                return(usu);
            }
            else if (user != null)
            {
                usu = new WsUserModel {
                    user                 = user,
                    connectionsId        = new List <string>(),
                    idActivityAssistance = -5
                };
                usu.connectionsId.Add(Context.ConnectionId);
                UserConnections.Add(usu.user.idUser, usu);
                return(usu);
            }
            return(null);
        }
Ejemplo n.º 6
0
 public override Task OnConnected()
 {
     if (Context.User.Identity.IsAuthenticated)
     {
         IUserDAL us   = new UserDALImp();
         User     user = us.Get_User(Convert.ToInt32(Context.Request.User.Identity.Name));
         if (UserConnections.TryGetValue(user.idUser, out WsUserModel usu))
         {
             usu.connectionsId.Add(Context.ConnectionId);
         }
         else
         {
             usu = new WsUserModel {
                 user                 = user,
                 connectionsId        = new List <string>(),
                 idActivityAssistance = -5
             };
             usu.connectionsId.Add(Context.ConnectionId);
             UserConnections.Add(usu.user.idUser, usu);
         }
     }
     return(base.OnConnected());
 }