Search the authenticated user for his user groups/roles and add
their roles to the hash map with the roles.

@param string $user   the authenticated user
@param string $userDN the DN of the authenticated user

@return void
774887
protected function rolesSearch($user, $userDN)
    {

        // query whether or not roles DN or filter has been set
        if ($this->rolesDN === null || $this->roleFilter === null) {
            return;
        }

        // load the default group name and the LDAP connection
        $groupName = Util::DEFAULT_GROUP_NAME;
        $ldapConnection = $this->ldapConnect();

        // replace the {0} placeholder with the username of the user
        $this->roleFilter = preg_replace("/\{0\}/", "$user", $this->roleFilter);

        // replace the {1} placeholder with the distiniguished name of the user
        $this->roleFilter = preg_replace("/\{1\}/", "$userDN", $this->roleFilter);

        // search for the roles using the roleFilter and get the first entry
        $search = ldap_search($ldapConnection, $this->rolesDN, $this->roleFilter);
        $entry = ldap_first_entry($ldapConnection, $search);

        do {
            // get the distinguished name of the entry and extract the common names out of it
            $dn = ldap_get_dn($ldapConnection, $entry);
            $roleArray = $this->extractCNFromDN($dn);

            // add every returned CN to the roles
            foreach ($roleArray as $role) {
                $this->addRole($groupName, $role);
            }

            // continue as long as there are entries still left from the search
        } while ($entry = ldap_next_entry($ldapConnection, $entry));
    }
156252
public function setAdminRole($user) {
    $classes = $this->loadClasses();

    $auth = Yii::$app->authManager;
    $auth->revokeAll($user->id);

    foreach ($classes as $item) {
      foreach ($item->adminRoles() as $role) {
        $auth->assign($auth->getRole($role), $user->id);
      }
    }

  }
710903
public function activateUser(User $user)
    {
        $user->setIsEnabled(true);
        $user->setIsMailValidated(true);
        $user->setResetPasswordHash(null);
        $user->setInitDate(new \DateTime());

        $this->objectManager->persist($user);
        $this->objectManager->flush();
    }
14335
public static function get_users_in_context(userlist $userlist) {
        $context = $userlist->get_context();

        if (!$context instanceof \context_user) {
            return;
        }

        $userlist->add_user($context->instanceid);
    }
421324
protected function setUser(array $userData, & $user = null)
    {
        // Generic birthdate parsing
        $user->birthday = date('Y-m-d H:i:s', strtotime($user->birthday));

        // If no external user is passed set as current user
        if (isset($user)) {
            $this->user = & $user;
        }
    }
363722
private function getRoles(UserInterface $user, TokenInterface $token)
    {
        $roles = $user->getRoles();

        foreach ($token->getRoles(false) as $role) {
            if ($role instanceof SwitchUserRole) {
                $roles[] = $role;

                break;
            }
        }

        return $roles;
    }
984294
protected function setUserInfo($user, $password = null)
    {
        $this->userInfo = $user . ((null !== $password) ? (':' . $password) : '');
    }
782412
public function login( UserData $user ) {
		// clear session
		foreach ( $_SESSION as $key => $value ) {
			unset( $_SESSION[$key] );
		}

		// generate new session id
		session_regenerate_id( true );

		// store user info in session
		$this->setUser( $user );
	}
1360391
protected function loadUser($defName, $userOrganization, $userName)
    {
        $definition = $this->getUserDefinition($defName);

        $values = $definition->getUserData($userName, $userOrganization);
        // \MUtil_Echo::track($defName, $login_name, $userOrganization, $values);

        $values = $this->ensureDefaultUserValues($values, $definition, $defName);
        // \MUtil_Echo::track($values, $userName, $userOrganization, $defName);

        return $this->_loadClass('User', true, array($values, $definition));
    }
1296413
public function addUser(UserInterface $user)
    {
        $this->users->add($user);

        if ($user->hasRole($this) === false)
            $user->addRole($this);

        return $this;
    }
851114
public function roles(User $user)
    {
        if ($this->session->hasValue(Roles::SESSION_KEY)) {
            return $this->session->value(Roles::SESSION_KEY);
        }

        $roles = $this->authorizationProvider->roles($user);
        $this->session->putValue(Roles::SESSION_KEY, $roles);
        return $roles;
    }
1149478
public function addUser($username, $password, array $roles)
    {
        $this->userProvider->createUser(new User($username, $password, $roles));
    }
330831
function addAllowUser($user, $password)
    {
        $this->userList[$user] = $password;
        $this->verifyUser = true;
    }
1162958
public function manageRoles(User $user)
    {
        $this->authorize('roles', $user);

        $roles = Role::all();

        return view('laralum_users::roles', ['user' => $user, 'roles' => $roles]);
    }
73005
private function addAllRolesToUser($user)
    {
        // only 2 - to 5 are needed
        $roles = Role::whereBetween('id', [2, 7])
            ->pluck('keyword', 'id')
            ->values();

        $user->syncRoles($roles);
    }
196368
public function requestNewPassword(User $user)
    {
        $user->setPasswordRequestedAt(new \DateTime());
        $user->resetAuthenticationToken();
        $user->setEmailSent(false);
        $this->save($user);
    }
642897
public function addUser($groupName, $username)
    {
        $groupDn = $this->dn($groupName);

        $userDn = $this->adldap->user()->dn($username);

        if ($groupDn && $userDn) {
            $add['member'] = $userDn;

            return $this->connection->modAdd($groupDn, $add);
        }

        return false;
    }