Skip to content

Commit 192be24

Browse files
authored
Merge pull request #4 from sander3/dispatch-event-feature
Dispatch event feature
2 parents 7b39a71 + 4c8d9a7 commit 192be24

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

readme.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# GDPR compliant data portability with ease
22

3+
[![Latest Stable Version](https://poser.pugx.org/soved/laravel-gdpr/v/stable?format=flat-square)](https://packagist.org/packages/soved/laravel-gdpr)
4+
[![Monthly Downloads](https://poser.pugx.org/soved/laravel-gdpr/d/monthly?format=flat-square)](https://packagist.org/packages/soved/laravel-gdpr)
5+
[![License](https://poser.pugx.org/soved/laravel-gdpr/license?format=flat-square)](https://packagist.org/packages/soved/laravel-gdpr)
6+
37
This package exposes an endpoint where authenticated users can download their data as required by GDPR article 20.
48

59
## Requirements
@@ -158,6 +162,8 @@ class User extends Authenticatable
158162

159163
This package exposes an endpoint at `/gdpr/download`. Only authenticated users should be able to access the routes. Your application should make a POST call, containing the currently authenticated user's password, to this endpoint. The re-authentication is needed to prevent information leakage.
160164

165+
You may listen for the `Soved\Laravel\Gdpr\Events\GdprDownloaded` event, which will be dispatched upon successful re-authentication and data conversion.
166+
161167
### Encryption
162168

163169
> Before using encryption, you must set a `key` option in your `config/app.php` configuration file. If this value is not properly set, all encrypted values will be insecure.
@@ -190,7 +196,6 @@ class User extends Authenticatable
190196

191197
## Roadmap
192198

193-
- Dispatch GdprDownload event
194199
- Data retention
195200

196201
## Security Vulnerabilities

src/Events/GdprDownloaded.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Soved\Laravel\Gdpr\Events;
4+
5+
use App\User;
6+
use Illuminate\Queue\SerializesModels;
7+
8+
class GdprDownloaded
9+
{
10+
use SerializesModels;
11+
12+
/**
13+
* @var \App\User
14+
*/
15+
public $user;
16+
17+
/**
18+
* Create a new event instance.
19+
*
20+
* @param \App\User $user
21+
* @return void
22+
*/
23+
public function __construct(User $user)
24+
{
25+
$this->user = $user;
26+
}
27+
}

src/Http/Controllers/GdprController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Http\Controllers\Controller;
66
use Illuminate\Support\Facades\Auth;
7+
use Soved\Laravel\Gdpr\Events\GdprDownloaded;
78
use Soved\Laravel\Gdpr\Http\Requests\GdprDownload;
89

910
class GdprController extends Controller
@@ -23,8 +24,14 @@ public function download(GdprDownload $request)
2324

2425
abort_unless(Auth::attempt($credentials), 403);
2526

27+
$data = $request->user()->portable();
28+
29+
event(new GdprDownloaded($request->user()));
30+
31+
// Backward compatible streamDownload() behavior
32+
2633
return response()->json(
27-
$request->user()->portable(),
34+
$data,
2835
200,
2936
[
3037
'Content-Disposition' => 'attachment; filename="user.json"',

0 commit comments

Comments
 (0)