ProfileController::removePicture PHP Method

removePicture() public method

Remove the user's photo.
Since: 2.0.0
public removePicture ( mixed $UserReference = '', string $Username = '', string $tk = '', $deliveryType = '' )
$UserReference mixed Unique identifier, possibly username or ID.
$Username string .
$tk string Security token.
    public function removePicture($UserReference = '', $Username = '', $tk = '', $deliveryType = '')
    {
        $this->permission('Garden.SignIn.Allow');
        $Session = Gdn::session();
        if (!$Session->isValid()) {
            $this->Form->addError('You must be authenticated in order to use this form.');
        }
        // Get user data & another permission check.
        $this->getUserInfo($UserReference, $Username, '', true);
        if ($Session->validateTransientKey($tk) && is_object($this->User)) {
            $HasRemovePermission = checkPermission('Garden.Users.Edit') || checkPermission('Moderation.Profiles.Edit');
            if ($this->User->UserID == $Session->UserID || $HasRemovePermission) {
                // Do removal, set message, redirect
                Gdn::userModel()->removePicture($this->User->UserID);
                $this->informMessage(t('Your picture has been removed.'));
            }
        }
        if ($deliveryType === DELIVERY_TYPE_VIEW) {
            $redirectUrl = userUrl($this->User);
        } else {
            $redirectUrl = userUrl($this->User, '', 'picture');
        }
        redirect($redirectUrl);
    }