public function delete_profile_img(): void
    {
        $oUri = Factory::service('Uri');
        if ($oUri->segment(5) != activeUser('id') && !userHasPermission('admin:auth:accounts:editOthers')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        $oInput     = Factory::service('Input');
        $oSession   = Factory::service('Session', 'nails/module-auth');
        $oUserModel = Factory::model('User', 'nails/module-auth');
        $iUserId    = $oUri->segment(5);
        $oUser      = $oUserModel->getById($iUserId);
        $sReturnTo  = $oInput->get('return_to') ? $oInput->get('return_to') : 'admin/auth/accounts/edit/' . $iUserId;

        // --------------------------------------------------------------------------

        if (!$oUser) {

            $oSession->setFlashData('error', lang('accounts_delete_img_error_noid'));
            redirect('admin/auth/accounts');

        } else {

            //  Non-superusers editing superusers is not cool
            if (!isSuperuser() && userHasPermission('superuser', $oUser)) {
                $oSession->setFlashData('error', lang('accounts_edit_error_noteditable'));
                redirect($sReturnTo);
            }

            // --------------------------------------------------------------------------

            if ($oUser->profile_img) {

                $oCdn = Factory::service('Cdn', 'nails/module-cdn');

                if ($oCdn->objectDelete($oUser->profile_img, 'profile-images')) {

                    //  Update the user
                    $oUserModel->update($iUserId, ['profile_img' => null]);

                    $sStatus  = 'notice';
                    $sMessage = lang('accounts_delete_img_success');

                } else {
                    $sStatus  = 'error';
                    $sMessage = lang('accounts_delete_img_error', implode('", "', $oCdn->getErrors()));
                }

            } else {
                $sStatus  = 'notice';
                $sMessage = lang('accounts_delete_img_error_noimg');
            }

            $oSession->setFlashData($sStatus, $sMessage);

            // --------------------------------------------------------------------------

            redirect($sReturnTo);
        }
    }
public function delete_profile_img(): void
    {
        $oUri = Factory::service('Uri');
        if ($oUri->segment(5) != activeUser('id') && !userHasPermission('admin:auth:accounts:editOthers')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        $oInput     = Factory::service('Input');
        $oSession   = Factory::service('Session', 'nails/module-auth');
        $oUserModel = Factory::model('User', 'nails/module-auth');
        $iUserId    = $oUri->segment(5);
        $oUser      = $oUserModel->getById($iUserId);
        $sReturnTo  = $oInput->get('return_to') ? $oInput->get('return_to') : 'admin/auth/accounts/edit/' . $iUserId;

        // --------------------------------------------------------------------------

        if (!$oUser) {

            $oSession->setFlashData('error', lang('accounts_delete_img_error_noid'));
            redirect('admin/auth/accounts');

        } else {

            //  Non-superusers editing superusers is not cool
            if (!isSuperuser() && userHasPermission('superuser', $oUser)) {
                $oSession->setFlashData('error', lang('accounts_edit_error_noteditable'));
                redirect($sReturnTo);
            }

            // --------------------------------------------------------------------------

            if ($oUser->profile_img) {

                $oCdn = Factory::service('Cdn', 'nails/module-cdn');

                if ($oCdn->objectDelete($oUser->profile_img, 'profile-images')) {

                    //  Update the user
                    $oUserModel->update($iUserId, ['profile_img' => null]);

                    $sStatus  = 'notice';
                    $sMessage = lang('accounts_delete_img_success');

                } else {
                    $sStatus  = 'error';
                    $sMessage = lang('accounts_delete_img_error', implode('", "', $oCdn->getErrors()));
                }

            } else {
                $sStatus  = 'notice';
                $sMessage = lang('accounts_delete_img_error_noimg');
            }

            $oSession->setFlashData($sStatus, $sMessage);

            // --------------------------------------------------------------------------

            redirect($sReturnTo);
        }
    }
public function delete_profile_img ( ) : void { $ oUri = Factory :: service ( 'Uri' ) ; if ( $ oUri -> segment ( 5 ) != activeUser ( 'id' ) && ! userHasPermission ( 'admin:auth:accounts:editOthers' ) ) { unauthorised ( ) ; } // -------------------------------------------------------------------------- $ oInput = Factory :: service ( 'Input' ) ; $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; $ oUserModel = Factory :: model ( 'User' , 'nails/module-auth' ) ; $ iUserId = $ oUri -> segment ( 5 ) ; $ oUser = $ oUserModel -> getById ( $ iUserId ) ; $ sReturnTo = $ oInput -> get ( 'return_to' ) ? $ oInput -> get ( 'return_to' ) : 'admin/auth/accounts/edit/' . $ iUserId ; // -------------------------------------------------------------------------- if ( ! $ oUser ) { $ oSession -> setFlashData ( 'error' , lang ( 'accounts_delete_img_error_noid' ) ) ; redirect ( 'admin/auth/accounts' ) ; } else { //  Non-superusers editing superusers is not cool if ( ! isSuperuser ( ) && userHasPermission ( 'superuser' , $ oUser ) ) { $ oSession -> setFlashData ( 'error' , lang ( 'accounts_edit_error_noteditable' ) ) ; redirect ( $ sReturnTo ) ; } // -------------------------------------------------------------------------- if ( $ oUser -> profile_img ) { $ oCdn = Factory :: service ( 'Cdn' , 'nails/module-cdn' ) ; if ( $ oCdn -> objectDelete ( $ oUser -> profile_img , 'profile-images' ) ) { //  Update the user $ oUserModel -> update ( $ iUserId , [ 'profile_img' => null ] ) ; $ sStatus = 'notice' ; $ sMessage = lang ( 'accounts_delete_img_success' ) ; } else { $ sStatus = 'error' ; $ sMessage = lang ( 'accounts_delete_img_error' , implode ( '", "' , $ oCdn -> getErrors ( ) ) ) ; } } else { $ sStatus = 'notice' ; $ sMessage = lang ( 'accounts_delete_img_error_noimg' ) ; } $ oSession -> setFlashData ( $ sStatus , $ sMessage ) ; // -------------------------------------------------------------------------- redirect ( $ sReturnTo ) ; } }
Delete a user's profile image

@throws \Nails\Common\Exception\FactoryException
Delete a user s profile image