-
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
018bc97
commit 14ef876
Showing
10 changed files
with
77 additions
and
51 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
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
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 |
---|---|---|
@@ -1,11 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Models\Scopes; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
/** | ||
* Trait UserScope | ||
* @package App\Models\Scopes | ||
*/ | ||
trait UserScope | ||
{ | ||
/** | ||
*/ | ||
public function scopeValid(Builder $query, bool $valid = true): Builder | ||
{ | ||
return $query->where(['is_valid' => $valid]); | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
namespace App\Services\Users; | ||
|
||
use App\Traits\UserAware; | ||
use App\Models\UserFlag; | ||
use App\Models\UserValidation; | ||
use App\Jobs\Emails\Subscriptions\EmailValidationJob; | ||
use Illuminate\Support\Str; | ||
|
||
class EmailValidationService | ||
{ | ||
use UserAware; | ||
|
||
public function requiresEmail(): void | ||
{ | ||
$token = UserValidation::where('user_id', $this->user->id)->first(); | ||
if ($token && $token->is_valid) { | ||
return; | ||
} | ||
//Check for existing token | ||
$flag = UserFlag::where('user_id', $this->user->id)->where('flag', UserFlag::FLAG_EMAIL)->first(); | ||
|
||
if (!$flag) { | ||
$flag = new UserFlag(); | ||
$flag->user_id = $this->user->id; | ||
$flag->flag = UserFlag::FLAG_EMAIL; | ||
$flag->save(); | ||
} | ||
|
||
if (!$token) { | ||
$token = new UserValidation(); | ||
$token->token = Str::uuid(); | ||
$token->user_id = $this->user->id; | ||
$token->is_valid = false; | ||
$token->save(); | ||
} | ||
|
||
EmailValidationJob::dispatch($this->user, $token->token); | ||
|
||
return; | ||
} | ||
} |
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
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