Save role to [[\yii\rbac\authManager]]
@return boolean
494090
public function save()
    {
        if ($this->validate()) {
            $manager = Configs::authManager();
            if ($this->_item === null) {
                if ($this->type == Item::TYPE_ROLE) {
                    $this->_item = $manager->createRole($this->name);
                } else {
                    $this->_item = $manager->createPermission($this->name);
                }
                $isNew = true;
            } else {
                $isNew = false;
                $oldName = $this->_item->name;
            }
            $this->_item->name = $this->name;
            $this->_item->description = $this->description;
            $this->_item->ruleName = $this->ruleName;
            $this->_item->data = $this->data === null || $this->data === '' ? null : Json::decode($this->data);
            if ($isNew) {
                $manager->add($this->_item);
            } else {
                $manager->update($oldName, $this->_item);
            }
            Helper::invalidate();
            return true;
        } else {
            return false;
        }
    }
1255716
public function save()
    {
        if ($this->validate()) {
            $this->user->scenario = 'settings';
            $this->user->username = $this->username;
            $this->user->nickname = $this->nickname;
            $this->user->password = $this->new_password;
            if ($this->email == $this->user->email && $this->user->unconfirmed_email != null) {
                $this->user->unconfirmed_email = null;
            } elseif ($this->email != $this->user->email) {
                switch (Yii::$app->settings->get('emailChangeStrategy','user')) {
                    case UserSettings::STRATEGY_INSECURE:
                        $this->insecureEmailChange();
                        break;
                    case UserSettings::STRATEGY_DEFAULT:
                        $this->defaultEmailChange();
                        break;
                    case UserSettings::STRATEGY_SECURE:
                        $this->secureEmailChange();
                        break;
                    default:
                        throw new \OutOfBoundsException('Invalid email changing strategy');
                }
            }
            return $this->user->save();
        }
        return false;
    }
1365853
public function create()
    {
        if ($this->scenario != self::SCENARIO_CREATE) {
            return false;
        }

        if (!$this->validate()) {
            return false;
        }

        $rule = \Yii::createObject([
            'class' => $this->class,
            'name'  => $this->name,
        ]);
        
        $this->authManager->add($rule);
        $this->authManager->invalidateCache();
        
        return true;
    }
974744
public static function getSavedRoutes()
    {
        $result = [];
        foreach (Yii::$app->getAuthManager()->getPermissions() as $name => $value) {
            if ($name[0] === '/' && substr($name, -1) != '*') {
                $result[] = $name;
            }
        }

        return $result;
    }
865262
public function isLoggedIn()
    {
        $roleModel = new \erdiko\users\models\Role;
        $roleGeneral = $roleModel->findByName('user');

		// @todo update exception message for clarity
        if (empty($roleGeneral)){
            throw  new \Exception('Error, role user not found.');
        }

		return ( ( $this->_user->getId() > 0 ) && ( $this->_user->getRole() !== $roleGeneral->getId() ) );
	}
577465
public function loggedIn()
    {
        if (parent::loggedIn()) {
            $account = new Account($_SESSION[ 'account' ]);

            if ($user = models('users')->findWhere(['username' => $account->username], 1)) {
                // Store Account Profile
                if ($profile = $user->profile) {
                    $account->store('profile', $profile);
                }

                // Store Account Role
                if ($role = $user->role) {
                    $account->store('role', new Role([
                        'label'       => $role->label,
                        'description' => $role->description,
                        'code'        => $role->code,
                        'authorities' => $role->authorities,
                    ]));
                }
            }
            
            // Store Globals Account
            globals()->store('account', $account);

            // Store Presenter Account
            if (services()->has('view')) {
                presenter()->store('account', $account);
            }

            return true;
        }

        return false;
    }
53896
public function actionPermissionForRole()
    {
        $rr = new RequestResponse();

        if (!$permissionName = \Yii::$app->request->post('permissionName')) {
            $rr->success = false;
            $rr->message = "Некорректные параметры";
            return $rr;
        }

        $permission = \Yii::$app->authManager->getPermission($permissionName);
        if (!$permission) {
            $rr->success = false;
            $rr->message = "Привилегия не найдена";
            return $rr;
        }

        $rolesValues = (array)\Yii::$app->request->post('roles');
        ///$rolesValues[] = CmsManager::ROLE_ROOT; //у root пользователя нельзя отобрать права

        foreach (\Yii::$app->authManager->getRoles() as $role) {
            if (in_array($role->name, $rolesValues)) {
                if (!\Yii::$app->authManager->hasChild($role, $permission)) {
                    \Yii::$app->authManager->addChild($role, $permission);
                }
            } else {
                if (\Yii::$app->authManager->hasChild($role, $permission)) {
                    \Yii::$app->authManager->removeChild($role, $permission);
                }
            }

            $rr->message = "Права доступа сохранены";
            $rr->success = true;
        }

        return $rr;
    }
1326436
public function change()
    {
        if ($this->validate()) {
            /* @var $user User */
            $user = Yii::$app->user->identity;
            $user->setPassword($this->newPassword);
            $user->generateAuthKey();
            if ($user->save()) {
                return true;
            }
        }

        return false;
    }
697570
public function roleSave(Role $role)
    {
        if ($role->role_id) {
            $query = "
                UPDATE
                    auth_role
                SET
                    `name` = :name, description = :description, updated_on = " . $this->sql_time_func . "
                WHERE
                    role_id = :role_id
            ";
        } else {
            $query = "
                INSERT INTO auth_role
                    (name, description, added_on, updated_on)
                VALUES
                    (:name, :description, " . $this->sql_time_func . ", " . $this->sql_time_func . ")
            ";
        }
        $cur = $this->db->prepare($query);
        $cur->bindParam(":name", $role->name, PDO::PARAM_STR, 32);
        $cur->bindParam(":description", $role->description, PDO::PARAM_STR);
        if ($role->role_id) {
            $cur->bindParam(":role_id", $role->role_id, PDO::PARAM_INT);
        }
        $this->db->beginTransaction();
        try {
            $cur->execute();
            if (!$role->role_id) {
                $role->role_id = (int)$this->db->lastInsertId();
            }
            $this->db->commit();
        } catch (PDOException $db_err) {
            $this->db->rollBack();
            if ($this->logger) {
                $this->logger->error("Failed to save role to DB", ['exception' => $db_err]);
            }
            return false;
        }
        foreach ($role->getPermissions() as $permission) {
            // TODO: Something on fail
            $this->rolePermissionAdd($role, $permission);
        }

        return true;
    }
957717
public function actionView()
    {
        $model = $this->model;
        $id = $model->name;
        $model = $this->findModel($id);
        $authManager = Yii::$app->getAuthManager();
        $avaliable = $assigned = [
            'Roles' => [],
            'Permission' => [],
            'Routes' => [],
        ];
        $children = array_keys($authManager->getChildren($id));
        $children[] = $id;
        foreach ($authManager->getRoles() as $name => $role) {
            if (in_array($name, $children)) {
                continue;
            }
            $avaliable['Roles'][$name] = $name . ' — ' . $role->description;
        }
        foreach ($authManager->getPermissions() as $name => $role) {
            if (in_array($name, $children)) {
                continue;
            }

            if (isset($name[0])) {
                $avaliable[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name . ' — ' . $role->description;
            }
        }
        foreach ($authManager->getChildren($id) as $name => $child) {
            if ($child->type == Item::TYPE_ROLE) {
                $assigned['Roles'][$name] = $name . ' — ' . $child->description;
            } else {
                if (isset($name[0])) {
                    $assigned[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name . ' — ' . $child->description;
                } else {
                    $assigned['Permission'][$name] = $name . ' — ' . $child->description;
                }
            }
        }
        $avaliable = array_filter($avaliable);
        $assigned = array_filter($assigned);
        return $this->render('view', ['model' => $model, 'avaliable' => $avaliable, 'assigned' => $assigned]);
    }
1050066
protected function applyRole(array $data)
    {
        if (!($name = ArrayHelper::get($data, 'name'))) {
            return false;
        }
        if ($role = $this->authManager->getRole($name)) {
            return $role;
        }
        $role = $this->authManager->createRole($name);
        $role->description = ArrayHelper::get($data, 'description', '');
        if ($this->authManager->add($role)) {
            return $role;
        }
        return false;
    }
1201341
public function actionAsync()
    {
        if (($lockout = $this->sessionBruteForceLock())) {
            return $this->sendArray(false, [Module::t('login_async_submission_limit_reached', ['time' =>  Yii::$app->formatter->asRelativeTime($lockout)])]);
        }
        
        // get the login form model
        $model = new LoginForm();
        $model->allowedAttempts = $this->module->loginUserAttemptCount;
        $model->lockoutTime = $this->module->loginUserAttemptLockoutTime;
        
        $loginData = Yii::$app->request->post('login');
        Yii::$app->session->remove('secureId');
        // see if values are sent via post
        if ($loginData) {
            $model->attributes = $loginData;
            if (($userObject = $model->login()) !== false) {
                // see if secure login is enabled or not
                if ($this->module->secureLogin) {
                    // try to send the secure token to the given user email store the token in the session.
                    if ($model->sendSecureLogin()) {
                        Yii::$app->session->set('secureId', $model->getUser()->id);
                        return $this->sendArray(false, [], true);
                    }
                    
                    return $this->sendArray(false, ['Unable to send and store secure token.']);
                }
                
                if (Yii::$app->adminuser->login($userObject)) {
                    return $this->sendArray(true);
                }
            }
        }

        return $this->sendArray(false, $model->getErrors(), false);
    }
529574
public function save()
    {
        if (!empty($this->ltiResultSourcedId) && !is_null($this->resourceLink)) {
            $ok = $this->resourceLink->getConsumer()->getStorage()->userSave($this);
        } else {
            $ok = true;
        }

        return $ok;
    }
500980
public function authRoleDelete()
    {
        $roleCount = AuthRoleUser::where(['role_id'=>$this->id])->count();
        if($roleCount > 0){
            return "已有{$roleCount}用户在是有此角色不可删除";
        }

        if($this->delete()){
            if($this->authAccess){
                AuthAccess::where(['role_id'=>$this->id,'type'=>'admin_url'])->delete();
            }
            return true;
        }
        return false;
    }
190153
public function save()
    {
        if ($this->validate()) {
            $manager = Configs::authManager();
            $class = $this->className;
            if ($this->_item === null) {
                $this->_item = new $class();
                $isNew = true;
            } else {
                $isNew = false;
                $oldName = $this->_item->name;
            }
            $this->_item->name = $this->name;

            if ($isNew) {
                $manager->add($this->_item);
            } else {
                $manager->update($oldName, $this->_item);
            }

            return true;
        } else {
            return false;
        }
    }
1198337
public function actionDeleteRole ()
		{

			$auth = Yii::$app->getAuthManager();
			$role = $auth->getRole(Yii::$app->request->get('id'));
			$auth->remove($role);
			$url = Yii::$app->request->referrer . '#roles';
			Yii::$app->response->redirect($url);

			Yii::$app->end();
		}
978376
public function getRolesNames ()
		{
			$auth = Yii::$app->getAuthManager();
			$rolesByUser = $auth->getRolesByUser($this->id);
			$roles = ArrayHelper::objectsAttribute($rolesByUser, 'name');

			return $roles;
		}