feat(altcha): add altcha validation layer to login
Some checks are pending
Cadoles/hydra-sql/pipeline/pr-develop Build started...
Some checks are pending
Cadoles/hydra-sql/pipeline/pr-develop Build started...
This commit is contained in:
48
src/Altcha/AltchaTransformer.php
Normal file
48
src/Altcha/AltchaTransformer.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Altcha;
|
||||
|
||||
use App\Altcha\Form\AltchaModel;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
|
||||
class AltchaTransformer implements DataTransformerInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function reverseTransform($value): AltchaModel
|
||||
{
|
||||
if (empty($value)) {
|
||||
return new AltchaModel();
|
||||
}
|
||||
|
||||
$decodedValue = base64_decode($value);
|
||||
$data = json_decode($decodedValue);
|
||||
|
||||
$model = new AltchaModel();
|
||||
|
||||
foreach ($data as $property => $value) {
|
||||
$model->{$property} = $value;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function transform($value): string
|
||||
{
|
||||
if (empty($value)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$json = json_encode($value);
|
||||
|
||||
if (false === $json) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return base64_encode($json);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user