Skip to content

Commit 614dad7

Browse files
authored
Merge pull request #2250 from codeeu/dev
Dev
2 parents cb1105f + c1a4313 commit 614dad7

File tree

108 files changed

+8983
-10662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+8983
-10662
lines changed
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Support\Facades\Auth;
7+
8+
class ConsentController extends Controller
9+
{
10+
public function show()
11+
{
12+
return view('consent');
13+
}
14+
15+
public function store(Request $request)
16+
{
17+
$user = Auth::user();
18+
19+
if ($request->input('consent1') === '1') {
20+
//$user->consent_given_at = now();
21+
$user->giveConsent();
22+
if ($request->input('consent2') === '1') {
23+
$user->giveFutureConsent();
24+
}
25+
26+
return redirect()->route('home');
27+
}
28+
29+
Auth::logout();
30+
return redirect('/');
31+
}
32+
33+
public function logout()
34+
{
35+
Auth::logout();
36+
return redirect('/login');
37+
}
38+
}
39+

app/Http/Kernel.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http;
44

5+
use App\Http\Middleware\EnsureUserHasGivenConsent;
56
use Illuminate\Foundation\Http\Kernel as HttpKernel;
67

78
class Kernel extends HttpKernel
@@ -20,7 +21,7 @@ class Kernel extends HttpKernel
2021
\App\Http\Middleware\TrimStrings::class,
2122
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
2223
\App\Http\Middleware\TrustProxies::class,
23-
\Spatie\CookieConsent\CookieConsentMiddleware::class,
24+
\Spatie\CookieConsent\CookieConsentMiddleware::class
2425
];
2526

2627
/**
@@ -39,6 +40,7 @@ class Kernel extends HttpKernel
3940
\App\Http\Middleware\VerifyCsrfToken::class,
4041
\Illuminate\Routing\Middleware\SubstituteBindings::class,
4142
\App\Http\Middleware\Locale::class,
43+
\App\Http\Middleware\CheckConsent::class,
4244
],
4345

4446
'api' => [
@@ -63,6 +65,6 @@ class Kernel extends HttpKernel
6365
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
6466
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
6567
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
66-
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
68+
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class
6769
];
6870
}

app/Http/Middleware/CheckConsent.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Support\Facades\Auth;
7+
8+
class CheckConsent
9+
{
10+
public function handle($request, Closure $next)
11+
{
12+
$excludedRoutes = [
13+
'consent.show',
14+
'consent.store',
15+
'consent.logout',
16+
];
17+
18+
if (Auth::check() && !Auth::user()->hasGivenConsent()) {
19+
if (!in_array($request->route()->getName(), $excludedRoutes)) {
20+
return redirect()->route('consent.show');
21+
}
22+
}
23+
24+
return $next($request);
25+
}
26+
}

app/User.php

+64-38
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ class User extends Authenticatable
9898
*
9999
* @var array
100100
*/
101-
// protected $fillable = [
102-
// 'firstname', 'lastname', 'username', 'avatar_path', 'email', 'password', 'bio', 'twitter', 'website', 'country_iso', 'privacy', 'email_display', 'receive_emails', 'magic_key','current_country','provider'
103-
// ];
101+
104102

105103
protected $guarded = [];
106104

@@ -110,19 +108,27 @@ class User extends Authenticatable
110108
* @var array
111109
*/
112110
protected $hidden = [
113-
'password', 'remember_token', 'magic_key'
111+
'password',
112+
'remember_token',
113+
'magic_key'
114114
];
115115

116116
protected $appends = ['fullName'];
117117

118-
protected $dates = ['deleted_at'];
118+
protected $dates = ['consent_given_at', 'future_consent_given_at'];
119119

120120

121121
public function getName()
122122
{
123-
if (!empty($this->username)) return $this->username;
124-
if (!empty($this->firstname) && !empty($this->lastname)) return $this->firstname . " " . $this->lastname;
125-
if (!empty($this->firstname) && empty($this->lastname)) return $this->firstname;
123+
if (!empty($this->username)) {
124+
return $this->username;
125+
}
126+
if (!empty($this->firstname) && !empty($this->lastname)) {
127+
return $this->firstname . " " . $this->lastname;
128+
}
129+
if (!empty($this->firstname) && empty($this->lastname)) {
130+
return $this->firstname;
131+
}
126132
return $this->email;
127133
}
128134

@@ -139,8 +145,6 @@ public function setAmbassadorAttribute($value)
139145
} else {
140146
$this->removeRole('ambassador');
141147
}
142-
143-
144148
}
145149

146150
public function achievements()
@@ -155,19 +159,15 @@ public function getLeadingTeacherAttribute()
155159

156160
public function setLeadingTeacherAttribute($value)
157161
{
158-
159162
if ($value) {
160163
$this->assignRole('leading teacher');
161164
} else {
162165
$this->removeRole('leading teacher');
163166
}
164-
165-
166167
}
167168

168169
public function isAdmin()
169170
{
170-
171171
return $this->hasRole("super admin");
172172
}
173173

@@ -218,7 +218,8 @@ public function participations()
218218

