public function can_be($method, \System\User $user)
 {
     $member = \Impro\Team\Member::get_first()->where(array('id_system_user' => $user->id, 'id_impro_team' => $this->team->id))->fetch();
     if ($method == \System\Model\Perm::BROWSE) {
         return true;
     }
     return $user->is_root() || in_array(ID_MANAGER, $member->roles) || in_array(ID_TRAINER, $member->roles);
 }
Example #2
0
 /** Ask if user has right to do this
  * @param string      $method One of created, browsed
  * @param System\User $user   User to get perms for
  * @return bool
  */
 public static function can_user($method, \System\User $user)
 {
     if ($user->is_root()) {
         return true;
     }
     $cname = get_called_class();
     $conds = array();
     if (isset($cname::$access) && isset($cname::$access[$method]) && !is_null($cname::$access[$method])) {
         return !!$cname::$access[$method];
     }
     if ($user->is_guest()) {
         $conds['public'] = true;
     } else {
         $groups = $user->get_groups();
         if (any($groups)) {
             $conds[] = 'id_group IN (' . implode(',', collect_ids($groups)) . ')';
         }
     }
     $perm = \System\User\Perm::get_first()->add_filter(array('attr' => 'trigger', 'type' => 'in', 'in' => array('model-' . $method, '*')))->add_filter(array('attr' => 'name', 'type' => 'in', 'in' => array(\System\Loader::get_model_from_class($cname) . \System\Loader::SEP_MODEL . $method, '*')))->where($conds)->fetch();
     return $perm ? $perm->allow : static::get_default_for($method);
 }
Example #3
0
 /** Get current active user
  * @return System\User
  */
 public function relogin()
 {
     $cookie = \System\User::COOKIE_USER;
     if ($this->user) {
         return $this->user;
     }
     if ($this->sess($cookie)) {
         $this->user = \System\User::find($this->sess($cookie));
     }
     if (!$this->user) {
         $this->user = \System\User::guest();
     }
     $this->user->get_rights();
 }
Example #4
0
<?php

#[Avatars]
#[Migrate avatar db structure to use new file API]
$users = \System\User::get_all()->fetch();
foreach ($users as $user) {
    if ($user->avatar) {
        $opts = $user->avatar->get_opts();
        if (empty($opts)) {
            $avatar = $user->avatar;
            if (strpos($user->avatar->path, '/') === 0) {
                $user->avatar->path = ROOT . $user->avatar->path;
            }
        } else {
            if (any($opts['file_path'])) {
                $avatar = \System\Image::from_path($opts['file_path']);
                if ($avatar) {
                    $avatar->keep = true;
                }
            } else {
                $avatar = null;
            }
        }
        if (!is_null($avatar)) {
            try {
                $avatar->save();
            } catch (Exception $e) {
                $avatar = null;
            }
        }
        $user->avatar = $avatar;
Example #5
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }