Updates the users profile image.

@param int $userid the id of the user
@param string $url the url of the image
@return bool|string true if successful, else a string explaining why it failed
420722
public static function update_user_profile_image($userid, $url) {
        global $CFG, $DB;

        require_once($CFG->libdir . '/filelib.php');
        require_once($CFG->libdir . '/gdlib.php');

        $fs = get_file_storage();

        $context = \context_user::instance($userid, MUST_EXIST);
        $fs->delete_area_files($context->id, 'user', 'newicon');

        $filerecord = array(
            'contextid' => $context->id,
            'component' => 'user',
            'filearea' => 'newicon',
            'itemid' => 0,
            'filepath' => '/'
        );

        $urlparams = array(
            'calctimeout' => false,
            'timeout' => 5,
            'skipcertverify' => true,
            'connecttimeout' => 5
        );

        try {
            $fs->create_file_from_url($filerecord, $url, $urlparams);
        } catch (\file_exception $e) {
            return get_string($e->errorcode, $e->module, $e->a);
        }

        $iconfile = $fs->get_area_files($context->id, 'user', 'newicon', false, 'itemid', false);

        // There should only be one.
        $iconfile = reset($iconfile);

        // Something went wrong while creating temp file - remove the uploaded file.
        if (!$iconfile = $iconfile->copy_content_to_temp()) {
            $fs->delete_area_files($context->id, 'user', 'newicon');
            return self::PROFILE_IMAGE_UPDATE_FAILED;
        }

        // Copy file to temporary location and the send it for processing icon.
        $newpicture = (int) process_new_icon($context, 'user', 'icon', 0, $iconfile);
        // Delete temporary file.
        @unlink($iconfile);
        // Remove uploaded file.
        $fs->delete_area_files($context->id, 'user', 'newicon');
        // Set the user's picture.
        $DB->set_field('user', 'picture', $newpicture, array('id' => $userid));
        return self::PROFILE_IMAGE_UPDATE_SUCCESSFUL;
    }
514195
def user_avatar_update(self, userid, payload):
        '''  '''
        response, status_code = self.__pod__.User.post_v1_admin_user_uid_avatar_update(
            sessionToken=self.__session,
            uid=userid,
            payload=payload
        ).result()
        self.logger.debug('%s: %s' % (status_code, response))
        return status_code, response
959459
protected function getUser($userId = null)
    {
        if ($userId === null) {
            /** @var Token $sessionAuth */
            if ($this->session()->isStarted() && $sessionAuth = $this->session()->get('authentication')) {
                return $sessionAuth->getUser();
            }

            return false;
        }
        /** @var Repository\UsersRepository $repo */
        $repo = $this->storage()->getRepository(Entity\Users::class);

        return $repo->getUser($userId);
    }
78598
public function addUserPrefixUrl($url = null) {
		if (empty($url)) {
			return $url;
		}

		$userPrefix = $this->Session->read('Auth.User.prefix');
		if (empty($userPrefix)) {
			return $url;
		}

		if (!is_array($url)) {
			if (($url === '/') || (stripos($url, '/') === false)) {
				return $url;
			}
			$url = Router::parse($url);
		}

		if (isset($url['prefix']) && ($url['prefix'] === false)) {
			$url[$userPrefix] = false;
			if (isset($url['prefix'])) {
				unset($url['prefix']);
			}

			return $url;
		}

		$url[$userPrefix] = true;

		return $url;
	}
1173890
public function update(UserUpdateRequest $request, $id)
    {
        $input = $request->except('roles');

        if ($request->has('password')) {
            $input['password'] = bcrypt($request->password);
        } else {
            unset($input['password']);
        }

        $record = $this->model->findOrFail($id);

        if ($request->has('roles')) {
            $record->syncRoles($request->roles);
        }

        $record->update($input);

        $this->notify([
            'type' => 'success',
            'title' => 'Successful update!',
            'description' => 'This user is updated successfully.',
        ]);

        return redirect()->back();
    }
349851
public function update(ProfileRequest $request, User $user)
    {
        event(new ProfileWasUpdated($request));

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

        return back();
    }
283872
public function edit($userId = null) {

		if ( $this->request->is('post')) {
			unset ( $this->request->data[$this->modelClass]['last_login'] );

			
			$this->SiteUser->bindModel(array(
		        'hasMany' => array(
		            'RolUser' => array(
		                'classname' => 'Users.RolUser',
		            ) 
		        ) 
		    ));

			$rolUser = array();
			if (!empty($this->request->data['Rol']['Rol'])) {
			    	$rolUser[] = array(
			    		'rol_id' => $this->request->data['Rol']['Rol'],
			    		'user_id' => $userId,
			    		);
			

			$this->SiteUser->RolUser->deleteAll(array('RolUser.user_id' => $userId ));

			if ( $this->SiteUser->RolUser->saveMany( $rolUser ) ) {
				$this->Session->setFlash(__d('users', 'User saved'));
			} else {
				$this->Session->setFlash(__d('users', 'Error saving'), 'Risto.flash_error');
			}
		  } else {
		  	$this->Session->setFlash(__d('users', 'Error: no has elegido el rol del usuario, intentelo de nuevo.'), 'Risto.flash_error');
		  }
		  $this->redirect($this->referer());
		}

		if (empty($this->request->data)) {
			$this->SiteUser->recursive = 1;
			$this->request->data = $this->SiteUser->read(null, $userId);
			unset($this->request->data[$this->modelClass]['password']);
		}

		$roles = $this->SiteUser->User->Rol->find('list');
		$this->set(compact( 'roles'));
		$this->render('admin_form');
	}
898027
public function getUserProfilePhotos($userId, $offset = 0, $limit = 100)
    {
        return UserProfilePhotos::fromResponse($this->call('getUserProfilePhotos', [
            'user_id' => (int)$userId,
            'offset' => (int)$offset,
            'limit' => (int)$limit,
        ]));
    }
780883
public function isSatisfiedBy($userId): bool
    {
        try {
            $this->userService->loadUser($userId);

            return true;
        } catch (NotFoundException $e) {
            return false;
        }
    }
1055854
public function update($userId, array $userInfo = [])
    {
        $params = array_merge($userInfo, ['userid' => $userId]);

        return $this->parseJSON('json', [self::API_UPDATE, $params]);
    }
866508
public function getPostUpdateUser($id)
    {
        $loggedInUser = $this->userService->getCurrentLoggedInUser();

        if (!$loggedInUser) {
            $this->response->redirect("user/login");
            return false;
        }

        if ($loggedInUser->id != $id) {
            if (!$loggedInUser->administrator) {
                $this->response->redirect("");
            }
        }

        $title      = "Uppdatera användaren";
        $form       = new UpdateUserForm($this->di, $id);

        $form->check();

        $data = [
            "content" => $form->getHTML(),
        ];

        $this->view->add("default2/article", $data);

        $this->pageRender->renderPage(["title" => $title]);
    }
33625
public function createOrUpdateAuthRecord($userId) {
        $token = $this->_getToken($userId);
        $authPwlessModel = new Model_AuthPasswordless();
        $select = $authPwlessModel->select()->where('user_id = ?', $userId);
        if ($authRecord = $authPwlessModel->fetchRow($select)) {
            $authPwlessModel->update(
                array(
                    'token' => $token,
                    'token_expiration_date' => $this->_getExpirationDate(),
                    'claimed' => 0
                ), 'id = ' . $authRecord->id
            );
            return $token;
        }
        $authPwlessModel->insert(
            array(
                'user_id' => $userId,
                'token' => $token,
                'token_expiration_date' => $this->_getExpirationDate()
            )
        );
        return $token;
    }
1257185
public function updateImage(Request $request, $id)
  {
    if($request->hasFile('avatar'))
    {
      $avatar = $request->file('avatar');
        $user = User::with('profile')->findOrFail($id);
        // REMOVE OLD AVATAR:
        if ($user->profile->avatar != NULL) {
            // DELETE FROM THE DIRECTORY:
            File::delete($user->profile->avatar);
            // DELETE FROM THE DATABASE:
            $user->profile->avatar= null;
        }
      $filename = uniqid() . '.' . $avatar->getClientOriginalExtension();
      if (!File::exists('assets/images/avatars'))
      {
          File::makeDirectory('assets/images/avatars', $mode = 0777, true, true);
      }
      \Image::make($avatar)->resize(320, 240)->save('assets/images/avatars/' . $filename );

      $user->profile->avatar = 'assets/images/avatars/' . $filename;
      $user->profile->file_name = $filename;
      $user->profile->update();
    }
    return \View::make('acl::admin.profiles.profile');
  }
65306
public function updateUser($uid, $properties): UserRecord
    {
        $request = $properties instanceof Request\UpdateUser
            ? $properties
            : Request\UpdateUser::withProperties($properties);

        $request = $request->withUid($uid);

        $response = $this->client->updateUser($request);

        $uid = JSON::decode((string) $response->getBody(), true)['localId'];

        return $this->getUser($uid);
    }
1212544
public function urlAvatar($iUserId = null, $iWidth = 100, $iHeight = 100)
    {
        if (is_null($iUserId)) {
            $iUserId = activeUser('id');
        }

        if (empty($iUserId)) {
            $avatarUrl = $this->urlBlankAvatar($iWidth, $iHeight);
        } else {
            $oUserModel = Factory::model('User', 'nails/module-auth');
            $user       = $oUserModel->getById($iUserId);
            if (empty($user)) {
                $avatarUrl = $this->urlBlankAvatar($iWidth, $iHeight);
            } elseif (empty($user->profile_img)) {
                $avatarUrl = $this->urlBlankAvatar($iWidth, $iHeight, $user->gender);
            } else {
                $avatarUrl = $this->urlCrop($user->profile_img, $iWidth, $iHeight);
            }
        }

        return $avatarUrl;
    }
637647
public function update($userId, $payload)
    {
        if (isset($payload['meta']) && ! isset($payload['meta']['terms_and_cond'])) {
            throw new Exception("You must agree to the terms and conditions.", 1);
        }

        try {
            return DB::transaction(function () use ($userId, $payload) {
                $user = $this->model->find($userId);

                if (isset($payload['meta']['marketing']) && ($payload['meta']['marketing'] == 1 || $payload['meta']['marketing'] == 'on')) {
                    $payload['meta']['marketing'] = 1;
                } else {
                    $payload['meta']['marketing'] = 0;
                }

                if (isset($payload['meta']['terms_and_cond']) && ($payload['meta']['terms_and_cond'] == 1 || $payload['meta']['terms_and_cond'] == 'on')) {
                    $payload['meta']['terms_and_cond'] = 1;
                } else {
                    $payload['meta']['terms_and_cond'] = 0;
                }

                $userMetaResult = (isset($payload['meta'])) ? $user->meta->update($payload['meta']) : true;

                $user->update($payload);

                if (isset($payload['roles'])) {
                    $this->unassignAllRoles($userId);
                    $this->assignRole($payload['roles'], $userId);
                }

                return $user;
            });
        } catch (Exception $e) {
            throw new Exception("We were unable to update your profile", 1);
        }
    }
898959
public static function update($userId, $id, $params = null, $options = null)
    {
        return self::_userBasedUpdate($userId, $id, $params, $options);
    }