I looked around and found some Laravel 4 authentication manuals using Sentry or Confide and Entrust . Which are good, but a little vague for me, I'm starting a Laravel newbie, and this is my first base.
Does anyone know any tutorial or recommendations for implementing user authentication with user roles.
Here is what I am trying to do. - Internal website for work. Where writers can enter and post articles. - Admins can iterate over these articles. - These articles are not publicly available, so no one sees them. - Writers cannot see each otherβs articles, but admins have access to everything.
I'm just looking for a tutorial on the role of users and how to implement them.
Edit
This is what I ended up doing.
After installing Sentry in the order specified by @ Antonio Carlos Ribeiro .
I had users, groups, and several other tables (I just needed to use users and groups).
Here is my seeder that I originally used to create users and groups. It can be made more efficient, but for those who just want to get started, it will work.
class SentrySeeder extends Seeder { public function run() { DB::table('users')->delete(); DB::table('groups')->delete(); DB::table('users_groups')->delete(); Sentry::getUserProvider()->create(array( 'email' => ' admin@admin.com ', 'password' => "admin", 'first_name' => 'John', 'last_name' => 'McClane', 'activated' => 1, )); Sentry::getUserProvider()->create(array( 'email' => ' user@user.com ', 'password' => "user", 'first_name' => 'Saad', 'last_name' => 'Kabir', 'activated' => 1, )); Sentry::getUserProvider()->create(array( 'email' => ' jack@user.com ', 'password' => "user", 'first_name' => 'Jack', 'last_name' => 'Doe', 'activated' => 1, )); Sentry::getUserProvider()->create(array( 'email' => ' jon@user.com ', 'password' => "user", 'first_name' => 'Jon', 'last_name' => 'Doe', 'activated' => 1, )); Sentry::getGroupProvider()->create(array( 'name' => 'Admin', 'permissions' => array('admin' => 1), )); Sentry::getGroupProvider()->create(array( 'name' => 'Writer', 'permissions' => array('writer' => 1), ));
}
After adding the initial users, I used the form to add new users, so in my controller I had something like this. Again, this is only for studying / testing the structure, the original implementation is very different. But for testing purposes this should work.
Assuming you have a form that obeys the function of the @ controller, you could have something like this,
$user = Sentry::getUserProvider()->create(array( 'email' => Input::get('email'), 'password' => Input::get('password'), 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'activated' => 1, )); $writerGroup = Sentry::getGroupProvider()->findByName('writer'); $user->addGroup($writerGroup);
You can find rest in the documentation of Sentry: Sentry Docs
Feel free to edit this question to make it more informative or add new examples.