Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #2250

Merged
merged 21 commits into from
Jul 1, 2024
Merged

Dev #2250

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions app/Http/Controllers/ConsentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ConsentController extends Controller
{
public function show()
{
return view('consent');
}

public function store(Request $request)
{
$user = Auth::user();

if ($request->input('consent1') === '1') {
//$user->consent_given_at = now();
$user->giveConsent();
if ($request->input('consent2') === '1') {
$user->giveFutureConsent();
}

return redirect()->route('home');
}

Auth::logout();
return redirect('/');
}

public function logout()
{
Auth::logout();
return redirect('/login');
}
}

6 changes: 4 additions & 2 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http;

use App\Http\Middleware\EnsureUserHasGivenConsent;
use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
Expand All @@ -20,7 +21,7 @@ class Kernel extends HttpKernel
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\TrustProxies::class,
\Spatie\CookieConsent\CookieConsentMiddleware::class,
\Spatie\CookieConsent\CookieConsentMiddleware::class
];

/**
Expand All @@ -39,6 +40,7 @@ class Kernel extends HttpKernel
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\Locale::class,
\App\Http\Middleware\CheckConsent::class,
],

'api' => [
Expand All @@ -63,6 +65,6 @@ class Kernel extends HttpKernel
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class
];
}
26 changes: 26 additions & 0 deletions app/Http/Middleware/CheckConsent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class CheckConsent
{
public function handle($request, Closure $next)
{
$excludedRoutes = [
'consent.show',
'consent.store',
'consent.logout',
];

if (Auth::check() && !Auth::user()->hasGivenConsent()) {
if (!in_array($request->route()->getName(), $excludedRoutes)) {
return redirect()->route('consent.show');
}
}

return $next($request);
}
}
102 changes: 64 additions & 38 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ class User extends Authenticatable
*
* @var array
*/
// protected $fillable = [
// 'firstname', 'lastname', 'username', 'avatar_path', 'email', 'password', 'bio', 'twitter', 'website', 'country_iso', 'privacy', 'email_display', 'receive_emails', 'magic_key','current_country','provider'
// ];


protected $guarded = [];

Expand All @@ -110,19 +108,27 @@ class User extends Authenticatable
* @var array
*/
protected $hidden = [
'password', 'remember_token', 'magic_key'
'password',
'remember_token',
'magic_key'
];

protected $appends = ['fullName'];

protected $dates = ['deleted_at'];
protected $dates = ['consent_given_at', 'future_consent_given_at'];


public function getName()
{
if (!empty($this->username)) return $this->username;
if (!empty($this->firstname) && !empty($this->lastname)) return $this->firstname . " " . $this->lastname;
if (!empty($this->firstname) && empty($this->lastname)) return $this->firstname;
if (!empty($this->username)) {
return $this->username;
}
if (!empty($this->firstname) && !empty($this->lastname)) {
return $this->firstname . " " . $this->lastname;
}
if (!empty($this->firstname) && empty($this->lastname)) {
return $this->firstname;
}
return $this->email;
}

Expand All @@ -139,8 +145,6 @@ public function setAmbassadorAttribute($value)
} else {
$this->removeRole('ambassador');
}


}

public function achievements()
Expand All @@ -155,19 +159,15 @@ public function getLeadingTeacherAttribute()

public function setLeadingTeacherAttribute($value)
{

if ($value) {
$this->assignRole('leading teacher');
} else {
$this->removeRole('leading teacher');
}


}

public function isAdmin()
{

return $this->hasRole("super admin");
}

Expand Down Expand Up @@ -218,7 +218,8 @@ public function participations()

public function expertises()
{
return $this->belongsToMany(LeadingTeacherExpertise::class, 'leading_teacher_expertise_user', 'user_id', 'lte_id');
return $this->belongsToMany(LeadingTeacherExpertise::class, 'leading_teacher_expertise_user', 'user_id',
'lte_id');
}

public function levels()
Expand Down Expand Up @@ -259,25 +260,27 @@ public function actions()

public function resetExperience($year = null)
{
if (is_null($year)) $year = Carbon::now()->year;
if (is_null($year)) {
$year = Carbon::now()->year;
}
$this->getExperience($year)->update(
["points" => 0]
);


}

public function getPoints($year = null)
{
if (is_null($year)) $year = Carbon::now()->year;
if (is_null($year)) {
$year = Carbon::now()->year;
}
return $this->getExperience($year)->points;


}

public function getExperience($year = null)
{
if (is_null($year)) $year = Carbon::now()->year;
if (is_null($year)) {
$year = Carbon::now()->year;
}

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

public function awardExperience($points, $year = null)
{

if (is_null($year)) $year = Carbon::now()->year;
if (is_null($year)) {
$year = Carbon::now()->year;
}
$this->getExperience($year)->awardExperience($points);

}

public function stripExperience($points, $year = null)
{
if (is_null($year)) $year = Carbon::now()->year;
if (is_null($year)) {
$year = Carbon::now()->year;
}
$this->getExperience($year)->stripExperience($points);

}


Expand All @@ -316,9 +320,10 @@ public function stripExperience($points, $year = null)
*/
public function getAvatarPathAttribute($avatar)
{
if (is_null($avatar)) $avatar = 'avatars/default_avatar.png';
if (is_null($avatar)) {
$avatar = 'avatars/default_avatar.png';
}
return Storage::disk('s3')->url($avatar);

}

/**
Expand All @@ -329,14 +334,11 @@ public function getAvatarPathAttribute($avatar)
*/
public function getAvatarAttribute()
{

$arr = explode("/", $this->avatar_path);
$filename = array_pop($arr);
array_push($arr, $filename);
$glued = implode("/", $arr);
return $glued;


}


Expand Down Expand Up @@ -365,7 +367,6 @@ public static function getGeoIPData()

public function activities($edition)
{

return DB::table('events')
->where('creator_id', '=', $this->id)
->where('status', "=", "APPROVED")
Expand All @@ -376,7 +377,6 @@ public function activities($edition)

public function reported($edition = null)
{

$query = DB::table('events')
->where('creator_id', '=', $this->id)
->where('status', "=", "APPROVED")
Expand All @@ -393,9 +393,10 @@ public function reported($edition = null)

public function influence($edition = null)
{

Log::info("Influence for $this->email for edition $edition");
if (is_null($this->tag)) return 0;
if (is_null($this->tag)) {
return 0;
}

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

Expand Down Expand Up @@ -440,7 +441,6 @@ public function unsubscribe()

public function getEventsToReviewCount()
{

if (auth()->user()->isAmbassador()) {
return EventHelper::getPendingEventsCount($this->country_iso);
}
Expand All @@ -457,7 +457,6 @@ public function getEventsToReviewCount()

public function getNextPendingEvent(Event $event)
{

if (auth()->user()->isAmbassador()) {
return EventHelper::getNextPendingEvent($event, $this->country_iso);
}
Expand All @@ -483,4 +482,31 @@ public function taggedActivities()
}


public function hasGivenConsent()
{
return $this->consent_given_at !== null;
}

public function hasGivenFutureConsent()
{
return $this->future_consent_given_at !== null;
}

public function giveConsent()
{
if (!$this->hasGivenConsent()) {
$this->consent_given_at = now();
$this->save();
}
}

public function giveFutureConsent()
{
if (!$this->hasGivenFutureConsent()) {
$this->future_consent_given_at = now();
$this->save();
}
}


}
Loading
Loading