Create a user and assign roles to it.

@param array $data
@param array $users
349463
public function updateWithUsers(array $data, $users, $id)
    {
        $role = $this->update((array) $data, $id);

        if (! empty($users)) {
            $role->users()->sync($users);
        } else {
            $role->users()->detach();
        }
    }
286378
private function createUsers()
    {
        if($this->option('users')
            || $this->option('users_per_role')
            || $this->option('all')
        ) {

            $this->comment('Creating dummy users...');
            $output = (new \UserSeeder())
                ->setCommand($this)
                ->run(
                    $this->getDefaultOption('users'),
                    $this->getDefaultOption('users_per_role'),
                    $this->getDefaultOption('role_id')
                );
            $this->info($output);
        }
        return $this;
    }
124768
protected function createDefaultUser()
    {
        // Get the user configuration data.
        $config = $this->user;

        // Create default permission.
        $this->permissionRepository->create([
          'name' => 'Administrator (Full Access)',
          'slug' => 'admin',
        ], false);

        // Create default role.
        $this->roleRepository->create([
          'name' => 'Registered',
          'slug' => 'registered',
        ], false);

        // Create the admin role.
        $role = $this->roleRepository->create([
          'name'        => 'Administrator',
          'slug'        => 'administrator',
          'permissions' => [
            'admin' => true,
          ],
        ], false);

        // Create the user.
        $user = $this->authRepository->registerAndActivate([
          'email'      => array_get($config, 'email'),
          'first_name' => array_get($config, 'first'),
          'last_name'  => array_get($config, 'last'),
          'password'   => array_get($config, 'pass'),
          'role'       => 'administrator',
        ], false);

        // Attach user to admin role.
        $role->users()
             ->attach($user);
    }
793819
public function update($username, array $data) {
        $cond = array();
        unset($data[$this->params['id']]);
		unset($data[$this->params['password']]);

        if($this->params['token']) {
            unset($data[$this->params['token']]);
        }

        if($this->params['created']) {
            unset($data[$this->params['created']]);
        }

        if($this->params['last_login']) {
            unset($data[$this->params['last_login']]);
        }


        foreach($data as $k => $v) {
            $cond[] = sprintf("`%s` = %s", str_replace(array('\\',"\0" ,'`'), '', $k), $this->pdo->quote($v));
        }


        if(is_numeric($username)) {
            $key = 'id';
        }
        else {
            $key = 'username';
        }

        $query = sprintf(self::UPDATE_QUERY,
            $this->params['table'],
            implode(', ', $cond),
            $this->params[$key],
            $this->pdo->quote($username));

        $stmt = $this->pdo->query($query);

        if($stmt === FALSE) {
            throw new UserException(json_encode($this->pdo->errorInfo()));
        }

    }
1192997
public function mapRoleAssignments(array $data)
    {
        $roleAssignmentData = array();
        foreach ($data as $row) {
            $id = (int)$row['id'];
            $roleId = (int)$row['role_id'];
            $contentId = (int)$row['contentobject_id'];
            // if user already have full access to a role, continue
            if (isset($roleAssignmentData[$roleId][$contentId])
              && $roleAssignmentData[$roleId][$contentId] instanceof RoleAssignment) {
                continue;
            }

            $limitIdentifier = $row['limit_identifier'];
            if (!empty($limitIdentifier)) {
                $roleAssignmentData[$roleId][$contentId][$limitIdentifier][$id] = new RoleAssignment(
                    array(
                        'id' => $id,
                        'roleId' => $roleId,
                        'contentId' => $contentId,
                        'limitationIdentifier' => $limitIdentifier,
                        'values' => array($row['limit_value']),
                    )
                );
            } else {
                $roleAssignmentData[$roleId][$contentId] = new RoleAssignment(
                    array(
                        'id' => $id,
                        'roleId' => $roleId,
                        'contentId' => $contentId,
                    )
                );
            }
        }

        $roleAssignments = array();
        array_walk_recursive(
            $roleAssignmentData,
            function ($roleAssignment) use (&$roleAssignments) {
                $roleAssignments[] = $roleAssignment;
            }
        );

        return $roleAssignments;
    }
722389
public function createAccount($userNames)
    {
        if (!is_array($userNames)) {
            $userNames = array($userNames);
        }

        foreach ($userNames as $userName) {
            if (empty($userName)) {
                continue;
            }

            if (!in_array($userName, $this->getLocalAccounts())) {

                //Do a sanity check
                if ($this->userNameExists($userName) === false) {

                    try {
                        $userId = wp_insert_user(
                            array(
                                'user_login' => $userName,
                                'user_pass' => wp_generate_password(),
                                'user_nicename' => $userName,
                                'user_email' => $this->createFakeEmail($userName),
                                'user_registered' => date('Y-m-d H:i:s'),
                                'role' =>  $this->defaultRole
                            )
                        );
                    } catch (\Exception $e) {
                        error_log("Error: Could not create a new user using bulk data (ad-api-integration).");
                    }

                } else {
                    $userId = null;
                }

                if (is_numeric($userId)) {
                    $this->setUserRole($userId);
                }
            }
        }
    }
