From aa206cb406b8d4f0062351d7ea8f3853b58fc0ba Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 2 Nov 2022 21:36:57 +1100 Subject: [PATCH] Fixes for verifyphone --- .github/workflows/phpunit.yml | 2 +- .../User/HasValidPhoneNumber.php | 2 +- app/Jobs/User/VerifyPhone.php | 22 ++++++++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index b4599c3da2..d662e4d2da 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: operating-system: ['ubuntu-20.04', 'ubuntu-22.04'] - php-versions: ['8.1.12'] + php-versions: ['8.1.11'] phpunit-versions: ['latest'] env: diff --git a/app/Http/ValidationRules/User/HasValidPhoneNumber.php b/app/Http/ValidationRules/User/HasValidPhoneNumber.php index 556bce5bf3..86e7b20a7a 100644 --- a/app/Http/ValidationRules/User/HasValidPhoneNumber.php +++ b/app/Http/ValidationRules/User/HasValidPhoneNumber.php @@ -38,7 +38,7 @@ class HasValidPhoneNumber implements Rule $token = config('ninja.twilio_auth_token'); if(!$sid) - return true; // no twilio api credentials provided, bail. + return true; $twilio = new Twilio\Rest\Client($sid, $token); diff --git a/app/Jobs/User/VerifyPhone.php b/app/Jobs/User/VerifyPhone.php index 6aa0823b0f..6bd17c7541 100644 --- a/app/Jobs/User/VerifyPhone.php +++ b/app/Jobs/User/VerifyPhone.php @@ -35,7 +35,7 @@ class VerifyPhone implements ShouldQueue * * @param User $user */ - public function __construct(public User $user){} + public function __construct(private User $user){} /** * Execute the job. @@ -45,7 +45,9 @@ class VerifyPhone implements ShouldQueue public function handle() : void { - MultiDB::checkUserEmailExists($user->email); + MultiDB::checkUserEmailExists($this->user->email); + + $this->user = User::find($this->user); $sid = config('ninja.twilio_account_sid'); $token = config('ninja.twilio_auth_token'); @@ -55,28 +57,28 @@ class VerifyPhone implements ShouldQueue $twilio = new Twilio\Rest\Client($sid, $token); - $country = $user->account?->companies()?->first()?->country(); + $country = $this->user->account?->companies()?->first()?->country(); - if(!$country || strlen($user->phone) < 2) + if(!$country || strlen($this->user->phone) < 2) return; $countryCode = $country->iso_3166_2; try{ - $phone_number = $twilio->lookups->v1->phoneNumbers($user->phone) + $phone_number = $twilio->lookups->v1->phoneNumbers($this->user->phone) ->fetch(["countryCode" => $countryCode]); } catch(\Exception $e) { - $user->verified_phone_number = false; - $user->save(); + $this->user->verified_phone_number = false; + $this->user->save(); } if($phone_number && strlen($phone_number->phoneNumber) > 1) { - $user->phone = $phone_number->phoneNumber; - $user->verified_phone_number = true; - $user->save(); + $this->user->phone = $phone_number->phoneNumber; + $this->user->verified_phone_number = true; + $this->user->save(); } }