diff --git a/app/Events/MobileVerificationCodeGenerated.php b/app/Events/MobileVerificationCodeGenerated.php new file mode 100644 index 0000000..aa433f9 --- /dev/null +++ b/app/Events/MobileVerificationCodeGenerated.php @@ -0,0 +1,28 @@ +user = $user; + $this->generationTime = $generationTime; + } + +} diff --git a/app/Events/MobileVerified.php b/app/Events/MobileVerified.php index 64f7b93..fcc4c46 100644 --- a/app/Events/MobileVerified.php +++ b/app/Events/MobileVerified.php @@ -3,11 +3,12 @@ namespace App\Events; use App\Classes\Verification\MustVerifyMobileNumber; +use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; class MobileVerified { - use SerializesModels; + use Dispatchable, SerializesModels; /** * The verified user. diff --git a/app/Listeners/MobileVerificationCodeGeneratedListener.php b/app/Listeners/MobileVerificationCodeGeneratedListener.php new file mode 100644 index 0000000..38031d1 --- /dev/null +++ b/app/Listeners/MobileVerificationCodeGeneratedListener.php @@ -0,0 +1,26 @@ +generationTime; + $user = $event->user; +// Carbon::createFromTimestamp($timeStamp); + Log::info('MobileVerificationCodeGeneratedListener : '.$user->id.' - '.$timeStamp); + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 0f0259c..4cc9028 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -3,8 +3,10 @@ namespace App\Providers; use App\Events\CountOption; +use App\Events\MobileVerificationCodeGenerated; use App\Events\MobileVerified; use App\Listeners\CountOptionListener; +use App\Listeners\MobileVerificationCodeGeneratedListener; use App\Listeners\MobileVerifiedListener; use App\Listeners\SendMobileVerificationNotification; use Illuminate\Auth\Events\Registered; @@ -28,8 +30,10 @@ class EventServiceProvider extends ServiceProvider ], CountOption::class => [ CountOptionListener::class + ], + MobileVerificationCodeGenerated::class => [ + MobileVerificationCodeGeneratedListener::class ] - ]; /** diff --git a/app/Traits/MustVerifyMobileNumberTrait.php b/app/Traits/MustVerifyMobileNumberTrait.php index 52f40cf..10714e2 100644 --- a/app/Traits/MustVerifyMobileNumberTrait.php +++ b/app/Traits/MustVerifyMobileNumberTrait.php @@ -8,9 +8,11 @@ namespace App\Traits; +use App\Events\MobileVerificationCodeGenerated; use App\Notifications\MobileVerified; use App\Notifications\VerifyMobile; -use Illuminate\Support\Facades\Cache; +use Carbon\Carbon; +use Illuminate\Support\Facades\Log; trait MustVerifyMobileNumberTrait { @@ -21,7 +23,7 @@ trait MustVerifyMobileNumberTrait */ public function hasVerifiedMobile() { - return $this->mobile_verified_at !== null; + return ! is_null($this->mobile_verified_at); } /** @@ -44,10 +46,10 @@ public function markMobileAsVerified() public function sendMobileVerificationNotification() { if ($this->setMobileVerificationCode()) { - $this->notify(new VerifyMobile()); +// $this->notify(new VerifyMobile()); } } - + /** * generate a verification code for given user * @@ -56,11 +58,28 @@ public function sendMobileVerificationNotification() */ public function setMobileVerificationCode(): bool { - $verificationCode = random_int(10000, 99999); + Log::info('before event'); + event(new MobileVerificationCodeGenerated($this , Carbon::now('Asia/Tehran'))); + return true; - return $this->forceFill([ + + $verificationCode = $this->getMobileVerificationCode(); + if(isset($verificationCode)) { + return true; + } + + + $verificationCode = random_int(10000, 99999); + $result = $this->forceFill([ 'mobile_verified_code' => $verificationCode, ])->save(); + + if($result){ + event(new MobileVerificationCodeGenerated($this , Carbon::now('Asia/Tehran'))); + + return true; + } + return false; } /**