diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 9e78361..682026c 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -6,7 +6,7 @@ use Illuminate\Http\Request; use App\Models\User; use App\Models\Order; use App\Models\Service; -use App\Notifications\ChangeEmail; +use App\Mail\ChangeEmail; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Hash; @@ -14,6 +14,8 @@ use Illuminate\Support\Facades\URL; use Illuminate\Auth\Events\Registered; use Illuminate\Support\Facades\Password; use Illuminate\Support\Facades\Auth; +use Illuminate\Notifications\Messages\MailMessage; +use Mail; use Stripe\Stripe; use Stripe\Customer; @@ -36,6 +38,7 @@ class UserController extends Controller $user->password = Hash::make($request->password); $user->save(); + Auth::login($user); event(new Registered($user)); } @@ -99,10 +102,8 @@ class UserController extends Controller $validated = $request->validate([ 'name' => 'required|max:30' ]); - Stripe::setApiKey(config('services.stripe.secret')); $user = Auth::user(); $user->name = $request->name; - Customer::update($user->customer_id, ['name' => $request->name]); $user->save(); return $user; } @@ -115,8 +116,8 @@ class UserController extends Controller $link = URL::temporarySignedRoute('reset-email', now()->addDays(30), ['user' => Auth::user()->id, 'email' => $request->email]); - Auth::user()->notify(new ChangeEmail($link, - $request->email)); + Mail::to($request->email)->send(new ChangeEmail(Auth::user()->email, + $link)); } diff --git a/app/Mail/ChangeEmail.php b/app/Mail/ChangeEmail.php new file mode 100644 index 0000000..d190a4d --- /dev/null +++ b/app/Mail/ChangeEmail.php @@ -0,0 +1,40 @@ +current_email = $current_email; + $this->link = $link; + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + $this->view('change-email'); + $this->from('donotreply@trendplays.com'); + $this->subject('Email change requested'); + return $this; + } +} diff --git a/app/Notifications/ChangeEmail.php b/app/Notifications/ChangeEmail.php deleted file mode 100644 index 13146de..0000000 --- a/app/Notifications/ChangeEmail.php +++ /dev/null @@ -1,66 +0,0 @@ -link = $link; - $this->email = $email; - } - - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail']; - } - - /** - * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage - */ - public function toMail($notifiable) - { - return (new MailMessage) - ->line('An email change has been requested. Please confirm your new address by clicking the link below.') - ->action('Confirm', $this->link) - ->to($this->email) - ->line('If you do not recognize this activity, please disregard this email.'); - } - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) - { - return [ - // - ]; - } - -} diff --git a/resources/views/change-email.blade.php b/resources/views/change-email.blade.php new file mode 100644 index 0000000..cd8f173 --- /dev/null +++ b/resources/views/change-email.blade.php @@ -0,0 +1,26 @@ +@extends('master') + +@section('title', 'Change Email') + +@section('head-metas') + @parent + + +@endsection + +@section('content') +@parent + +
+

An email change has been requested from {{$current_email}}

+ + + + If you do not recognize this activity, please disregard this + message. +
+ +@endsection + +@section('footer') +@endsection diff --git a/routes/web.php b/routes/web.php index b41ba31..e81d8c1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -10,7 +10,6 @@ use App\Http\Controllers\Ticket; use Illuminate\Foundation\Auth\EmailVerificationRequest; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; -use App\Notifications\ChangeEmail; /* |-------------------------------------------------------------------------- @@ -43,16 +42,11 @@ Route::get('/verify-email', function() { } })->middleware('auth')->name('verification.notice'); -Route::get('/verify/{id}/{hash}', function (EmailVerificationRequest $request, $id) { - if (Auth::user()->email_verified_at) { - abort(404); - } - - Auth::loginUsingId($id); +Route::get('/verify/{id}/{hash}', function (EmailVerificationRequest $request) { $request->fulfill(); return redirect('/panel'); -})->middleware(['signed'])->name('verification.verify'); +})->middleware(['auth', 'signed'])->name('verification.verify'); Route::post('/resend-verification', function (Request $request) { if (Auth::user()->email_verified_at) {