Laravel:启用 Sentry 用户帐户在多台计算机上使用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17393833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:03:35  来源:igfitidea点击:

Laravel: Enable Sentry user account be used in multiple computers

phplaravelcartalyst-sentry

提问by enchance

While using Sentry in L4, is it possible to make an account be used in multiple computers at the same time? Right now, Sentry logs out the user the moment the same account is used in another computer.

在 L4 中使用 Sentry 时,是否可以在多台计算机上同时使用一个帐户?现在,Sentry 在另一台计算机上使用同一帐户时注销用户。

Right now I'm trying for that notto happen and keep both users logged in at the same time. I know that it's a security feature when a user gets logged out, but my project's circumstances aren't what you'd call normal.

现在我正在努力避免这种情况发生并让两个用户同时登录。我知道当用户注销时这是一项安全功能,但我的项目情况不是你所说的normal

回答by Gravy

Extension to Nico Kaag's answer and implementation of spamoom's comment:

Nico Kaag 的回答和 spamoom 评论的扩展:

/app/config/packages/cartalyst/sentry/config.php

/app/config/packages/cartalyst/sentry/config.php

...
    // Modify users array to point to custom model.    

'users' => array(
    'model' => 'User',
    'login_attribute' => 'email',
),    

...

/app/models/User.php

/app/models/User.php

use Cartalyst\Sentry\Users\Eloquent\User as SentryUser;

class User extends SentryUser
{

    ...

    ...

    // Override the SentryUser getPersistCode method.

    public function getPersistCode()
    {
        if (!$this->persist_code)
        {
            $this->persist_code = $this->getRandomString();

            // Our code got hashed
            $persistCode = $this->persist_code;

            $this->save();

            return $persistCode;            
        }
        return $this->persist_code;
    }
}

回答by Nico Kaag

It is possible, but not supported by Sentry itself. To do this, you have to change some core code in Sentry, or find a way to override the User class that's in the Sentry code.

这是可能的,但 Sentry 本身不支持。为此,您必须更改 Sentry 中的一些核心代码,或者找到一种方法来覆盖 Sentry 代码中的 User 类。

The function you need to adjust is "GetPresistCode()" in the User model, which can be found in:

需要调整的函数是User模型中的“GetPresistCode()”,可以在:

/vendor/cartalyst/sentry/src/Cartalyst/Sentry/Users/Eloquent/User.php

And this is how the function should look like (not tested):

这就是该函数的外观(未测试):

/**
 * Gets a code for when the user is
 * persisted to a cookie or session which
 * identifies the user.
 *
 * @return string
 */
public function getPersistCode()
{
    if (!$this->persist_code) {
        $this->persist_code = $this->getRandomString();

        // Our code got hashed
        $persistCode = $this->persist_code;

        $this->save();

        return $persistCode;
    }
    return $this->persist_code;
}

I have to say that I highly recommend you don'tchange the code in Sentry, and that you find another way around, but that might be really hard.

我不得不说,我强烈建议您不要更改 Sentry 中的代码,并且您会找到另一种方法,但这可能真的很难。