Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Flatroy/302cf74d645b44e8a699 to your computer and use it in GitHub Desktop.

Select an option

Save Flatroy/302cf74d645b44e8a699 to your computer and use it in GitHub Desktop.

Revisions

  1. @maid450 maid450 renamed this gist Jul 10, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @maid450 maid450 renamed this gist Jul 10, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @maid450 maid450 revised this gist Feb 17, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.aw
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ Auth::instance()->logged_in('admin') // for current user

    //Check whether some other user has a role
    // Load the role
    $role = ORM::factory('role', array('name' => 'admin));
    $role = ORM::factory('role', array('name' => 'admin'));
    // Check that the user has the given role
    $status = $user->has('roles', $role);

  4. @maid450 maid450 revised this gist Feb 17, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.aw
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    //Useful code snippets
    //Here are some code snippets which show you the basics of Auth:

    @@ -37,4 +38,4 @@ $user->remove('roles', ORM::factory('role')->where('name', '=', 'admin')->find()
    // find all the reviewer users in order of their username
    $role = ORM::factory('role')->where('name', '=', 'reviewer')->find();
    $users = $role->users->order_by('username', 'DESC')->find_all();
    foreach($users as $user) {...}
    foreach($users as $user) {...}
  5. @maid450 maid450 created this gist Feb 17, 2012.
    40 changes: 40 additions & 0 deletions gistfile1.aw
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    //Useful code snippets
    //Here are some code snippets which show you the basics of Auth:

    //Create a new user (e.g. if you have not set up any users yet and want to do that programmatically)
    $model = ORM::factory('user');
    $model->values(array(
    'username' => 'admin',
    'email' => '[email protected]',
    'password' => 'admin',
    'password_confirm' => 'admin',
    ));
    $model->save();
    // remember to add the login role AND the admin role
    // add a role; add() executes the query immediately
    $model->add('roles', ORM::factory('role')->where('name', '=', 'login')->find());
    $model->add('roles', ORM::factory('role')->where('name', '=', 'admin')->find());


    //Check whether current user has a role
    Auth::instance()->logged_in('admin') // for current user

    //Check whether some other user has a role
    // Load the role
    $role = ORM::factory('role', array('name' => 'admin));
    // Check that the user has the given role
    $status = $user->has('roles', $role);

    //Add a role to a user
    // add() executes the query immediately, and saves the data (unlike the KO2 docs say)
    $user->add('roles', ORM::factory('role')->where('name', '=', 'admin')->find());

    //Remove a role from a user
    // remove() executes the query immediately
    $user->remove('roles', ORM::factory('role')->where('name', '=', 'admin')->find());

    //Retrieve all users that have a particular role
    // find all the reviewer users in order of their username
    $role = ORM::factory('role')->where('name', '=', 'reviewer')->find();
    $users = $role->users->order_by('username', 'DESC')->find_all();
    foreach($users as $user) {...}