diff --git a/Changelog b/Changelog index 9f45f16a9..db86c57b5 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-11-13 DariusIII + * Chg: Use laravel queue for sending emails * Chg: Update basepage template and remove duplicated meta tags * Chg: Update nesbot/carbon to latest version * Chg: Remove unnecesarry code from login template diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index c0252e837..252b90480 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -2,12 +2,11 @@ namespace App\Http\Controllers\Admin; +use App\Jobs\SendAccountChangedEmail; use App\Models\User; use App\Models\Invitation; -use App\Mail\AccountChange; use Illuminate\Http\Request; use Spatie\Permission\Models\Role; -use Illuminate\Support\Facades\Mail; use App\Http\Controllers\BasePageController; class UserController extends BasePageController @@ -157,7 +156,7 @@ class UserController extends BasePageController } } $email = $request->input('email') ?? $request->input('email'); - Mail::to($email)->send(new AccountChange($request->input('id'))); + SendAccountChangedEmail::dispatch($email, $request->input('id')); } } diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index a1ef852c8..d584acc5b 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Auth; +use App\Jobs\SendPasswordForgottenEmail; use App\Models\User; use App\Models\Settings; use Illuminate\Http\Request; @@ -70,7 +71,7 @@ class ForgotPasswordController extends Controller // Send the email // $resetLink = url('/').'/resetpassword?guid='.$guid; - Mail::to($ret['email'])->send(new ForgottenPassword($resetLink)); + SendPasswordForgottenEmail::dispatch($ret['email'], $resetLink); $sent = true; } diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 9ede85231..dcbc6627b 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Auth; +use App\Jobs\SendPasswordResetEmail; use App\Models\User; use App\Models\Settings; use App\Mail\PasswordReset; @@ -65,9 +66,8 @@ class ResetPasswordController extends Controller $newpass = User::generatePassword(); User::updatePassword($ret['id'], $newpass); - $to = $ret['email']; $onscreen = 'Your password has been reset to '.$newpass.' and sent to your e-mail address.'; - Mail::to($to)->send(new PasswordReset($ret['id'], $newpass)); + SendPasswordResetEmail::dispatch($ret['email'], $ret['id'], $newpass); app('smarty.view')->assign('notice', $onscreen); $confirmed = true; diff --git a/app/Http/Controllers/ContactUsController.php b/app/Http/Controllers/ContactUsController.php index d37fecd95..b81ff614d 100644 --- a/app/Http/Controllers/ContactUsController.php +++ b/app/Http/Controllers/ContactUsController.php @@ -2,10 +2,9 @@ namespace App\Http\Controllers; -use App\Mail\ContactUs; +use App\Jobs\SendContactUsEmail; use App\Models\Settings; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Mail; class ContactUsController extends BasePageController { @@ -42,7 +41,7 @@ class ContactUsController extends BasePageController } if (! preg_match("/\n/i", $request->input('useremail'))) { - Mail::to($mailTo)->send(new ContactUs($email, $mailBody)); + SendContactUsEmail::dispatch($email, $mailTo, $mailBody); } $msg = "

Thank you for getting in touch with ".Settings::settingValue('site.main.title').'.

'; } diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index d5e2cfda5..d93fd2689 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -8,13 +8,11 @@ use Blacklight\SABnzbd; use App\Models\Category; use App\Models\Settings; use App\Models\UserRequest; -use App\Mail\AccountDeleted; use App\Models\UserDownload; use Illuminate\Http\Request; use App\Models\ReleaseComment; use Blacklight\utility\Utility; use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\Mail; use Jrean\UserVerification\Facades\UserVerification; class ProfileController extends BasePageController @@ -363,7 +361,7 @@ class ProfileController extends BasePageController $userId = $request->input('id'); if ($userId !== null && $this->userdata->hasRole('Admin') === false && (int) $userId === Auth::id()) { - Mail::to(Settings::settingValue('site.main.email'))->send(new AccountDeleted($userId)); + User::deleteUser($userId); return redirect('login'); diff --git a/app/Jobs/SendAccountChangedEmail.php b/app/Jobs/SendAccountChangedEmail.php new file mode 100644 index 000000000..3cfffe4ce --- /dev/null +++ b/app/Jobs/SendAccountChangedEmail.php @@ -0,0 +1,42 @@ +email = $email; + $this->id = $id; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + Mail::to($this->email)->send(new AccountChange($this->id)); + } +} diff --git a/app/Jobs/SendAccountDeletedEmail.php b/app/Jobs/SendAccountDeletedEmail.php new file mode 100644 index 000000000..1127b5d64 --- /dev/null +++ b/app/Jobs/SendAccountDeletedEmail.php @@ -0,0 +1,39 @@ +userId = $userId; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + Mail::to(Settings::settingValue('site.main.email'))->send(new AccountDeleted($this->userId)); + } +} diff --git a/app/Jobs/SendAccountExpiredEmail.php b/app/Jobs/SendAccountExpiredEmail.php new file mode 100644 index 000000000..188ad2f73 --- /dev/null +++ b/app/Jobs/SendAccountExpiredEmail.php @@ -0,0 +1,43 @@ +email = $email; + $this->userId = $userId; + + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + Mail::to($this->email)->send(new AccountExpired($this->userId)); + } +} diff --git a/app/Jobs/SendContactUsEmail.php b/app/Jobs/SendContactUsEmail.php new file mode 100644 index 000000000..e977dd291 --- /dev/null +++ b/app/Jobs/SendContactUsEmail.php @@ -0,0 +1,44 @@ +email = $email; + $this->mailTo = $mailTo; + $this->mailBody = $mailBody; + } + + /** + * + */ + public function handle() + { + Mail::to($this->mailTo)->send(new ContactUs($this->email, $this->mailBody)); + } +} diff --git a/app/Jobs/SendInviteEmail.php b/app/Jobs/SendInviteEmail.php new file mode 100644 index 000000000..b0af522d4 --- /dev/null +++ b/app/Jobs/SendInviteEmail.php @@ -0,0 +1,45 @@ +email = $email; + $this->userId = $userId; + $this->url = $url; } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + Mail::to($this->email)->send(new SendInvite($this->userId, $this->url)); + } +} diff --git a/app/Jobs/SendPasswordForgottenEmail.php b/app/Jobs/SendPasswordForgottenEmail.php new file mode 100644 index 000000000..edcb18680 --- /dev/null +++ b/app/Jobs/SendPasswordForgottenEmail.php @@ -0,0 +1,42 @@ +email = $email; + $this->resetLink = $resetLink; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + Mail::to($this->email)->send(new ForgottenPassword($this->resetLink)); + } +} diff --git a/app/Jobs/SendPasswordResetEmail.php b/app/Jobs/SendPasswordResetEmail.php new file mode 100644 index 000000000..d77dd7121 --- /dev/null +++ b/app/Jobs/SendPasswordResetEmail.php @@ -0,0 +1,46 @@ +email = $email; + $this->userId = $userId; + $this->newPass = $newPass; + } + + /** + * Execute the job. + * + * @return void + */ + public function handle() + { + Mail::to($this->email)->send(new PasswordReset($this->userId, $this->newPass)); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index e07717896..d0afda257 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,13 +2,12 @@ namespace App\Models; -use App\Mail\SendInvite; +use App\Jobs\SendAccountExpiredEmail; +use App\Jobs\SendInviteEmail; use Illuminate\Support\Str; -use App\Mail\AccountExpired; use Illuminate\Support\Facades\DB; use Spatie\Permission\Models\Role; use Illuminate\Support\Facades\Hash; -use Illuminate\Support\Facades\Mail; use Spatie\Permission\Traits\HasRoles; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Facades\Password; @@ -424,7 +423,7 @@ class User extends Authenticatable $user = self::find($u['id']); $user->update(['roles_id' => self::ROLE_USER, 'rolechangedate' => null]); $user->syncRoles('User'); - Mail::to($u['email'])->send(new AccountExpired($u['id'])); + SendAccountExpiredEmail::dispatch($u['email'], $u['id']); } return self::SUCCESS; @@ -941,9 +940,9 @@ class User extends Authenticatable $token = \Token::randomString(40); $url = $serverUrl.'register?invitecode='.$token; - Mail::to($emailTo)->send(new SendInvite($uid, $url)); - Invitation::addInvite($uid, $token); + Invitation::addInvite($uid, $token); + SendInviteEmail::dispatch($emailTo, $uid, $url); return $url; }