/** * Непосредственно привязка роли к юзеру * * @param $userid * * @return bool|string */ public function userAssign($userid) { $role = $this->getItem($this->forassign, self::TYPE_ROLE); $oldroles = $this->_authMan->getRolesByUser($userid); $this->_authMan->revokeAll($userid); try { if ($this->beforeAssign($userid, $role, $oldroles)) { $this->_authMan->assign($role, $userid); $this->afterAssign($userid, $role, $oldroles); return true; } else { return false; } } catch (\yii\base\Exception $e) { foreach ($oldroles as $orole) { $this->_authMan->assign($orole, $userid); } return RbacModule::t('simplerbac', 'Can`t assign this item for this user'); } }