Skip Navigation
Expand
Preventing Contact or Incident Creation
Answer ID 12338   |   Last Review Date 08/16/2022

How do I prevent unauthenticated contact or incident creation?

Environment

Oracle B2C Service Customer Portal pages

Resolution

The primary use case of this implementation is to prevent any unauthenticated incident (SR) or contact (User) creation.

  • If you want to prevent unauthenticated incident creation only use the 'pre_incident_create' hook.
  • If you want to prevent unauthenticated contact creation as well, use the following code as is.
  • When you want to reactivate unauthenticated incident and contact creation in your site, change 'cp/customer/development/config/hooks.php' and remove the hook entries.

We can use hooks to prevent unauthenticated contact and incident creation in Customer Portal. Please follow the following steps to implement:

  1. Create a new custom model under 'cp/customer/development/models/custom' by creating a new file 'HookAction.php'. This model will contain the methods which will get executed by the respective hooks. 
  2. Add the following code to the 'HookAction.php' file:

 

<?php
namespace Custom\Models;
 
use \RightNow\Utils\Framework;
use \RightNow\Utils\Config;
 
/**
* Class to check contact permission for certain actions.
*/
class HookAction {
    /**
     * Blocks request for contact creation by returning error.
     * return string Error message if not allowed
     */
    function blockContactCreate() {
        return Config::getMessage(AN_ERROR_OCCURRED_LBL);
    }
 
    /**
     * Blocks unauthenticated request for incident creation by returning error
     * return string Error message if user not logged-in
     */
    function blockUnauthenticatedIncidentCreate() {
        if(!Framework::isLoggedIn()) {
            return Config::getMessage(AN_ERROR_OCCURRED_LBL);
        }
    }
}
 
  1. Now go to the 'cp/customer/development/config/hooks.php' file and add the following hook entries:
 
// Below hook will block contact create request for new users
$rnHooks['pre_contact_create'] = array(
    'class' => 'HookAction',
    'function' => 'blockContactCreate',
);
 
// Below hook will block unauthenticated incident create request for all users
$rnHooks['pre_incident_create'] = array(
    'class' => 'HookAction',
    'function' => 'blockUnauthenticatedIncidentCreate',
);
 
 
  1. Now attempt to create a contact and/or incident as an unauthenticated user and you will get an error, as seen below: