-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75580c2
commit a468176
Showing
13 changed files
with
283 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\User; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\UserValidation; | ||
use App\User; | ||
use Illuminate\Http\Request; | ||
|
||
|
||
class EmailValidationController extends Controller | ||
{ | ||
|
||
public function validateEmail(Request $request, User $user) | ||
{ | ||
$token = $request->get('token'); | ||
|
||
/** @var UserValidation $validation */ | ||
$validation = UserValidation::where('user_id', $user->id) | ||
->where('token', $token) | ||
->first(); | ||
|
||
if ($validation->exists) { | ||
$validation->is_valid = true; | ||
$validation->saveQuietly(); | ||
} else { | ||
response()->redirectTo(route('settings.subscription'))->withError(__('emails/validation.error')); | ||
} | ||
|
||
return response()->redirectTo(route('settings.subscription'))->withSuccess(__('emails/validation.success')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace App\Jobs\Emails\Subscriptions; | ||
|
||
use App\Mail\Subscription\User\ValidationEmail; | ||
use App\Models\UserValidation; | ||
use App\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Facades\Mail; | ||
|
||
class EmailValidationJob implements ShouldQueue | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
/** @var int user id */ | ||
protected $user; | ||
protected $token; | ||
|
||
/** | ||
*/ | ||
public function __construct(User $user, string $token) | ||
{ | ||
$this->user = $user->id; | ||
$this->token = $token; | ||
} | ||
|
||
/** | ||
* @throws \Illuminate\Contracts\Container\BindingResolutionException | ||
*/ | ||
public function handle() | ||
{ | ||
// User deleted their account already? Sure thing | ||
/** @var User|null $user */ | ||
$user = User::find($this->user); | ||
if (empty($user)) { | ||
return; | ||
} | ||
|
||
// Send an email to the user | ||
Mail::to($user->email) | ||
->locale($user->locale) | ||
->send( | ||
new ValidationEmail($user, $this->token) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Mail\Subscription\User; | ||
|
||
use App\Models\UserValidation; | ||
use App\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class ValidationEmail extends Mailable | ||
{ | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
/** | ||
* @var User | ||
*/ | ||
public $user; | ||
public $token; | ||
|
||
|
||
public $date; | ||
|
||
/** | ||
* Create a new message instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(User $user, string $token) | ||
{ | ||
$this->user = $user; | ||
$this->token = $token; | ||
} | ||
|
||
/** | ||
* Build the message. | ||
* | ||
* @return $this | ||
*/ | ||
public function build() | ||
{ | ||
return $this | ||
->from(['address' => config('app.email'), 'name' => 'Kanka Team']) | ||
->subject(__('emails/subscriptions/validation.title')) | ||
->view('emails.subscriptions.validation.user-html') | ||
->tag('validation'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use App\User; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Prunable; | ||
|
||
/** | ||
* @property int $user_id | ||
* @property bool $is_valid | ||
*/ | ||
class UserValidation extends Model | ||
{ | ||
use Prunable; | ||
|
||
/** @var string[] */ | ||
protected $fillable = [ | ||
'is_valid', | ||
'token' | ||
]; | ||
|
||
public function user() | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
|
||
/** | ||
* Automatically prune old elements from the db | ||
* @return \Illuminate\Database\Eloquent\Builder | ||
*/ | ||
public function prunable() | ||
{ | ||
return static::where('is_valid', false)->where('created_at', '<=', now()->subDays(1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
database/migrations/2024_01_22_203110_create_user_validations_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('user_validations', function (Blueprint $table) { | ||
$table->id(); | ||
$table->uuid('token'); | ||
$table->unsignedInteger('user_id'); | ||
$table->boolean('is_valid'); | ||
$table->timestamps(); | ||
|
||
$table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete(); | ||
$table->index(['is_valid']); | ||
|
||
|
||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('user_validations'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
return [ | ||
'modal' => 'Email validation required for subscription, please check your inbox to continue the validation process.', | ||
'success' => 'Email succesfully validated.', | ||
'error' => 'Validation failed, please try again.', | ||
]; |
22 changes: 22 additions & 0 deletions
22
resources/views/emails/subscriptions/validation/user-html.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@extends('emails.base', [ | ||
'utmSource' => 'subscription', | ||
'utmCampaign' => 'failed-charge' | ||
]) | ||
|
||
@section('content') | ||
<p> | ||
<strong>Email Validation</strong> | ||
</p> | ||
<p> | ||
{{ __('emails/subscriptions/upcoming.dear', ['name' => $user->name]) }}, | ||
</p> | ||
|
||
<p>This is an automatic notification.</p> | ||
<p>To validate the email for your Kanka account click <a href="{{ 'https://app.kanka.io/users/' . $user->id . '/validation?token=' . $token }}">here</a>. This link will expire in 24 hours.</p> | ||
<p>If the above link doesnt work, open the following URL in your web browser {{ 'https://app.kanka.io/users/' . $user->id . '/validation?token=' . $token }}</p> | ||
<p> | ||
{{ __('emails/subscriptions/upcoming.closing') }}<br /> | ||
The Kanka Team | ||
</p> | ||
|
||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters