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 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题