Skip to content

Commit

Permalink
feat: add an option to disable mail verification (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin committed Oct 29, 2020
1 parent fefc342 commit 7c504dd
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function store(Request $request): RedirectResponse
'password',
]));

if (User::count() == 1) {
if (! config('mail.verify') || User::count() == 1) {
// if it's the first user, we can skip the email verification
$user->markEmailAsVerified();
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Kernel extends HttpKernel
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'verified' => \App\Http\Middleware\EnsureEmailIsVerified::class,
'company' => \App\Http\Middleware\CheckCompany::class,
'administrator' => \App\Http\Middleware\CheckAdministratorRole::class,
'hr' => \App\Http\Middleware\CheckHRRole::class,
Expand Down
26 changes: 26 additions & 0 deletions app/Http/Middleware/EnsureEmailIsVerified.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Auth\Middleware\EnsureEmailIsVerified as Middleware;

class EnsureEmailIsVerified extends Middleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param mixed|null $redirectToRoute
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
*/
public function handle($request, Closure $next, $redirectToRoute = null)
{
if (config('mail.verify')) {
return parent::handle($request, $next, $redirectToRoute);
}

return $next($request);
}
}
2 changes: 1 addition & 1 deletion app/Models/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function getLatestNotifications(Company $company, int $numberOfNotificati
*/
public function sendEmailVerificationNotification(): void
{
if (User::count() > 1) {
if (config('mail.verify') && User::count() > 1) {
SendVerifyEmail::dispatch($this);
}
}
Expand Down
11 changes: 11 additions & 0 deletions config/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,15 @@
],
],

/*
|--------------------------------------------------------------------------
| Verify Email
|--------------------------------------------------------------------------
|
| Verifies the user's email by sending a verification mail.
|
*/

'verify' => (bool) env('MAIL_VERIFY', true),

];

0 comments on commit 7c504dd

Please sign in to comment.