enabled() public static method

Should we expect captcha submissions?
public static enabled ( ) : boolean
return boolean
Ejemplo n.º 1
0
 /**
  * Wrapper for captcha rendering.
  *
  * Allows conditional ignoring of captcha rendering if skipped in the config.
  *
  * @param Gdn_Controller $controller
  * @return null;
  */
 public static function render($controller)
 {
     if (!Captcha::enabled()) {
         return null;
     }
     // Hook to allow rendering of captcha form
     $controller->fireAs('captcha')->fireEvent('render');
     return null;
 }
Ejemplo n.º 2
0
 /**
  * To be used for basic registration, and captcha registration.
  *
  * @param array $FormPostValues
  * @param bool $CheckCaptcha
  * @param array $Options
  * @return bool|int|string
  * @throws Exception
  */
 public function insertForBasic($FormPostValues, $CheckCaptcha = true, $Options = [])
 {
     $RoleIDs = RoleModel::getDefaultRoles(RoleModel::TYPE_MEMBER);
     if (!is_array($RoleIDs) || count($RoleIDs) == 0) {
         throw new Exception(t('The default role has not been configured.'), 400);
     }
     if (val('SaveRoles', $Options)) {
         $RoleIDs = val('RoleID', $FormPostValues);
     }
     $UserID = false;
     // Define the primary key in this model's table.
     $this->defineSchema();
     // Add & apply any extra validation rules.
     if (val('ValidateEmail', $Options, true)) {
         $this->Validation->applyRule('Email', 'Email');
     }
     // TODO: DO I NEED THIS?!
     // Make sure that the checkbox val for email is saved as the appropriate enum
     if (array_key_exists('ShowEmail', $FormPostValues)) {
         $FormPostValues['ShowEmail'] = forceBool($FormPostValues['ShowEmail'], '0', '1', '0');
     }
     if (array_key_exists('Banned', $FormPostValues)) {
         $FormPostValues['Banned'] = forceBool($FormPostValues['Banned'], '0', '1', '0');
     }
     $this->addInsertFields($FormPostValues);
     if ($this->validate($FormPostValues, true) === true) {
         $Fields = $this->Validation->validationFields();
         // All fields on the form that need to be validated (including non-schema field rules defined above)
         $Username = val('Name', $Fields);
         $Email = val('Email', $Fields);
         $Fields = $this->Validation->schemaValidationFields();
         // Only fields that are present in the schema
         $Fields['Roles'] = $RoleIDs;
         unset($Fields[$this->PrimaryKey]);
         // If in Captcha registration mode, check the captcha value.
         if ($CheckCaptcha && Captcha::enabled()) {
             $captchaIsValid = Captcha::validate();
             if ($captchaIsValid !== true) {
                 $this->Validation->addValidationResult('Garden.Registration.CaptchaPublicKey', 'The captcha was not completed correctly. Please try again.');
                 return false;
             }
         }
         if (!$this->validateUniqueFields($Username, $Email)) {
             return false;
         }
         // Check for spam.
         if (val('ValidateSpam', $Options, true)) {
             $ValidateSpam = $this->validateSpamRegistration($FormPostValues);
             if ($ValidateSpam !== true) {
                 return $ValidateSpam;
             }
         }
         // Define the other required fields:
         $Fields['Email'] = $Email;
         // And insert the new user
         $UserID = $this->insertInternal($Fields, $Options);
         if ($UserID > 0 && !val('NoActivity', $Options)) {
             $ActivityModel = new ActivityModel();
             $ActivityModel->save(['ActivityUserID' => $UserID, 'ActivityType' => 'Registration', 'HeadlineFormat' => t('HeadlineFormat.Registration', '{ActivityUserID,You} joined.'), 'Story' => t('Welcome Aboard!')], false, ['GroupBy' => 'ActivityTypeID']);
         }
     }
     return $UserID;
 }