990351
public function setRoleToUsers( core_kernel_classes_Resource $role, $users = array())
    {
        $returnValue = (bool) false;
        $userService = tao_models_classes_UserService::singleton();

        $rolesProperty = new core_kernel_classes_Property(GenerisRdf::PROPERTY_USER_ROLES);
    	foreach ($users as $u){
    		$u = ($u instanceof core_kernel_classes_Resource) ? $u : new core_kernel_classes_Resource($u);

    		// just in case of ...
    		$userService->unnatachRole($u, $role);

    		// assign the new role.
    		$u->setPropertyValue($rolesProperty, $role);

    		if (common_session_SessionManager::getSession()->getUserUri() == $u->getUri()) {
    		    common_session_SessionManager::getSession()->refresh();
    		}
    	}

    	$returnValue = true;

        return (bool) $returnValue;
    }
870946
public function assignTasksRoles(array $roles)
    {
        foreach ($roles as $roles => $tasks) {
            $tasks = (array) $tasks;
            $roles = (array) $roles;

            foreach ($tasks as $task) {
                $this->builder->buildTask($task)->addRoles($roles);
            }
        }
    }
1009795
public function createUserFromOAuth($data)
    {
        $user = $this->createUser();
        $user->setAuthDataByProvider($data['provider'], ['id' => $data['id'], 'token' => $data['token']]);
        $user->setAuthProvider($data['provider']);
        $user->setFirstAuthProvider($data['provider']);
        $user->setUsername($data['email']);
        $user->setEmail($data['email']);
        $user->setPassword('none');
        $user->setEnabled(true);
        $user->setContact(new Contact);

        return $user;
    }
290656
public void setUsers(Set<PrincipalUser> users) {
        SystemAssert.requireArgument(users != null && !users.isEmpty(), "Users associated with a namespace cannot be null or empty.");
        this.users.clear();
        if (users != null && !users.isEmpty()) {
            this.users.addAll(users);
        }
    }
369547
public function assignProfiles($profiles) : void
    {
        $profiles = (array) $profiles;
        foreach ($profiles as $profile) {
            $electedProfile = Profile::where('code', $profile)->first();

            // Profile exists and not assigned to user?
            if (!is_null($electedProfile) && !$this->hasProfile($profile)) {
                // Assign both role and permissions defined for this user profile.
                // Into the Spatie Permissions.
                $this->assignRole(Role::find([$electedProfile->role_id])->first()->name);
                $this->givePermissionTo(Permission::find([$electedProfile->permission_id])->first()->name);

                // Assign user profile into the profiles table.
                $this->profiles()->save($electedProfile);
            }
        }
    }
145281
public function update(User $user, array $data)
    {
        $user->fill([
            'name'                  => $data['name'],
            'email'                 => $data['email'],
            'birthday_at'           => $data['birthday_at'],
            'gender'                => $data['gender'],
            'locale'                => $data['locale'],
            'city'                  => $data['city'],
            'about'                 => $data['about'],
            'profession'            => $data['profession'],
            'hobbies'               => $data['hobbies'],
            'homepage'              => $data['homepage'],
            'skype'                 => $data['skype'],
            'facebook'              => $data['facebook'],
            'twitter'               => $data['twitter'],
            'main_character'        => $data['main_character'],
            'main_guild'            => $data['main_guild'],
            'favorite_race'         => $data['favorite_race'],
            'favorite_class'        => $data['favorite_class'],
            'favorite_spec'         => $data['favorite_spec'],
            'favorite_instance'     => $data['favorite_instance'],
            'favorite_battleground' => $data['favorite_battleground'],
        ]);

        // only fill password if specified
        if (array_key_exists('password', $data)
            && !empty($data['password'])) {
            $user->fill([
                'password' => bcrypt($data['password']),
            ]);
        }

        return $user->save();
    }
1282067
private static function activated(array $data, $user)
    {
        $input = array_keys($data);

        $field = $input[0];
        $value = $data[$field];

        if ($user->$field != $value) {
            return false;
        }

        return true;
    }
499089
public static function setUserdata($data = '', $value = NULL)
    {
        if (is_array($data)) {
            foreach ($data as $key => &$value) {
                $_SESSION[$key] = $value;
            }

            return;
        }

        $_SESSION[$data] = $value;
    }
304311
protected function create(array $data)
    {
        $user = UserModel::create($data);
        return User::find($user->id);
    }
309236
public function createRole(array $data = [], $permissionIds = '')
    {
        $model = new Role($this->db);
        $model->data($data);
        try{
            $res = $model->saveRole($permissionIds);
            return $res;
        } catch (Exception $e) {
            throw new Exception($e->getMessage());
        }

    }
1000521
protected function create(array $data)
    {
        $fields = [
            'name'     => $data['name'],
            'email'    => $data['email'],
            'password' => bcrypt($data['password']),
        ];
        if (config('auth.providers.users.field', 'email') === 'username' && isset($data['username'])) {
            $fields['username'] = $data['username'];
        }
        return User::create($fields);
    }