Skip to content

Commit

Permalink
add files
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndr-w committed Feb 11, 2024
1 parent f6bdb9f commit 68f5423
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
1 change: 1 addition & 0 deletions assets/jetzt-spenden.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions lib/yform/validate/compromised.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

class rex_yform_compromised extends \rex_yform_validate_abstract
{
public function enterObject()
{

$Object = $this->getValueObject($this->getElement('name'));

if (!$this->isObject($Object)) {
return;
}

if ('' == $Object->getValue()) {
return;
}

$partitalSHA256 = substr(hash('sha256', $Object->getValue()), 0, 10);

$url = 'https://api.enzoic.com/v1/passwords';
$rex_socket = rex_socket::factoryUrl($url);
$rex_socket->addBasicAuthorization(rex_config::get('yform_field', 'compromised_api_key'), rex_config::get('yform_field', 'compromised_api_secret'));
$rex_socket_response = $rex_socket->doPost(['partialSHA256' => $partitalSHA256]);

if (!$rex_socket_response->isOk()) {

$body = $rex_socket_response->getBody();
$candidates = json_decode($body, true);
if(!$candidates) {
return;
}

if (isset($candidates['candidates'])) {
foreach ($candidates['candidates'] as $candidate) {
if ($candidate['sha256'] == hash('sha256', $Object->getValue())) {
$Object->setValue('');
$this->params['warning'][$Object->getId()] = $this->params['error_class'];
$this->params['warning_messages'][$Object->getId()] = $this->getElement('message');
return;
}
}
}
}
}

public function getDescription(): string
{
return 'validate|password_compromised|passwordfieldname|warning_message';
}

public function getDefinitions(): array
{
return [
'type' => 'validate',
'name' => 'password_compromised',
'values' => [
'name' => ['type' => 'select_name', 'label' => rex_i18n::msg('yform_validate_password_compromised_name')],
'message' => ['type' => 'text', 'label' => rex_i18n::msg('yform_validate_password_compromised_message')],
],
'description' => rex_i18n::msg('yform_validate_password_compromised_description'),
];
}
}
38 changes: 38 additions & 0 deletions lib/yform/value/be_media_preview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

class rex_yform_value_be_media_preview extends rex_yform_value_be_media
{
public function getDefinitions(): array
{
return [
'type' => 'value',
'name' => 'be_media_preview',
'values' => [
'name' => ['type' => 'name', 'label' => rex_i18n::msg('yform_values_defaults_name')],
'label' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_defaults_label')],
'preview' => ['type' => 'checkbox', 'label' => rex_i18n::msg('yform_values_be_media_preview')],
'multiple' => ['type' => 'checkbox', 'label' => rex_i18n::msg('yform_values_be_media_multiple')],
'category' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_be_media_category')],
'types' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_be_media_types'), 'notice' => rex_i18n::msg('yform_values_be_media_types_notice')],
'notice' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_defaults_notice')],
],
'description' => rex_i18n::msg('yform_values_be_media_preview_description'),
'formbuilder' => false,
'db_type' => ['text'],
];
}

public static function getListValue($params)
{
$files = explode(',', $params['subject']);

$return = [];
foreach ($files as $file) {
if (rex_media::get($file)) {
$return[] = '<img style="width: 40px;" src="' . rex_media_manager::getUrl('rex_media_small', $files[0]) . '">';
}
}

return implode('<br />', $return);
}
}
25 changes: 25 additions & 0 deletions pages/yform.yform_field_docs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* @var rex_addon $this
* @psalm-scope-this rex_addon
*/

$page = rex_be_controller::getPageObject('yform/yform_field_docs');

echo rex_view::title($this->i18n('product_title'));

[$Toc, $Content] = rex_markdown::factory()->parseWithToc(rex_file::get(rex_path::addon('yform_field', 'README.md')), 2, 3, [
rex_markdown::SOFT_LINE_BREAKS => false,
rex_markdown::HIGHLIGHT_PHP => true,
]);

$fragment = new rex_fragment();
$fragment->setVar('content', $Content, false);
$fragment->setVar('toc', $Toc, false);
$content = $fragment->parse('core/page/docs.php');

$fragment = new rex_fragment();
$fragment->setVar('title', rex_i18n::msg('package_help') . ' YForm Field', false);
$fragment->setVar('body', $content, false);
echo $fragment->parse('core/page/section.php');

0 comments on commit 68f5423

Please sign in to comment.