Add artisan commands to update expired roles and delete unverified users

This commit is contained in:
DariusIII
2019-06-30 23:03:52 +02:00
parent 0a17515714
commit 897647d04a
10 changed files with 236 additions and 9 deletions
+1
View File
@@ -1,4 +1,5 @@
2019-06-30 DariusIII
* Chg: Add artisan commands to update expired roles and delete unverified users
* Chg: Update tinyMCE to latest version
2019-06-29 DariusIII
* Chg: Update used libraries to their latest versions
@@ -0,0 +1,45 @@
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
class NntmuxDeleteUnVerifiedUsers extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'nntmux:delete-unverified-users';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Deletes unverified users from site';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('Deleting unverified users.');
User::deleteUnVerified();
$this->info('Unverified users deleted.');
}
}
@@ -0,0 +1,45 @@
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
class NntmuxUpdateExpiredRoles extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'nntmux:update-expired-roles';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update users who\'s user role has expired';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('Updating expired roles.');
User::updateExpiredRoles();
$this->info('Expired roles updated.');
}
}
+2 -1
View File
@@ -27,7 +27,8 @@ class Kernel extends ConsoleKernel
{
$schedule->command('disposable:update')->weekly();
$schedule->command('clean:directories')->hourly();
$schedule->exec('php '.base_path().'/misc/testing/DB/checkUsers.php')->twiceDaily(1, 13);
$schedule->command('nntmux:delete-unverified-users')->twiceDaily(1, 13);
$schedule->command('nntmux:update-expired-roles')->twiceDaily(1, 13);
$schedule->command('telescope:prune')->daily();
$schedule->command('horizon:snapshot')->everyFiveMinutes();
if (config('nntmux.purge_inactive_users') === true) {
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use App\Mail\AccountWillExpire;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Mail;
class SendAccountWillExpireEmail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private $days;
private $user;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($user, $days)
{
$this->user = $user;
$this->days = $days;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Mail::to($this->user->email)->send(new AccountWillExpire($this->user, $this->days));
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
namespace App\Mail;
use App\Models\Settings;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class AccountWillExpire extends Mailable
{
use Queueable, SerializesModels;
private $days;
private $user;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($user, $days)
{
$this->user = $user;
$this->days = $days;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from(Settings::settingValue('site.main.email'))->subject('Account about to expire')->view('emails.accountAboutToExpire')->with(['account' => $this->user->role->name, 'username' => $this->user->username, 'site' => Settings::settingValue('site.main.title'), 'days' => $this->days]);
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RoleExpirationEmail extends Model
{
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class, 'users_id');
}
}
@@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRoleExpirationEmailsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('role_expiration_emails', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('users_id')->unique();
$table->timestamps();
$table->boolean('day')->default(false);
$table->boolean('week')->default(false);
$table->boolean('month')->default(false);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('role_expiration_emails');
}
}
-8
View File
@@ -1,8 +0,0 @@
<?php
require_once dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
use App\Models\User;
User::updateExpiredRoles();
User::deleteUnVerified();
@@ -0,0 +1,13 @@
@extends('emails.email_layout')
@section('title')
Your account is about to expire
@endsection
@section('content')
Dear {{ $username }},
<br>
Your account role {{ $account }} is about to expire in less than {{ $days }} day(s).
<br><br><br>
Greetings from {{ $site }}
@endsection