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 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥20 两个不同Subnet的点对点连接
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计