Skip to content

Commit

Permalink
v8 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
riasvdv committed Apr 11, 2024
1 parent b33aa1f commit 67dce12
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 204 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/WelcomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public function sendPasswordSavedResponse(): Response
{
notify(__mc('Your password has been saved.'));

return redirect()->route('mailcoach.campaigns');
return redirect()->route('mailcoach.dashboard');
}
}
13 changes: 10 additions & 3 deletions app/Listeners/SetupMailcoach.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@ public function handle(ServingMailcoach $event): void
MenuItem::make()
->label(__mc('Account'))
->url(route('account'))
->icon('fa-user'),
->icon('heroicon-s-user'),
MenuItem::make()
->label(__mc('Users'))
->url(route('users'))
->icon('fa-users'),
->icon('heroicon-s-user-group'),
);

Mailcoach::addUserMenuItemsAfter(
MenuItem::make()->divider(),
MenuItem::make()
->label(__mc('Documentation'))
->icon('heroicon-s-academic-cap')
->external()
->url('https://mailcoach.app/self-hosted/documentation'),
MenuItem::make()->divider(),
MenuItem::make()
->isForm()
->label(__mc('Log out'))
->url(route('logout'))
->icon('fa-power-off text-red-500'),
->icon('heroicon-s-arrow-right-start-on-rectangle'),
);