219219
public function expertises()
220220
{
221-
return $this->belongsToMany(LeadingTeacherExpertise::class, 'leading_teacher_expertise_user', 'user_id', 'lte_id');
221+
return $this->belongsToMany(LeadingTeacherExpertise::class, 'leading_teacher_expertise_user', 'user_id',
222+
'lte_id');
222223
}
223224

224225
public function levels()
@@ -259,25 +260,27 @@ public function actions()
259260

260261
public function resetExperience($year = null)
261262
{
262-
if (is_null($year)) $year = Carbon::now()->year;
263+
if (is_null($year)) {
264+
$year = Carbon::now()->year;
265+
}
263266
$this->getExperience($year)->update(
264267
["points" => 0]
265268
);
266-
267-
268269
}
269270

270271
public function getPoints($year = null)
271272
{
272-
if (is_null($year)) $year = Carbon::now()->year;
273+
if (is_null($year)) {
274+
$year = Carbon::now()->year;
275+
}
273276
return $this->getExperience($year)->points;
274-
275-
276277
}
277278

278279
public function getExperience($year = null)
279280
{
280-
if (is_null($year)) $year = Carbon::now()->year;
281+
if (is_null($year)) {
282+
$year = Carbon::now()->year;
283+
}
281284

282285
$experience = Experience::firstOrCreate(
283286
[
@@ -294,17 +297,18 @@ public function getExperience($year = null)
294297

295298
public function awardExperience($points, $year = null)
296299
{
297-
298-
if (is_null($year)) $year = Carbon::now()->year;
300+
if (is_null($year)) {
301+
$year = Carbon::now()->year;
302+
}
299303
$this->getExperience($year)->awardExperience($points);
300-
301304
}
302305

303306
public function stripExperience($points, $year = null)
304307
{
305-
if (is_null($year)) $year = Carbon::now()->year;
308+
if (is_null($year)) {
309+
$year = Carbon::now()->year;
310+
}
306311
$this->getExperience($year)->stripExperience($points);
307-
308312
}
309313

310314

@@ -316,9 +320,10 @@ public function stripExperience($points, $year = null)
316320
*/
317321
public function getAvatarPathAttribute($avatar)
318322
{
319-
if (is_null($avatar)) $avatar = 'avatars/default_avatar.png';
323+
if (is_null($avatar)) {
324+
$avatar = 'avatars/default_avatar.png';
325+
}
320326
return Storage::disk('s3')->url($avatar);
321-
322327
}
323328

324329
/**
@@ -329,14 +334,11 @@ public function getAvatarPathAttribute($avatar)
329334
*/
330335
public function getAvatarAttribute()
331336
{
332-
333337
$arr = explode("/", $this->avatar_path);
334338
$filename = array_pop($arr);
335339
array_push($arr, $filename);
336340
$glued = implode("/", $arr);
337341
return $glued;
338-
339-
340342
}
341343

342344

@@ -365,7 +367,6 @@ public static function getGeoIPData()
365367

366368
public function activities($edition)
367369
{
368-
369370
return DB::table('events')
370371
->where('creator_id', '=', $this->id)
371372
->where('status', "=", "APPROVED")
@@ -376,7 +377,6 @@ public function activities($edition)
376377

377378
public function reported($edition = null)
378379
{
379-
380380
$query = DB::table('events')
381381
->where('creator_id', '=', $this->id)
382382
->where('status', "=", "APPROVED")
@@ -393,9 +393,10 @@ public function reported($edition = null)
393393

394394
public function influence($edition = null)
395395
{
396-
397396
Log::info("Influence for $this->email for edition $edition");
398-
if (is_null($this->tag)) return 0;
397+
if (is_null($this->tag)) {
398+
return 0;
399+
}
399400

400401
// $nameInTag = TagsHelper::getNameInTag($this->tag);
401402

@@ -440,7 +441,6 @@ public function unsubscribe()
440441

441442
public function getEventsToReviewCount()
442443
{
443-
444444
if (auth()->user()->isAmbassador()) {
445445
return EventHelper::getPendingEventsCount($this->country_iso);
446446
}
@@ -457,7 +457,6 @@ public function getEventsToReviewCount()
457457

458458
public function getNextPendingEvent(Event $event)
459459
{
460-
461460
if (auth()->user()->isAmbassador()) {
462461
return EventHelper::getNextPendingEvent($event, $this->country_iso);
463462
}
@@ -483,4 +482,31 @@ public function taggedActivities()
483482
}
484483

485484

485+
public function hasGivenConsent()
486+
{
487+
return $this->consent_given_at !== null;
488+
}
489+
490+
public function hasGivenFutureConsent()
491+
{
492+
return $this->future_consent_given_at !== null;
493+
}
494+
495+
public function giveConsent()
496+
{
497+
if (!$this->hasGivenConsent()) {
498+
$this->consent_given_at = now();
499+
$this->save();
500+
}
501+
}
502+
503+
public function giveFutureConsent()
504+
{
505+
if (!$this->hasGivenFutureConsent()) {
506+
$this->future_consent_given_at = now();
507+
$this->save();
508+
}
509+
}
510+
511+
486512
}

0 commit comments

Comments
 (0)