Skip to content

Commit

Permalink
update to v3 + install sanctum
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Aug 3, 2020
1 parent ab13009 commit 2b3730a
Show file tree
Hide file tree
Showing 18 changed files with 339 additions and 100,570 deletions.
34 changes: 34 additions & 0 deletions app/Http/App/Controllers/Settings/Account/TokensController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Http\App\Controllers\Settings\Account;

use App\Http\App\Requests\UpdatePasswordRequest;
use App\Models\PersonalAccessToken;

class TokensController
{
public function index()
{
return view('app.settings.account.tokens', [
'tokens' => auth()->user()->tokens,
]);
}

public function update(UpdatePasswordRequest $request)
{
auth()->user()->update(['password' => bcrypt($request->password)]);

flash()->success(__('Your password has been updated.'));

return redirect()->action([static::class, 'index']);
}

public function destroy(PersonalAccessToken $personalAccessToken)
{
$personalAccessToken->delete();

flash()->success(__('The token has been deleted.'));

return back();
}
}
14 changes: 14 additions & 0 deletions app/Models/PersonalAccessToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;

class PersonalAccessToken extends Model
{
public function tokenable(): MorphTo
{
return $this->morphTo();
}
}
9 changes: 8 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\WelcomeNotification\ReceivesWelcomeNotification;

class User extends Authenticatable
{
use Notifiable, ReceivesWelcomeNotification;
use Notifiable, ReceivesWelcomeNotification, HasApiTokens;

/**
* The attributes that are mass assignable.
Expand Down Expand Up @@ -36,4 +38,9 @@ class User extends Authenticatable
protected $casts = [
'email_verified_at' => 'datetime',
];

public function tokens(): MorphMany
{
return $this->morphMany(PersonalAccessToken::class, 'tokenable');
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
"guzzlehttp/guzzle": "^6.5",
"laravel/framework": "^7.0",
"laravel/horizon": "^4.0",
"laravel/sanctum": "^2.4",
"laravel/tinker": "^2.0",
"laravel/ui": "^2.0",
"spatie/laravel-flash": "^1.5",
"spatie/laravel-json-api-paginate": "^1.7",
"spatie/laravel-mailcoach": "v3.x-dev",
"spatie/laravel-mailcoach": "v3.x-dev as v2.7",
"spatie/laravel-mailcoach-mailgun-feedback": "^2.0",
"spatie/laravel-mailcoach-monaco": "^1.0",
"spatie/laravel-mailcoach-postmark-feedback": "^2.0",
Expand Down
67 changes: 60 additions & 7 deletions config/mailcoach.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
\Spatie\Mailcoach\Support\Replacers\SubscriberReplacer::class,
\Spatie\Mailcoach\Support\Replacers\EmailListReplacer::class,
\Spatie\Mailcoach\Support\Replacers\UnsubscribeUrlReplacer::class,
\Spatie\Mailcoach\Support\Replacers\CampaignReplacer::class,
],

/**
Expand All @@ -50,6 +51,7 @@
'send_campaign_job' => 'send-campaign',
'send_mail_job' => 'send-mail',
'send_test_mail_job' => 'mailcoach',
'send_welcome_mail_job' => 'mailcoach',
'process_feedback_job' => 'mailcoach-feedback',
'import_subscribers_job' => 'mailcoach',
],
Expand All @@ -71,6 +73,7 @@
'allowed_number_of_jobs_in_timespan' => 10,
'timespan_in_seconds' => 1,
'release_in_seconds' => 5,
'retry_until_hours' => 24,
],

/*
Expand Down Expand Up @@ -117,19 +120,69 @@
'guard' => env('MAILCOACH_GUARD', null),

/*
* These middleware will be assigned to every Mailcoach UI route, giving you the chance
* These middleware will be assigned to every Mailcoach routes, giving you the chance
* to add your own middleware to this stack or override any of the existing middleware.
*/
'middleware' => [
'web',
Spatie\Mailcoach\Http\App\Middleware\Authenticate::class,
Spatie\Mailcoach\Http\App\Middleware\Authorize::class,
Spatie\Mailcoach\Http\App\Middleware\SetMailcoachDefaults::class,
'web' => [
'web',
Spatie\Mailcoach\Http\App\Middleware\Authenticate::class,
Spatie\Mailcoach\Http\App\Middleware\Authorize::class,
Spatie\Mailcoach\Http\App\Middleware\SetMailcoachDefaults::class,
],
'api' => [
'api',
'auth:sanctum',
],
],

/*
* This disk will be used to store files regarding importing subscribers. This must
* be a disk that uses the `local` driver.
* This disk will be used to store files regarding importing subscribers.
*/
'import_subscribers_disk' => 'public',


'models' => [

/*
* The model you want to use as a Campaign model. It needs to be or
* extend the `Spatie\Mailcoach\Models\Campaign` model.
*/
'campaign' => Spatie\Mailcoach\Models\Campaign::class,

/*
* The model you want to use as a EmailList model. It needs to be or
* extend the `Spatie\Mailcoach\Models\EmailList` model.
*/
'email_list' => Spatie\Mailcoach\Models\EmailList::class,

/*
* The model you want to use as a Subscriber model. It needs to be or
* extend the `Spatie\Mailcoach\Models\Subscriber` model.
*/
'subscriber' => Spatie\Mailcoach\Models\Subscriber::class,

/*
* The model you want to use as a Template model. It needs to be or
* extend the `Spatie\Mailcoach\Models\Template` model.
*/
'template' => Spatie\Mailcoach\Models\Template::class,

],

'views' => [

/*
* The service provider registers several Blade components that are
* used in Mailcoach's views. If you are using the default Mailcoach
* views, leave this as true so they work as expected. If you have
* your own views and don't need/want Mailcoach to register these
* blade components (e.g., because of naming conflicts), you can
* change this setting to false and they won't be registered.
*
* If you change this setting, be sure to run `php artisan view:clear`
* so Laravel can recompile your views.
*/
'use_blade_components' => true,
],
];
47 changes: 47 additions & 0 deletions config/sanctum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Stateful Domains
|--------------------------------------------------------------------------
|
| Requests from the following domains / hosts will receive stateful API
| authentication cookies. Typically, these should include your local
| and production domains which access your API via a frontend SPA.
|
*/

