diff --git a/app/Console/Commands/TestEmail.php b/app/Console/Commands/EmailTest.php similarity index 52% rename from app/Console/Commands/TestEmail.php rename to app/Console/Commands/EmailTest.php index 3a5726c..c228808 100644 --- a/app/Console/Commands/TestEmail.php +++ b/app/Console/Commands/EmailTest.php @@ -6,17 +6,20 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Mail; -use App\Mail\TestEmail as MailTest; +use App\Mail\Test; use App\Models\{Site,User}; -class TestEmail extends Command +class EmailTest extends Command { /** * The name and signature of the console command. * * @var string */ - protected $signature = 'test:email {site : Site ID} {id : User ID} {email? : Alternative Email}'; + protected $signature = 'test-email' + .' {--s|site : Site ID}' + .' {id : User ID}' + .' {email? : Alternative Email}'; /** * The console command description. @@ -25,16 +28,6 @@ class TestEmail extends Command */ protected $description = 'Send a test email'; - /** - * Create a new command instance. - * - * @return void - */ - public function __construct() - { - parent::__construct(); - } - /** * Execute the console command. * @@ -42,11 +35,20 @@ class TestEmail extends Command */ public function handle() { - Config::set('site',Site::findOrFail($this->argument('site'))); + Config::set( + 'site', + $this->option('site') + ? Site::findOrFail($this->option('site')) + : Site::where('url',config('app.url'))->sole() + ); $uo = User::find($this->argument('id')); - Mail::to($this->argument('email') ?? $uo->email) - ->send(new MailTest($uo)); + $result = Mail::to($this->argument('email') ?? $uo->email) + ->send(new Test($uo)); + + $this->info($result->getMessageId()); + + return self::SUCCESS; } } \ No newline at end of file diff --git a/app/Http/Controllers/Auth/SocialLoginController.php b/app/Http/Controllers/Auth/SocialLoginController.php index dd5f830..ce36112 100644 --- a/app/Http/Controllers/Auth/SocialLoginController.php +++ b/app/Http/Controllers/Auth/SocialLoginController.php @@ -3,14 +3,10 @@ namespace App\Http\Controllers\Auth; use Carbon\Carbon; -use Illuminate\Http\Request; -use Illuminate\Support\Arr; use Illuminate\Support\Facades\Auth; -use Illuminate\Support\Facades\Mail; use Laravel\Socialite\Facades\Socialite; use App\Http\Controllers\Controller; -use App\Mail\SocialLink; use App\Models\{ProviderOauth,ProviderToken,User,UserOauth}; class SocialLoginController extends Controller @@ -105,46 +101,4 @@ class SocialLoginController extends Controller ->intended('/home') ->with('success','Token refreshed.'); } - - /** - * We have identified the user and oauth, just need them to confirm the link - * - * @param $provider - * @param UserOauth $ao - * @param User $uo - * @return \Illuminate\View\View - */ - public function link($provider,UserOauth $ao,User $uo): \Illuminate\View\View - { - // @note If this is sent now (send()), it results in the caller to be executed a second time (handleProviderCallback()). - Mail::to($uo->email)->queue(new SocialLink($ao)); - - return view('auth.social_link') - ->with('oauthid',$ao->id) - ->with('provider',$provider); - } - - public function linkcomplete(Request $request,$provider) - { - // Load our oauth id - $aoo = UserOauth::findOrFail($request->post('oauthid')); - - // Check our email matches - if (Arr::get($aoo->oauth_data,'email','invalid') !== $request->post('email')) - return redirect('/login')->with('error','Account details didnt match to make link.'); - - // Check our token matches - if ($aoo->link_token !== $request->post('token')) - return redirect('/login')->with('error','Token details didnt match to make link.'); - - // Load our email. - $uo = User::where('email',$request->post('email'))->firstOrFail(); - - $aoo->user_id = $uo->id; - $aoo->save(); - Auth::login($uo); - - return redirect() - ->intended('/home'); - } } \ No newline at end of file diff --git a/app/Mail/SocialLink.php b/app/Mail/SocialLink.php deleted file mode 100644 index 8149a32..0000000 --- a/app/Mail/SocialLink.php +++ /dev/null @@ -1,48 +0,0 @@ -site = $o->site; - $this->token = $o->link_token; - $this->user = $o->user; - } - - /** - * Build the message. - * - * @return $this - */ - public function build() - { - Config::set('site',$this->site); - - return $this - ->markdown('mail.system.social_link') - ->subject('Link your Account') - ->with([ - 'site'=>$this->site, - ]); - } -} \ No newline at end of file diff --git a/app/Mail/TestEmail.php b/app/Mail/Test.php similarity index 73% rename from app/Mail/TestEmail.php rename to app/Mail/Test.php index a8795ee..549df5f 100644 --- a/app/Mail/TestEmail.php +++ b/app/Mail/Test.php @@ -3,14 +3,12 @@ namespace App\Mail; use Illuminate\Bus\Queueable; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Facades\Config; use App\Models\User; -class TestEmail extends Mailable +class Test extends Mailable { use Queueable, SerializesModels; @@ -33,10 +31,8 @@ class TestEmail extends Mailable */ public function build() { - Config::set('site',$this->user->site); - return $this - ->markdown('mail.system.test_email') + ->markdown('mail.test') ->subject('Just a test...') ->with([ 'site'=>$this->user->site, diff --git a/resources/views/mail/system/social_link.blade.php b/resources/views/mail/system/social_link.blade.php deleted file mode 100644 index 221e15d..0000000 --- a/resources/views/mail/system/social_link.blade.php +++ /dev/null @@ -1,21 +0,0 @@ -@component('mail::message',['site'=>$site,'heading'=>'Link Your Account']) -Hi {{ isset($user) ? $user->name_full.',' : '' }} - -A request was made to link your account to a social login. -If you didnt make this request, you can ignore this, and the request will be ignored. -If you did make the request, then please enter the code displayed below. - -@component('mail::button') -{{ $token }} -@endcomponent - -Once you've keyed in this code, you'll be able to login to your account using your social login instead of a username and a password. - -Thanks, - -{{ config('mail.from.name') }} - -@component('mail::subcontent') -If you didnt make this request, you can safely ignore this email - no change was made to your account, nor was it accessed by an unauthorised person. -@endcomponent -@endcomponent \ No newline at end of file diff --git a/resources/views/mail/system/test_email.blade.php b/resources/views/mail/test.blade.php similarity index 100% rename from resources/views/mail/system/test_email.blade.php rename to resources/views/mail/test.blade.php diff --git a/resources/views/theme/backend/adminlte/auth/social_link.blade.php b/resources/views/theme/backend/adminlte/auth/social_link.blade.php deleted file mode 100644 index 61f48ed..0000000 --- a/resources/views/theme/backend/adminlte/auth/social_link.blade.php +++ /dev/null @@ -1,80 +0,0 @@ -@extends('adminlte::layouts.auth') - -@section('htmlheader_title') - Link Account -@endsection - -@section('content') -
- - -
- NOTE: Link your account.

- -
- - @if (count($errors) > 0) -
- Whoops! {{ trans('adminlte_lang::message.someproblems') }}

- -
- @endif - - -
- - -
-
- -@endsection \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 9bf99be..85535f1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -61,8 +61,6 @@ Route::get('pay/paypal/capture',[PaypalController::class,'capture']); Route::get('auth/{socialProvider}',[SocialLoginController::class,'redirectToProvider']); Route::get('auth/{socialProvider}/callback',[SocialLoginController::class,'handleProviderCallback']); Route::get('auth/{socialProvider}/token',[SocialLoginController::class,'handleBearerTokenCallback']); -Route::get('auth/{socialProvider}/link',[SocialLoginController::class,'link']); -Route::post('auth/{socialProvider}/linkcomplete',[SocialLoginController::class,'linkcomplete']); // Return from user switch Route::get('admin/switch/stop',[SwitchUserController::class,'switch_stop'])