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.

图片转代码服务由CSDN问答提供 功能建议

我正在尝试在Symfony中学习 FOSUserBundle 。 我搜索谷歌“如何检查其他用户是否登录到他们的帐户”,但我没有这样做。 我希望在特定用户登录时添加绿色标记,就像Facebook一样。

我不知道 FOSUserBundle 是否有代码 这将检查用户是否已登录。我发现了这一点(关于SOF的其他问题)但它只检查当前用户是否已登录。

我不知道这是一个好主意 在我的实体中添加此属性

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

这将设置用户的状态(登录与否),我将添加一列到 fos_user表将其保存到数据库中。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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.

    解决 无用
    打赏 举报
  • dongxian0320 2017-07-31 09:25

    adding that field it's good know you can just go a query to find user that status its true
    but the probleme its how to keep update this data you can't do that by symfony
    for me i use a ping evry X min like Heartbeat to see if user its Active you can use

    解决 无用
    打赏 举报

相关推荐 更多相似问题