Browse Source

Remove notifications for email change requests

master
Immanuel Onyeka 3 years ago
parent
commit
b5d7780e2c
5 changed files with 74 additions and 79 deletions
  1. +6
    -5
      app/Http/Controllers/UserController.php
  2. +40
    -0
      app/Mail/ChangeEmail.php
  3. +0
    -66
      app/Notifications/ChangeEmail.php
  4. +26
    -0
      resources/views/change-email.blade.php
  5. +2
    -8
      routes/web.php

+ 6
- 5
app/Http/Controllers/UserController.php View File

@@ -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));


}


+ 40
- 0
app/Mail/ChangeEmail.php View File

@@ -0,0 +1,40 @@
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class ChangeEmail extends Mailable
{
use Queueable, SerializesModels;

/**
* Create a new message instance.
*
* @return void
*/
public $current_email;
public $link;

public function __construct($current_email, $link)
{
$this->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;
}
}

+ 0
- 66
app/Notifications/ChangeEmail.php View File

@@ -1,66 +0,0 @@
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class ChangeEmail extends Notification
{
use Queueable;

private $link;
private $email;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($link, $email)
{
$this->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 [
//
];
}

}

+ 26
- 0
resources/views/change-email.blade.php View File

@@ -0,0 +1,26 @@
@extends('master')

@section('title', 'Change Email')

@section('head-metas')
@parent
<link rel="stylesheet" href="/css/app.css">
<link rel="stylesheet" href="/css/panel.css">
@endsection

@section('content')
@parent

<main id="ticket-email">
<h3>An email change has been requested from {{$current_email}}</h3>

<a href="{{$link}}"><button>Confirm</button></a>

<small>If you do not recognize this activity, please disregard this
message.</small>
</main>

@endsection

@section('footer')
@endsection

+ 2
- 8
routes/web.php View File

@@ -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) {


Loading…
Cancel
Save