Sample Four: Self-Registration Validation

This sample is an example of a script that can be run from the self-registration context.

Note: To use this script, you must add it to SBM System Administrator under Options | Settings | External User | Registration Form Settings | Form Validation Script.

Sample Self-Registration Script Contents

' SBM ModScript Example: SelfRegValidationExample.tscm

/*  ModScript Example: SelfRegValidationExample.tsc
    Purpose: Perform additional password validation for self-registration form.

    Context: Registration Form Settings for the "Self-Registration by External
             Users" feature.

    Implementation: Verify that the password is at least 5 characters. */


/*  Validate that the Shell contains the properties that are
    expected to be there in the context of the self-registration form.*/

if ( !( Ext.ShellHasProp( "RegistrationMethod" ) && Ext.ShellHasProp( "Password" ) ) ) {
  Shell.RedoMessage() = "Missing shell properties, is this a Self-Registration context?";
} 
else {
  /*  Only verify the password if the registration mode is "automatic".
      In 'manual' registration mode the form doesn't ask for a login id
      and password.  In automatic mode, Shell.registrationMethod is 1
      and in manual mode, Shell.registrationMethod is 0. */

  if ( Shell.RegistrationMethod() == "automatic" ) {
    if ( Shell.Password().to_string().size() < 5 ) { 
// could also use Len( Shell.Password() ), but using this to demo that 
// Variants can be converted to the ChaiScript string class
      Shell.RedoMessage() = "Password must be at least 5 characters";
    }
  }
}