public function suspend(): void
    {
        if (!userHasPermission('admin:auth:accounts:suspend')) {
            unauthorised();
        }

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

        //  Get the user's details
        $oUri       = Factory::service('Uri');
        $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);
        $bOldValue  = $oUser->is_suspended;

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

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

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

        //  Suspend user
        $oUserModel->suspend($iUserId);

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

        //  Get the user's details, again
        $oUser     = $oUserModel->getById($iUserId);
        $bNewValue = $oUser->is_suspended;

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

        //  Define messages
        if (!$oUser->is_suspended) {
            $oSession->setFlashData(
                'error',
                lang('accounts_suspend_error', title_case($oUser->first_name . ' ' . $oUser->last_name))
            );
        } else {
            $oSession->setFlashData(
                'success',
                lang('accounts_suspend_success', title_case($oUser->first_name . ' ' . $oUser->last_name))
            );
        }

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

        //  Update admin changelog
        $this->oChangeLogModel->add(
            'suspended',
            'a',
            'user',
            $iUserId,
            '#' . number_format($iUserId) . ' ' . $oUser->first_name . ' ' . $oUser->last_name,
            'admin/auth/accounts/edit/' . $iUserId,
            'is_suspended',
            $bOldValue,
            $bNewValue,
            false
        );

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

        $this->returnToIndex();
    }
public function suspend(): void
    {
        if (!userHasPermission('admin:auth:accounts:suspend')) {
            unauthorised();
        }

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

        //  Get the user's details
        $oUri       = Factory::service('Uri');
        $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);
        $bOldValue  = $oUser->is_suspended;

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

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

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

        //  Suspend user
        $oUserModel->suspend($iUserId);

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

        //  Get the user's details, again
        $oUser     = $oUserModel->getById($iUserId);
        $bNewValue = $oUser->is_suspended;

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

        //  Define messages
        if (!$oUser->is_suspended) {
            $oSession->setFlashData(
                'error',
                lang('accounts_suspend_error', title_case($oUser->first_name . ' ' . $oUser->last_name))
            );
        } else {
            $oSession->setFlashData(
                'success',
                lang('accounts_suspend_success', title_case($oUser->first_name . ' ' . $oUser->last_name))
            );
        }

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

        //  Update admin changelog
        $this->oChangeLogModel->add(
            'suspended',
            'a',
            'user',
            $iUserId,
            '#' . number_format($iUserId) . ' ' . $oUser->first_name . ' ' . $oUser->last_name,
            'admin/auth/accounts/edit/' . $iUserId,
            'is_suspended',
            $bOldValue,
            $bNewValue,
            false
        );

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

        $this->returnToIndex();
    }
public function suspend ( ) : void { if ( ! userHasPermission ( 'admin:auth:accounts:suspend' ) ) { unauthorised ( ) ; } // -------------------------------------------------------------------------- //  Get the user's details $ oUri = Factory :: service ( 'Uri' ) ; $ 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 ) ; $ bOldValue = $ oUser -> is_suspended ; // -------------------------------------------------------------------------- //  Non-superusers editing superusers is not cool if ( ! isSuperuser ( ) && userHasPermission ( 'superuser' , $ oUser ) ) { $ oSession -> setFlashData ( 'error' , lang ( 'accounts_edit_error_noteditable' ) ) ; $ this -> returnToIndex ( ) ; } // -------------------------------------------------------------------------- //  Suspend user $ oUserModel -> suspend ( $ iUserId ) ; // -------------------------------------------------------------------------- //  Get the user's details, again $ oUser = $ oUserModel -> getById ( $ iUserId ) ; $ bNewValue = $ oUser -> is_suspended ; // -------------------------------------------------------------------------- //  Define messages if ( ! $ oUser -> is_suspended ) { $ oSession -> setFlashData ( 'error' , lang ( 'accounts_suspend_error' , title_case ( $ oUser -> first_name . ' ' . $ oUser -> last_name ) ) ) ; } else { $ oSession -> setFlashData ( 'success' , lang ( 'accounts_suspend_success' , title_case ( $ oUser -> first_name . ' ' . $ oUser -> last_name ) ) ) ; } // -------------------------------------------------------------------------- //  Update admin changelog $ this -> oChangeLogModel -> add ( 'suspended' , 'a' , 'user' , $ iUserId , '#' . number_format ( $ iUserId ) . ' ' . $ oUser -> first_name . ' ' . $ oUser -> last_name , 'admin/auth/accounts/edit/' . $ iUserId , 'is_suspended' , $ bOldValue , $ bNewValue , false ) ; // -------------------------------------------------------------------------- $ this -> returnToIndex ( ) ; }
Suspend a user

@throws \Nails\Common\Exception\FactoryException
@throws \Nails\Common\Exception\ModelException
Suspend a user