diff --git a/Changelog b/Changelog index e0363f482..8cd5d1d24 100755 --- a/Changelog +++ b/Changelog @@ -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 diff --git a/app/Console/Commands/NntmuxDeleteUnVerifiedUsers.php b/app/Console/Commands/NntmuxDeleteUnVerifiedUsers.php new file mode 100644 index 000000000..daed3f240 --- /dev/null +++ b/app/Console/Commands/NntmuxDeleteUnVerifiedUsers.php @@ -0,0 +1,45 @@ +info('Deleting unverified users.'); + User::deleteUnVerified(); + $this->info('Unverified users deleted.'); + } +} diff --git a/app/Console/Commands/NntmuxUpdateExpiredRoles.php b/app/Console/Commands/NntmuxUpdateExpiredRoles.php new file mode 100644 index 000000000..7e99e0caf --- /dev/null +++ b/app/Console/Commands/NntmuxUpdateExpiredRoles.php @@ -0,0 +1,45 @@ +info('Updating expired roles.'); + User::updateExpiredRoles(); + $this->info('Expired roles updated.'); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 1a89c191d..317093599 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -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) { diff --git a/app/Jobs/SendAccountWillExpireEmail.php b/app/Jobs/SendAccountWillExpireEmail.php new file mode 100644 index 000000000..018930de1 --- /dev/null +++ b/app/Jobs/SendAccountWillExpireEmail.php @@ -0,0 +1,41 @@ +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)); + } +} diff --git a/app/Mail/AccountWillExpire.php b/app/Mail/AccountWillExpire.php new file mode 100644 index 000000000..8dad2c419 --- /dev/null +++ b/app/Mail/AccountWillExpire.php @@ -0,0 +1,38 @@ +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]); + } +} diff --git a/app/Models/RoleExpirationEmail.php b/app/Models/RoleExpirationEmail.php new file mode 100644 index 000000000..4ae41a4c6 --- /dev/null +++ b/app/Models/RoleExpirationEmail.php @@ -0,0 +1,16 @@ +belongsTo(User::class, 'users_id'); + } +} diff --git a/database/migrations/2019_06_14_095012_create_role_expiration_emails_table.php b/database/migrations/2019_06_14_095012_create_role_expiration_emails_table.php new file mode 100644 index 000000000..3e4f1b3ed --- /dev/null +++ b/database/migrations/2019_06_14_095012_create_role_expiration_emails_table.php @@ -0,0 +1,35 @@ +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'); + } +} diff --git a/misc/testing/DB/checkUsers.php b/misc/testing/DB/checkUsers.php deleted file mode 100644 index aa361f2cd..000000000 --- a/misc/testing/DB/checkUsers.php +++ /dev/null @@ -1,8 +0,0 @@ - + Your account role {{ $account }} is about to expire in less than {{ $days }} day(s). +


+ Greetings from {{ $site }} +@endsection