cartalyst / sentinel

A framework agnostic authentication & authorization system.
BSD 3-Clause "New" or "Revised" License
1.51k stars 238 forks source link

Can I use custom users table (for example of other CMS)? #522

Open ChefMC opened 4 years ago

ChefMC commented 4 years ago

I have my own users database from one game. Can I use this existing users database table and authorize players on web-site via Sentinel as framework (for auth, sessions/cookie mechanism, remember me feature, XSS/CSRF protection)?

rscarpim commented 4 years ago

That's a wonderful question, also I would like if there's any chance to add more field's to the table user, and off-course control those fields?

sabas commented 4 years ago

You need to make your user tables compatible with the classes in src/Users I think, by replacing or extending them.

Adding other fields you can do, I extended EloquentUser, example:

class User extends \Cartalyst\Sentinel\Users\EloquentUser
{
    protected $fillable = [
        'email',
        'password',
        'last_name',
        'first_name',
        'permissions',
        'company',
        'department',
        'title',
        'phone',
        'mobile',
        'manager'
    ];

    protected $loginNames = ['email'];
}

Then I added the configuration (which is the same file from src/config/config.php with changes) before starting the instance

$config = new Cartalyst\Sentinel\Native\ConfigRepository(__DIR__.'/src/customSentinelConfig.php');
$bootstrapper = new Cartalyst\Sentinel\Native\SentinelBootstrapper($config);
Sentinel::instance($bootstrapper);