Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: Enable Sentry user account be used in multiple computers

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.

Right now I'm trying for that not to 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.

like image 617
enchance Avatar asked Jun 30 '13 19:06

enchance


2 Answers

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

/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

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;
    }
}
like image 75
Gravy Avatar answered Oct 10 '22 13:10

Gravy


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.

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

/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't change the code in Sentry, and that you find another way around, but that might be really hard.

like image 5
Nico Kaag Avatar answered Oct 10 '22 14:10

Nico Kaag