Skip to content

Commit 1c9e4e3

Browse files
author
Mike van den Hoek
committed
(refactor): retrieve bsn by DigiD session instead of value of form field
1 parent 46287a3 commit 1c9e4e3

5 files changed

Lines changed: 14 additions & 41 deletions

File tree

src/PrefillGravityForms/Controllers/BaseController.php

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
namespace OWC\PrefillGravityForms\Controllers;
44

5+
use Exception;
6+
use function OWC\PrefillGravityForms\Foundation\Helpers\decrypt;
57
use function OWC\PrefillGravityForms\Foundation\Helpers\view;
6-
use function Yard\DigiD\Foundation\Helpers\decrypt;
78
use function Yard\DigiD\Foundation\Helpers\resolve;
89
use OWC\PrefillGravityForms\Foundation\TeamsLogger;
910
use OWC\PrefillGravityForms\GravityForms\GravityFormsSettings;
@@ -33,31 +34,15 @@ public function resolveTeams(): TeamsLogger
3334
}
3435
}
3536

36-
/**
37-
* Validate if form has a DigiD field.
38-
* If so return the decrypted BSN number.
39-
*/
40-
protected function getBSN(array $form): string
37+
protected function getBSN(): string
4138
{
42-
$bsn = '';
43-
44-
foreach ($form['fields'] as $field) {
45-
if ($field->type !== 'digid') {
46-
continue;
47-
}
48-
49-
$resolvedBSN = resolve('session')->getSegment('digid')->get('bsn');
50-
51-
if (empty($resolvedBSN)) {
52-
continue;
53-
}
54-
55-
$bsn = decrypt($resolvedBSN);
56-
57-
break;
39+
try {
40+
$bsn = resolve('session')->getSegment('digid')->get('bsn');
41+
} catch(Exception $e) {
42+
$bsn = '';
5843
}
5944

60-
return $bsn;
45+
return is_string($bsn) && ! empty($bsn) ? decrypt($bsn) : '';
6146
}
6247

6348
/**

src/PrefillGravityForms/Controllers/EnableUController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class EnableUController extends BaseController
66
{
77
public function handle(array $form)
88
{
9-
$bsn = $this->getBSN($form);
9+
$bsn = $this->getBSN();
1010

1111
if (empty($bsn)) {
1212
return $form;

src/PrefillGravityForms/Controllers/OpenZaakController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class OpenZaakController extends BaseController
66
{
77
public function handle(array $form)
88
{
9-
$bsn = $this->getBSN($form);
9+
$bsn = $this->getBSN();
1010

1111
if (empty($bsn)) {
1212
return $form;

src/PrefillGravityForms/Foundation/Cryptor.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@
44

55
class Cryptor
66
{
7-
/** @var string */
8-
protected $method = 'aes-128-ctr'; // default cipher method if none supplied
7+
protected string $method = 'aes-128-ctr'; // default cipher method if none supplied
8+
private string $key;
99

10-
/** @var string */
11-
private $key;
12-
13-
/**
14-
* @param boolean $method
15-
*/
16-
public function __construct($method = false)
10+
public function __construct(bool $method = false)
1711
{
1812
$key = \AUTH_KEY ?? php_uname();
1913
if (ctype_print($key)) {

src/PrefillGravityForms/Foundation/Helpers.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,7 @@ function decrypt($string): string
5252
return $decrypted ?: '';
5353
}
5454

55-
/**
56-
* @param string $setting
57-
* @param string $default
58-
*
59-
* @return string
60-
*/
61-
function config(string $setting, $default = ''): ?string
55+
function config(string $setting, $default = '')
6256
{
6357
return resolve('config')->get($setting, $default);
6458
}

0 commit comments

Comments
 (0)