public function cancel($userId, $code)
    {
        $this->loadModel('User.Users');
        $user = $this->Users
            ->find()
            ->where(['id' => $userId])
            ->contain(['Roles'])
            ->limit(1)
            ->first();

        if (in_array(ROLE_ID_ADMINISTRATOR, $user->role_ids) &&
            $this->Users->countAdministrators() === 1
        ) {
            $this->Flash->warning(__d('user', 'You are the last administrator in the system, your account cannot be canceled.'));
            $this->redirect($this->referer());
        }

        if ($user && $code == $user->cancel_code) {
            if ($this->Users->delete($user)) {
                NotificationManager::canceled($user)->send();
                $this->Flash->success(__d('user', 'Account successfully canceled'));
            } else {
                $this->Flash->danger(__d('user', 'Account could not be canceled due to an internal error, please try again later.'));
            }
        } else {
            $this->Flash->warning(__d('user', 'Not user was found, invalid cancellation URL.'));
        }

        $this->title(__d('user', 'Account Cancellation'));
        $this->redirect($this->referer());
    }