Skip to content

Commit

Permalink
Merge pull request #178 from paynl/feature/PLUG-3327
Browse files Browse the repository at this point in the history
PLUG-3327 - Password Field
  • Loading branch information
woutse authored Apr 22, 2024
2 parents 7dc0095 + 8723b9e commit c505965
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 4 deletions.
94 changes: 94 additions & 0 deletions Block/Adminhtml/Render/Obscured.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Paynl\Payment\Block\Adminhtml\Render;

use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Data\Form\Element\AbstractElement;

class Obscured extends Field
{
protected $configPath;
protected $_template = 'Paynl_Payment::system/config/obscured.phtml';

/**
*
* @var Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;

/**
*
* @var Magento\Framework\App\RequestInterface
*/
protected $request;

/**
* Constructor.
*
* @param Context $context
* @param ScopeConfigInterface $scopeConfig
* @param RequestInterface $request
*/
public function __construct(Context $context, ScopeConfigInterface $scopeConfig, RequestInterface $request)
{
$this->scopeConfig = $scopeConfig;
$this->request = $request;
parent::__construct($context);
}

/**
*
* @param AbstractElement $element
*
* @return string
*/
protected function _getElementHtml(AbstractElement $element) // phpcs:ignore
{
$this->configPath = $element->getData('field_config')['config_path'];
$this->setNamePrefix($element->getName())
->setHtmlId($element->getHtmlId());
return $this->_toHtml();
}

/**
*
* @return string
*/
public function getValue()
{
$data = $this->getConfigData();
if (isset($data[$this->configPath])) {
$data = $data[$this->configPath];
} else {
$data = '';
}
return $data;
}

/**
* @return string
*/
public function getDecryptedValue()
{
$storeId = $this->request->getParam('store');
$websiteId = $this->request->getParam('website');

$scope = 'default';
$scopeId = 0;

if ($storeId) {
$scope = 'stores';
$scopeId = $storeId;
}
if ($websiteId) {
$scope = 'websites';
$scopeId = $websiteId;
}

$apiToken = trim((string) $this->scopeConfig->getValue($this->configPath, $scope, $scopeId));
return $apiToken ?? $this->getValue();
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "paynl/magento2-plugin",
"description": "PAY. Payment methods for Magento2",
"type": "magento2-module",
"version": "3.11.4",
"version": "3.12.0",
"require": {
"magento/module-sales": "^102.0.0 || ^103.0.0",
"magento/module-payment": "^100.3.0",
Expand Down
7 changes: 4 additions & 3 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
</comment>
<config_path>payment/paynl/tokencode</config_path>
</field>
<field id="apitoken_encrypted" translate="label, comment" type="obscure" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="apitoken_encrypted" translate="label, comment" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>API token</label>
<comment>
<![CDATA[Your API token, you can find your tokens <a target='_blank' href='https://my.pay.nl/company/tokens'>here</a>.]]>
</comment>
<config_path>payment/paynl/apitoken_encrypted</config_path>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
<frontend_model>Paynl\Payment\Block\Adminhtml\Render\Obscured</frontend_model>
<config_path>payment/paynl/apitoken_encrypted</config_path>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
</field>
<field id="serviceid" translate="label, comment" type="text" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Sales location</label>
Expand Down
1 change: 1 addition & 0 deletions view/adminhtml/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Paynl_Payment::css/configtab.css" />
<link src="Paynl_Payment::js/configtab.js"/>
</head>
</page>
4 changes: 4 additions & 0 deletions view/adminhtml/templates/system/config/obscured.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<span class="obscuredField">
<input type="text" name="<?php echo $this->getNamePrefix() ?>" value="<?php echo $this->getDecryptedValue(); ?>" />
<span class="obscuredDisplay"></span>
</span>
33 changes: 33 additions & 0 deletions view/adminhtml/web/css/configtab.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,36 @@
float: left;
margin-left: 10px;
}

.obscuredField {
position: relative;
}

.obscuredField input{
text-security: disc;
-webkit-text-security: disc;
-moz-text-security: disc;
}

.obscuredField input.display{
text-security: none;
-webkit-text-security: none;
-moz-text-security: none;
}

.obscuredField .obscuredDisplay{
position: absolute;
right: 10px;
top: 0;
cursor: pointer;
}

.obscuredField .obscuredDisplay::before{
content: '\e60f';
-webkit-font-smoothing: antialiased;
font-family: 'Admin Icons';
font-style: normal;
font-weight: normal;
line-height: 1;
speak: none;
}
8 changes: 8 additions & 0 deletions view/adminhtml/web/js/configtab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require([
'jquery',
'Magento_Ui/js/modal/alert'
], function ($, alert) {
$('.obscuredDisplay').click(function () {
$(this).parent().find('input').toggleClass('display')
})
})

0 comments on commit c505965

Please sign in to comment.