dongmeixi5311 2017-07-31 08:39
浏览 9
已采纳

如何在symfony 3中查看其他用户登录信息

I'm trying to study FOSUserBundle in Symfony. I searched on google "how to check if other users are logged into their account", but I failed to do it. I want to add a green coloured mark if a specific user is logged in, the way Facebook does it.

I don't know if FOSUserBundle has a code that will check whether a user is logged in. I found this (other question on SOF) but it only checks if the current user is logged in.

I don't know it's a good idea to add this property in my entity

   /**
     *
     * @ORM\Column(name="log_status", type="boolean", nullable=true)
     */
    protected $logStatus;

This will set the status of a user (logged in or not) and I'll add a column to the fos_user table to save it to the database.

  • 写回答

2条回答 默认 最新

  • doushi8231 2017-07-31 09:41
    关注

    To tackle this issue, you would first need to define what logged in really means in your case. Because your code is normally only called once per request, the user can be gone 5 seconds after that, or he can have the page opened for an hour, but in both cases the user might still be logged in in the session.

    So what you probably want to do is checking if the user is currently active. There are multiple ways to do this, and depending on how real-time the information has to be, you have to choose the best option for you.

    Easiest (imho) would be to ping every X seconds to the server with an AJAX call (Polling or Long-Polling), and than make a ruling on how long before the status will change to offline. There should be some rome for the AJAX call to fail.

    Other options, which will give you a more real-time overview would be to use either WebSockets, or Server Sent Events.

    There might be other options, like using a service like PubNub to handle the connections, and use their API to determine if a user gets inactive. But that you would need to figure out for yourself.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失