Mailcoach::addSettingsMenuItemsBefore(
Expand Down
38 changes: 30 additions & 8 deletions app/Livewire/AccountComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

namespace App\Livewire;

use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rule;
use Laravel\Sanctum\PersonalAccessToken;
use Livewire\Component;

class AccountComponent extends Component
class AccountComponent extends Component implements HasForms, HasActions
{
use InteractsWithActions;
use InteractsWithForms;

public string $email;

public string $name;
Expand Down Expand Up @@ -77,13 +84,28 @@ public function saveToken()
$this->tokenName = '';
}

public function deleteToken(PersonalAccessToken $token)
public function deleteTokenAction(): Action
{
abort_unless($token?->tokenable_id === Auth::id(), 403);

$token->delete();

notify(__mc('The token has been deleted.'));
return Action::make('deleteToken')
->requiresConfirmation()
->icon('heroicon-s-trash')
->color('danger')
->link()
->label('')
->tooltip(__mc('Delete token'))
->modalIcon('heroicon-s-trash')
->modalHeading(__mc('Delete token'))
->modalDescription(__mc('Are you sure you want to delete this token?'))
->modalCloseButton(false)
->action(function (array $arguments) {
$token = Auth::user()->personalAccessTokens->find($arguments['token']);

abort_unless($token, 404);

$token->delete();

notify(__mc('The token has been deleted.'));
});
}

public function render()
Expand Down
13 changes: 11 additions & 2 deletions app/Livewire/CreateUserComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@

namespace App\Livewire;

use App\Models\User;
use App\User;

This comment has been minimized.

Copy link
@danielzabotti

danielzabotti Jun 4, 2024

Contributor

Possible cause for issue #1617?

use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Livewire\Component;
use Spatie\WelcomeNotification\WelcomeNotification;

class CreateUserComponent extends Component
class CreateUserComponent extends Component implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;

public string $email = '';

public string $name = '';
Expand Down
3 changes: 2 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Laravel\Sanctum\PersonalAccessToken;
use Spatie\Mailcoach\Domain\Settings\Models\MailcoachUser;
use Spatie\Mailcoach\Domain\Shared\Traits\UsesMailcoachModels;
use Spatie\WelcomeNotification\ReceivesWelcomeNotification;
Expand Down Expand Up @@ -48,7 +49,7 @@ protected function casts(): array

public function personalAccessTokens(): MorphMany
{
return $this->morphMany(self::getPersonalAccessTokenClass(), 'tokenable');
return $this->morphMany(PersonalAccessToken::class, 'tokenable');
}

public function canViewMailcoach(): bool
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"laravel/horizon": "^5.22",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.9",
"spatie/laravel-mailcoach": "^7.0"
"spatie/laravel-mailcoach": "^8.0"
},
"require-dev": {
"fakerphp/faker": "^1.23",
Expand Down
93 changes: 40 additions & 53 deletions resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
@@ -1,54 +1,41 @@
@extends('auth.layout', ['title' => __mc('Log in')])

@section('content')
<h1 class="markup-h2">{{ __mc('Log in') }}</h1>

<form class="form-grid" method="POST" action="{{ route('login') }}">
@csrf

<div class="form-field">
@error('email')
<p class="form-error" role="alert">
{{ $message }}
</p>
@enderror

<label for="email" class="label">{{ __mc('Email') }}</label>

<input id="email" type="email" class="input @error('email') is-invalid @enderror" name="email"
value="{{ old('email') }}" required autocomplete="email" autofocus>
</div>

<div class="form-field">
@error('password')
<p class="form-error" role="alert">
{{ $message }}
</p>
@enderror

<label for="password" class="label">{{ __mc('Password') }}</label>

<input id="password" type="password" class="input @error('password') is-invalid @enderror"
name="password" required autocomplete="current-password">
<x-mailcoach::layout :title="__mc('Login')" hide-footer hide-nav>
<div class="flex flex-col gap-6 justify-center mt-12">
<div class="w-20 mx-auto">
@include('mailcoach::app.layouts.partials.logoSvg')
</div>

<div class="form-field">
<label class="checkbox-label" for="remember">
<input class="checkbox" type="checkbox" name="remember" id="remember"
{{ old('remember') ? 'checked' : '' }}>

{{ __mc('Remember me next time') }}
</label>
</div>

<x-mailcoach::form-buttons>
<x-mailcoach::button :label="__mc('Log in')" />

@if (Route::has('forgot-password'))
<a class="link ml-2" href="{{ route('forgot-password') }}">
{{ __mc('Forgot Your Password?') }}
</a>
@endif
</x-mailcoach::form-buttons>
</form>
@endsection
<x-mailcoach::fieldset class="w-full max-w-md mx-auto" card :legend="__mc('Log in')">
<form class="form-grid" method="POST" action="{{ route('login') }}">
@csrf

<x-mailcoach::text-field
:label="__mc('Email')"
name="email"
type="email"
autofocus
autocomplete="email"
required
/>

<x-mailcoach::text-field
:label="__mc('Password')"
name="password"
type="password"
autocomplete="current-password"
required
/>

<x-mailcoach::form-buttons>
<x-mailcoach::button :label="__mc('Log in')" />

@if (Route::has('forgot-password'))
<a class="ml-3" href="{{ route('forgot-password') }}">
<x-mailcoach::button-link
:label="__mc('Forgot Your Password?')"
/>
</a>
@endif
</x-mailcoach::form-buttons>
</form>
</x-mailcoach::fieldset>
</div>
</x-mailcoach::layout>
46 changes: 23 additions & 23 deletions resources/views/auth/passwords/email.blade.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
@extends('auth.layout', ['title' => __mc('Forgot password?')])
@section('content')
<h1 class="markup-h2">{{ __mc('Forgot password?') }}</h1>

<form class="form-grid" method="POST" action="{{ route('password.email') }}">
@csrf

<div class="form-field">
@error('email')
<p class="form-error" role="alert">
{{ $message }}
</p>
@enderror

<label for="email" class="label">{{ __mc('Email') }}</label>

<input id="email" type="email" class="input @error('email') is-invalid @enderror" name="email"
value="{{ old('email') }}" required autocomplete="email" autofocus>
<x-mailcoach::layout :title="__mc('Forgot password?')" hide-footer hide-nav>
<div class="flex flex-col gap-6 justify-center mt-12">
<div class="w-20 mx-auto">
@include('mailcoach::app.layouts.partials.logoSvg')
</div>
<x-mailcoach::fieldset class="w-full max-w-md mx-auto" card :legend="__mc('Forgot password?')">
<form class="form-grid" method="POST" action="{{ route('password.email') }}">
@csrf

<x-mailcoach::text-field
:label="__mc('Email')"
name="email"
type="email"
autofocus
autocomplete="email"
required
/>

<x-mailcoach::form-buttons>
<x-mailcoach::button :label="__mc('Send password reset link')" />
</x-mailcoach::form-buttons>
</form>
@endsection
<x-mailcoach::form-buttons>
<x-mailcoach::button :label="__mc('Send password reset link')" />
</x-mailcoach::form-buttons>
</form>
</x-mailcoach::fieldset>
</div>
</x-mailcoach::layout>
91 changes: 42 additions & 49 deletions resources/views/auth/passwords/reset.blade.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,43 @@
@extends('auth.layout', ['title' => __mc('Reset password')])
@section('content')
<h1 class="markup-h2">{{ __mc('Reset Password') }}</h1>

<form class="form-grid" method="POST" action="{{ route('password.update') }}">
@csrf

<input type="hidden" name="token" value="{{ $token }}">

<div class="form-field">
<label for="email" class="label">{{ __mc('Email') }}</label>

<div>
{{ $email ?? old('email') }}
</div>
</div>

<input id="email" type="hidden" class="input @error('email') is-invalid @enderror" name="email"
value="{{ $email ?? old('email') }}" required autocomplete="email">

<div class="form-field">
@error('password')
<p class="form-error" role="alert">
{{ $message }}
</p>
@enderror

<label for="password" class="label">{{ __mc('Password') }}</label>

<div class="col-md-6">
<input id="password" type="password" class="input @error('password') is-invalid @enderror"
name="password" autofocus required autocomplete="new-password">

</div>
<x-mailcoach::layout :title="__mc('Reset password')" hide-footer hide-nav>
<div class="flex flex-col gap-6 justify-center mt-12">
<div class="w-20 mx-auto">
@include('mailcoach::app.layouts.partials.logoSvg')
</div>

<div class="form-field">
<label for="password-confirm"
class="label">{{ __mc('Confirm password') }}</label>

<input id="password-confirm" type="password" class="input" name="password_confirmation"
required
autocomplete="new-password">
</div>

<x-mailcoach::form-buttons>
<x-mailcoach::button :label="__mc('Reset Password')" />
</x-mailcoach::form-buttons>
</form>
@endsection
<x-mailcoach::fieldset class="w-full max-w-md mx-auto" card :legend="__mc('Reset password')">
<form class="form-grid" method="POST" action="{{ route('password.update') }}">
@csrf

<input type="hidden" name="token" value="{{ $token }}">

<x-mailcoach::text-field
:label="__mc('Email')"
name="email"
type="email"
autocomplete="email"
:value="request('email') ?? old('email')"
required
/>

<x-mailcoach::text-field
:label="__mc('Password')"
name="password"
type="password"
autocomplete="new-password"
required
/>

<x-mailcoach::text-field
:label="__mc('Confirm password')"
name="password_confirmation"
type="password"
autocomplete="new-password"
required
/>

<x-mailcoach::form-buttons>
<x-mailcoach::button :label="__mc('Reset Password')" />
</x-mailcoach::form-buttons>
</form>
</x-mailcoach::fieldset>
</div>
</x-mailcoach::layout>
Loading

0 comments on commit 67dce12

Please sign in to comment.