Skip to content

Commit

Permalink
move fortify stuff to blog
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley committed Sep 26, 2024
1 parent eef2748 commit d03d807
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 128 deletions.
1 change: 0 additions & 1 deletion resources/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ module.exports = {
content: [
"./resources/views/**/*.blade.php",
"./vendor/arkecosystem/foundation/resources/views/**/*.blade.php",
"./vendor/arkecosystem/fortify/resources/views/**/*.blade.php",
"./vendor/arkecosystem/hermes/resources/views/**/*.blade.php",
"./resources/js/**/*.js",
"./resources/js/**/*.vue",
Expand Down
19 changes: 19 additions & 0 deletions src/Blog/Components/Concerns/InteractsWithUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace ARKEcosystem\Foundation\Blog\Components\Concerns;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Auth;

/**
* @property ?Authenticatable $user
*/
trait InteractsWithUser
{
public function getUserProperty(): ?Authenticatable
{
return Auth::user();
}
}
10 changes: 10 additions & 0 deletions src/Blog/Contracts/UserRole.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace ARKEcosystem\Foundation\Blog\Contracts;

interface UserRole
{
public static function toArray(): array;
}
36 changes: 36 additions & 0 deletions src/Blog/Http/Middleware/EnforceTwoFactorAuthentication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace ARKEcosystem\Foundation\Blog\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

final class EnforceTwoFactorAuthentication
{
/**
* Handle an incoming request.
*
* @param Request $request
* @return mixed
*/
public function handle($request, Closure $next)
{
$user = $request->user();

if (config('web.2fa_enabled') === false) {
return $next($request);
}

if ($user === null) {
return $next($request);
}

if ($user->two_factor_secret) {
return $next($request);
}

return redirect()->route('kiosk');
}
}
26 changes: 26 additions & 0 deletions src/Blog/Models/Concerns/HasLocalizedTimestamps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace ARKEcosystem\Foundation\Blog\Models\Concerns;

use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;

trait HasLocalizedTimestamps
{
public function getCreatedAtLocalAttribute(): Carbon
{
$timezone = Auth::check() ? Auth::user()->timezone : Config::get('app.timezone');

return Carbon::parse($this->created_at)->timezone($timezone);
}

public function getUpdatedAtLocalAttribute(): Carbon
{
$timezone = Auth::check() ? Auth::user()->timezone : Config::get('app.timezone');

return Carbon::parse($this->updated_at)->timezone($timezone);
}
}
48 changes: 46 additions & 2 deletions src/Blog/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,49 @@

namespace ARKEcosystem\Foundation\Blog\Models;

use ARKEcosystem\Foundation\Blog\Models\Concerns\HasLocalizedTimestamps;
use ARKEcosystem\Foundation\Blog\Models\Factories\UserFactory;
use ARKEcosystem\Foundation\Fortify\Models\User as BaseUser;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Str;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\PersonalDataExport\PersonalDataSelection;
use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;

class User extends BaseUser implements HasMedia
class User extends Authenticatable implements HasMedia
{
use HasSlug;
use HasFactory;
use HasLocalizedTimestamps;
use Notifiable;
use InteractsWithMedia;
use SoftDeletes;
use TwoFactorAuthenticatable;

/**
* The attributes that aren't mass assignable.
*
* @var array|bool
*/
protected $guarded = false;

/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
'two_factor_recovery_codes',
'two_factor_secret',
];

/**
* The attributes that should be cast to native types.
Expand Down Expand Up @@ -60,6 +85,25 @@ public function registerMediaCollections() : void
$this->addMediaCollection('photo')->singleFile();
}

/**
* @codeCoverageIgnore
*/
public function selectPersonalData(PersonalDataSelection $personalData): void
{
$personalData->add('user.json', [
'name' => $this->name,
'email' => $this->email,
]);
}

/**
* @codeCoverageIgnore
*/
public function personalDataExportName(): string
{
return 'personal-data-'.Str::slug($this->name).'.zip';
}

/**
* Create a new factory instance for the model.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Hermes/Components/ManageNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ARKEcosystem\Foundation\Hermes\Components;

use ARKEcosystem\Foundation\Fortify\Components\Concerns\InteractsWithUser;
use ARKEcosystem\Foundation\Blog\Components\Concerns\InteractsWithUser;
use ARKEcosystem\Foundation\Hermes\Enums\NotificationFilterEnum;
use Illuminate\Contracts\View\View;
use Illuminate\Notifications\DatabaseNotification;
Expand Down
2 changes: 1 addition & 1 deletion src/Hermes/Models/DatabaseNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ARKEcosystem\Foundation\Hermes\Models;

use ARKEcosystem\Foundation\Fortify\Models\Concerns\HasLocalizedTimestamps;
use ARKEcosystem\Foundation\Blog\Models\Concerns\HasLocalizedTimestamps;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Notifications\DatabaseNotification as BaseNotification;
Expand Down
114 changes: 0 additions & 114 deletions src/Providers/NovaServiceProvider.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/Blog/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Tests\Blog;

use ARKEcosystem\Foundation\Blog\Enums\Category;
use ARKEcosystem\Foundation\Fortify\Http\Middleware\EnforceTwoFactorAuthentication;
use ARKEcosystem\Foundation\Blog\Http\Middleware\EnforceTwoFactorAuthentication;
use ARKEcosystem\Foundation\Providers\BlogServiceProvider;
use ARKEcosystem\Foundation\Providers\MarkdownServiceProvider;
use ARKEcosystem\Foundation\Providers\UserInterfaceServiceProvider;
Expand Down
2 changes: 1 addition & 1 deletion tests/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Tests;

use ARKEcosystem\Foundation\Fortify\Models\User;
use ARKEcosystem\Foundation\Blog\Models\User;
use Carbon\Carbon;
use Closure;
use Illuminate\Support\Facades\DB;
Expand Down
1 change: 0 additions & 1 deletion tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'CommonMark',
'DataBags',
'Documentation',
'Fortify',
'NumberFormatter',
'Rules',
'Support',
Expand Down
2 changes: 1 addition & 1 deletion tests/Rules/UniqueCaseInsensitiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use ARKEcosystem\Foundation\Fortify\Models\User;
use ARKEcosystem\Foundation\Blog\Models\User;
use ARKEcosystem\Foundation\Rules\UniqueCaseInsensitive;

beforeEach(function (): void {
Expand Down
7 changes: 2 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

namespace Tests;

use ARKEcosystem\Foundation\Providers\CommonMarkServiceProvider;
use ARKEcosystem\Foundation\Providers\FortifyServiceProvider;
use ARKEcosystem\Foundation\Providers\HermesServiceProvider;
use ARKEcosystem\Foundation\Providers\MarkdownServiceProvider;
use ARKEcosystem\Foundation\Providers\RulesServiceProvider;
use ARKEcosystem\Foundation\Providers\UserInterfaceServiceProvider;
use Illuminate\Foundation\Testing\Concerns\InteractsWithViews;
use Illuminate\Support\Facades\View;
use Illuminate\Testing\TestView;
use Laravel\Fortify\FortifyServiceProvider as LaravelFortifyServiceProvider;
use Laravel\Fortify\FortifyServiceProvider;
use Livewire\LivewireServiceProvider;
use Orchestra\Testbench\TestCase as Orchestra;
use Spatie\Honeypot\HoneypotServiceProvider;
Expand Down Expand Up @@ -67,12 +65,11 @@ protected function getPackageProviders($app)
{
return [
// Third-Party
LaravelFortifyServiceProvider::class,
FortifyServiceProvider::class,
MarkdownServiceProvider::class,
LivewireServiceProvider::class,
HoneypotServiceProvider::class,
// First-Party
FortifyServiceProvider::class,
HermesServiceProvider::class,
NewsletterServiceProvider::class,
RulesServiceProvider::class,
Expand Down

0 comments on commit d03d807

Please sign in to comment.