'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', 'localhost,127.0.0.1,127.0.0.1:8000,::1')),

/*
|--------------------------------------------------------------------------
| Expiration Minutes
|--------------------------------------------------------------------------
|
| This value controls the number of minutes until an issued token will be
| considered expired. If this value is null, personal access tokens do
| not expire. This won't tweak the lifetime of first-party sessions.
|
*/

'expiration' => null,

/*
|--------------------------------------------------------------------------
| Sanctum Middleware
|--------------------------------------------------------------------------
|
| When authenticating your first-party SPA with Sanctum you may need to
| customize some of the middleware Sanctum uses while processing the
| request. You may change the middleware listed below as required.
|
*/

'middleware' => [
'verify_csrf_token' => App\Http\Middleware\VerifyCsrfToken::class,
'encrypt_cookies' => App\Http\Middleware\EncryptCookies::class,
],

];
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public function up()
$table->string('welcome_mail_subject')->nullable();
$table->text('welcome_mail_content')->nullable();
$table->string('welcome_mailable_class')->nullable();
$table->boolean('welcome_mail_delay_in_minutes')->default(0);

$table->integer('welcome_mail_delay_in_minutes')->default(0);

$table->string('report_recipients')->nullable();
$table->boolean('report_campaign_sent')->default(false);
Expand All @@ -59,6 +58,9 @@ public function up()
$table->json('extra_attributes')->nullable();

$table->uuid('uuid');

$table->uuid('imported_via_import_uuid')->nullable();

$table->timestamp('subscribed_at')->nullable();
$table->timestamp('unsubscribed_at')->nullable();
$table->nullableTimestamps();
Expand Down Expand Up @@ -272,8 +274,12 @@ public function up()

Schema::create('mailcoach_subscriber_imports', function (Blueprint $table) {
$table->bigIncrements('id');
$table->longText('subscribers_csv')->nullable();
$table->uuid('uuid');
$table->string('status');
$table->unsignedBigInteger('email_list_id');
$table->boolean('subscribe_unsubscribed')->default(false);
$table->boolean('unsubscribe_others')->default(false);
$table->integer('imported_subscribers_count')->default(0);
$table->integer('error_count')->default(0);
$table->timestamps();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePersonalAccessTokensTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->bigIncrements('id');
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('personal_access_tokens');
}
}
Loading

0 comments on commit 2b3730a

Please sign in to comment.