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

enc*_*nce 11 php laravel cartalyst-sentry

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

现在我正在尝试发生这种情况并让两个用户同时登录.我知道当用户退出时这是一个安全功能,但我的项目情况不是你所说的正常情况.

Gra*_*avy 22

扩展到Nico Kaag对垃圾邮件评论的回答和实施:

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

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

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

...
Run Code Online (Sandbox Code Playgroud)

/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;
    }
}
Run Code Online (Sandbox Code Playgroud)


Nic*_*aag 5

这是可能的,但Sentry本身并不支持.要做到这一点,你必须改变在一些哨兵核心代码,或找到一种方法来覆盖用户类是在哨兵代码.

你需要调整的功能是在用户模式,可以发现"GetPresistCode()":

/vendor/cartalyst/sentry/src/Cartalyst/Sentry/Users/Eloquent/User.php
Run Code Online (Sandbox Code Playgroud)

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

/**
 * 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;
}
Run Code Online (Sandbox Code Playgroud)

我不得不说,我强烈建议你不要改变哨兵的代码,你发现周围的另一种方式,但可能是真的很难.

  • 要扩展Nico的观点,您可以将Sentry指向配置中的自定义User类,然后使用上面的代码从那里覆盖 (3认同)