pdir / key-generator-bundle
Contao 4 的密钥生成向导
1.2.0
2022-10-25 10:20 UTC
Requires
- php: ^5.6 || ^7.0 || ^8.0
- contao/core-bundle: ^4.4
Requires (Dev)
- contao/manager-plugin: ^2.0
- doctrine/doctrine-cache-bundle: ^1.3
- friendsofphp/php-cs-fixer: ^2.12
- php-http/guzzle6-adapter: ^1.1
- php-http/message-factory: ^1.0.2
- phpunit/phpunit: ^5.7.26
- symfony/phpunit-bridge: ^3.2
Conflicts
- contao/core: *
- contao/manager-plugin: <2.0 || >=3.0
This package is auto-updated.
Last update: 2024-09-25 14:51:30 UTC
README
此扩展适用于 Contao 4,并增强 BE TextField Widget 的密钥生成向导。查看示例
$GLOBALS['TL_DCA']['tl_member']['fields']['apikey'] = array ( 'label' => &$GLOBALS['TL_LANG']['tl_member']['apikey'], 'exclude' => true, 'search' => false, 'inputType' => 'text', 'wizard' => [['\Pdir\KeyGeneratorBundle\KeyGenerator','getWizard']], 'save_callback' => [['\Pdir\KeyGeneratorBundle\KeyGenerator','setKeyIfEmpty']], 'eval' => ['maxlength'=>32, 'feEditable'=>false, 'feViewable'=>false, 'feGroup'=>'rpc', 'tl_class'=>'w50 wizard'], 'sql' => "varchar(32) NOT NULL default ''" );
您可以编写自己的生成器。使用 HOOK
回调方法获取字段名和最大长度。如果方法不想设置密钥,则返回新的密钥字符串或 false
// config.php $GLOBALS['TL_HOOKS']['generateKey'][] = array('\MyClass','generateKey'); // MyClass public function generateKey($strFieldName, $intLength) { if ($strFieldName == 'simplePasswordField') { return str_repeat('X',$intLength); } else if ($strFieldName == 'megaPasswordField') { return 'pasword123'; } return false; }
由 Sebastian Tilch 于 2012 年为 Contao 3 创建,原始链接:Sebastian Tilch 2012