Either update an existing provider record with the newest details
or add this provider to the user.

@param null|\App\Models\User                $user
@param null|\Laravel\Socialite\AbstractUser $socialUser

@return mixed
513181
protected function updateFromProvider($user, $socialUser)
    {
        if (! $user->hasProvider($this->provider->driver)) {
            return $user->addSocial($socialUser, $this->provider->driver);
        }

        return $user->getProvider($this->provider->driver)
            ->updateFromProvider($socialUser, $this->provider->driver);
    }
349851
public function update(ProfileRequest $request, User $user)
    {
        event(new ProfileWasUpdated($request));

        if ($request->wantsJson()) {
            return $this->respondsWithSuccess('ok');
        }

        return back();
    }
1178843
public function encryptUserData(AbstractUser $user)
    {
        // extract the roles
        $roles = $user->getRoles();
        $roleArray = [];
        foreach($roles as $r){
            $roleArray[] = $r->getRole();
        }

        // data (we use short syntax to reduce the size of the cookie or session)
        $data = [
            // username
            'u'   => $user->getUsername(),
            // roles
            'r'   => $roleArray,
            // valid until
            'vu'  => time() + (86400 * 30),
            // session id
            'sid' => $this->httpSession()->getSessionId(),
            // auth provider driver
            'ap'  => $user->getAuthProviderName()
        ];

        // build and add token to $data
        return $this->getCrypt()->encrypt($this->jsonEncode($data), $this->getEncryptionKey());
    }
234987
public function refreshUser(UserInterface $user)
    {
        $username                     = $user->getUsername();
        $this->cachedUsers[$username] = $this->userProvider->refreshUser($user);
        return $this->cachedUsers[$username];
    }
1344725
public function update(User $user, Request $request)
    {
        // user we want to edit and session user must be the same
        if ($user->id != user()->id) {
            return redirect()
                ->back()
                ->withInput($request->all())
                ->withErrors(['firstname' => 'Unauthorized access']);
        }

        // submit without a file
        if (is_null($request->file('photo'))) {
            $this->validate($request, array_except(User::$rulesProfile, 'photo'));
        }
        else {
            $this->validate($request, User::$rulesProfile);

            $photo = $this->uploadProfilePicture($request->file('photo'));

            $request->merge(['image' => $photo]);
        }

        // update user without photo and password
        $this->updateEntry($user, $request->only([
            'firstname',
            'lastname',
            'cellphone',
            'telephone',
            'born_at',
            'image'
        ]));

        // update user  password
        if ($request['password'] && strlen($request['password']) >= 2) {
            user()->update([
                'password' => bcrypt($request['password']),
            ]);
        }

        return redirect('/admin/profile');
    }
253310
public function addUserSocialAccount(User $user, $serviceName, AbstractUser $response)
    {
        $user->has_social_integrations = true;
        $user->save();
        // create relation for new user and social integration
        $this->addSocialRelation($user, $serviceName, $response);
        return $user;
    }
530003
private function createNewToken(AbstractUserInterface $user)
    {
        return new UsernamePasswordToken(
            $user,
            null,
            $this->providerKey,
            $user->getRoles()
        );
    }
172711
public function addUser($user)
    {
        if (!$this->hasUser($user)) {
            return RoleUser::create(['role_id' => $this->id, 'user_id' => $user->id]);
        }

        return false;
    }
458717
public function update(UpdateUserRequest $request, User $user)
    {
        $this->authorize(UsersPolicy::PERMISSION_UPDATE);

        $user->update($request->getValidatedData());
        $user->roles()->sync($request->get('roles'));

        $this->transNotification('updated', ['name' => $user->full_name], $user->toArray());

        return redirect()->route('admin::auth.users.show', [$user->hashed_id]);
    }
833582
public function postUpdateUser(User $user)
    {
        $userData = array_filter(Binput::only(['username', 'email', 'password', 'level']));

        try {
            $user->update($userData);
        } catch (ValidationException $e) {
            return cachet_redirect('dashboard.team.edit', [$user->id])
                ->withInput($userData)
                ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.team.edit.failure')))
                ->withErrors($e->getMessageBag());
        }

        return cachet_redirect('dashboard.team.edit', [$user->id])
            ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.team.edit.success')));
    }
941223
public function register(AbstractUserInterface $user)
    {
        parent::register($user);

        /**
         * @var AdminUserInterface $user
         */
        $this
            ->userEventDispatcher
            ->dispatchOnAdminUserRegisteredEvent($user);

        return $this;
    }
698481
public function saveUser($user) {
        global $DB;

        $now = time();
        $isinsert = is_null($user->created);
        $user->updated = $now;

        $params = [
            'ltiresultsourcedid' => $user->ltiResultSourcedId,
            'updated' => $user->updated
        ];

        if ($isinsert) {
            $params['resourcelinkid'] = $user->getResourceLink()->getRecordId();
            $params['ltiuserkey'] = $user->getId(ToolProvider\ToolProvider::ID_SCOPE_ID_ONLY);
            $user->created = $now;
            $params['created'] = $user->created;
            $id = $DB->insert_record($this->userresulttable, (object) $params);
            if ($id) {
                $user->setRecordId($id);
                return true;
            }

        } else {
            $params['id'] = $user->getRecordId();
            return $DB->update_record($this->userresulttable, (object) $params);
        }

        return false;
    }
713963
public function updateRoles(Request $request, User $user)
    {
        $this->authorize('roles', $user);

        $roles = Role::all();

        foreach ($roles as $role) {
            if (array_key_exists($role->id, $request->all())) {
                $role->addUser($user);
            } else {
                $role->deleteUser($user);
            }
        }

        return redirect()->route('laralum::users.index')->with('success', __('laralum_users::general.user_roles_updated', ['id' => $user->id]));
    }
318648
public function edit(User $user)
    {
        return $this->appShellView('user.edit', [
            'user'  => $user,
            'types' => UserTypeProxy::choices(),
            'roles' => RoleProxy::all()
        ]);
    }
1307784
public function setUser(User $user = null): FamilyPermission
    {
        $this->user = $user;
        if ($user && !$user->getFamilyPermissions()->contains($this)) {
            $user->getFamilyPermissions()->add($this);
        }

        return $this;
    }
1091744
public function setUser(\Amulen\UserBundle\Entity\User $user = null)
    {
        $this->user = $user;

        return $this;
    }
533753
public function add( models\VPN\Server\User $user){
        $rest = $this->getService( self::API_VPN_USER);
        $rest->POST( $user);

        return $rest->getResult( models\VPN\Server\User::class);
    }