/**
  * Purges all remember tokens for a single user. Effectively logs
  * a user out of all devices. Intended to allow users to log themselves
  * out of all devices as a security measure.
  *
  * @param $email
  */
 public function purgeRememberTokens($email)
 {
     // Emails should NOT be case sensitive.
     $email = strtolower($email);
     $this->ci->login_model->purgeRememberTokens($email);
     // todo record activity of remember me purges.
     Events::trigger('didPurgeRememberTokens', [$email]);
 }
Ejemplo n.º 2
0
 public function testRemoveUnknownListener()
 {
     $result = false;
     $callback = function () use(&$result) {
         $result = true;
     };
     Events::on('foo', $callback);
     Events::trigger('foo');
     $this->assertTrue($result);
     $result = false;
     $this->assertFalse(Events::removeListener('bar', $callback));
     Events::trigger('foo');
     $this->assertTrue($result);
 }
Ejemplo n.º 3
0
 /**
  * Deletes one or more meta values from a user.
  *
  * @param $user_id
  * @param $key
  *
  * @return bool
  */
 public function removeMetaFromUser($user_id, $key)
 {
     if (!Events::trigger('beforeRemoveMetaFromUser', [$user_id, $key])) {
         return false;
     }
     if (is_array($key)) {
         $this->db->where_in('meta_key', $key);
     } else {
         $this->db->where('meta_key', $key);
     }
     $this->db->where('user_id', (int) $user_id)->delete('user_meta');
 }
Ejemplo n.º 4
0
 /**
  * Runs all of the tasks (after checking their time, of course...)
  *
  * @param string $alias
  * @return mixed
  */
 public function run($alias = null)
 {
     // Has the system been disabled?
     if (Settings::get('is_disabled', 'cron') == 'y') {
         return CLI::error('The cron system has been disabled. No tasks were run.');
     }
     $force_run = false;
     // Run one task or all?
     if (!empty($alias)) {
         $tasks = \Myth\Cron\CronManager::task($alias);
         if (is_null($tasks)) {
             return CLI::error("Unable to find the task: '{$alias}'.");
         }
         $tasks = [$alias => $tasks];
         $force_run = true;
     } else {
         $tasks = \Myth\Cron\CronManager::tasks();
     }
     if (empty($tasks)) {
         return CLI::write("There are no tasks to run at this time.");
     }
     // We need to be able to check against suspended tasks.
     $suspended = Settings::get('suspended_tasks', 'cron');
     if (!is_array($suspended)) {
         $suspended = array($suspended);
     }
     // Loop over all of our tasks, checking them against the
     // suspended tasks to see if they're okay to run.
     // Collect the output of the actions so that we can make
     // it available to the event (for sending emails and the like)
     $output = '';
     echo CLI::write('Starting Tasks...');
     foreach ($tasks as $alias => $task) {
         if (in_array($alias, $suspended)) {
             echo CLI::write("\t[Suspended] {$alias} will not run until resumed.", 'yellow');
             $output .= "[Suspended] {$alias} will not run until resumed.";
             continue;
         }
         echo CLI::write("\tRunning task: {$alias}...");
         $output .= \Myth\Cron\CronManager::run($alias, $force_run);
     }
     // Give other people a chance to respond.
     echo CLI::write('Done. Firing the event so others can play too...');
     Events::trigger('afterCron', [$output]);
     // And we're out of here boys and girls!
     echo CLI::write('Done');
 }
Ejemplo n.º 5
0
 /**
  * Removes a single permission from a user. Only applies to permissions
  * that have been assigned with addPermissionToUser, not to permissions
  * inherited based on groups they belong to.
  *
  * @param int/string $permission
  * @param int        $user_id
  */
 public function removePermissionFromUser($permission, $user_id)
 {
     $permission_id = $this->getPermissionID($permission);
     if (!is_numeric($permission_id)) {
         return false;
     }
     if (empty($user_id) || !is_numeric($user_id)) {
         return null;
     }
     $user_id = (int) $user_id;
     if (!Events::trigger('beforeRemovePermissionFromUser', [$user_id, $permission])) {
         return false;
     }
     // Grab the existing permissions for this user, and remove
     // the permission id from the list.
     $ci =& get_instance();
     $ci->load->model('User_model');
     $permissions = $ci->user_model->getMetaItem($user_id, 'RBAC_permissions');
     if (!is_array($permissions)) {
         $permissions = [];
     }
     unset($permissions[array_search($permission_id, $permissions)]);
     // Save the updated permissions
     return $ci->user_model->saveMetaToUser($user_id, 'RBAC_permissions', serialize($permissions));
 }