/** * @inheritdoc */ public function isValid($data, $field = '', array $extra = []) { if (is_array($data) && array_key_exists($field, $data)) { return $this->isValid($data[$field], $field, $extra); } if ($this->acl->hasPermission('frontend/captcha/index/image') === true && $this->user->isAuthenticated() === false) { return $this->checkCaptcha($data, isset($extra['path']) ? $extra['path'] : ''); } return true; }
/** * Erzeugt das Captchafeld für das Template * * @param integer $captchaLength * @param string $formFieldId * @param bool $inputOnly * @param string $path * * @return string */ public function captcha($captchaLength = self::CAPTCHA_DEFAULT_LENGTH, $formFieldId = self::CAPTCHA_DEFAULT_INPUT_ID, $inputOnly = false, $path = '') { if ($this->user->isAuthenticated() === false) { $path = sha1($this->router->route(empty($path) === true ? $this->request->getQuery() : $path)); $this->sessionHandler->set('captcha_' . $path, $this->secureHelper->salt($captchaLength)); $this->view->assign('captcha', ['width' => $captchaLength * 25, 'id' => $formFieldId, 'height' => 30, 'input_only' => $inputOnly, 'path' => $path]); return $this->view->fetchTemplate('Captcha/Partials/captcha.tpl'); } return ''; }
/** * @param int $pollId * @param string $ipAddress * @return mixed */ protected function getVotes($pollId, $ipAddress) { // Check, whether the logged user has already voted if ($this->userModel->isAuthenticated() === true) { $votes = $this->voteRepository->getVotesByUserId($pollId, $this->userModel->getUserId(), $ipAddress); } else { // For guest users check against the ip address $votes = $this->voteRepository->getVotesByIpAddress($pollId, $ipAddress); } return $votes; }
/** * @param array $formData * @param int $pollId * @param string $ipAddress * @param string $time * @return bool|int * @throws Core\Validation\Exceptions\ValidationRuleNotFoundException */ public function vote(array $formData, $pollId, $ipAddress, $time) { $answers = $formData['answer']; $bool = false; $userId = $this->userModel->isAuthenticated() ? $this->userModel->getUserId() : null; // Multiple Answers if (is_array($answers) === false) { $answers = [$answers]; } foreach ($answers as $answer) { if ($this->validator->is(IntegerValidationRule::class, $answer) === true) { $insertValues = ['poll_id' => $pollId, 'answer_id' => $answer, 'user_id' => $userId, 'ip' => $ipAddress, 'time' => $time]; $bool = $this->voteRepository->insert($insertValues); } } return $bool; }