Skip to content

Commit c4e8fd3

Browse files
committed
Profile: add phone number verification
This forces us to take GB numbers and then we store them in e164 ready for nexmo fix #210
1 parent 41cdfb3 commit c4e8fd3

File tree

7 files changed

+247
-6
lines changed

7 files changed

+247
-6
lines changed

app/HMS/User/ProfileManager.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
use HMS\Entities\User;
77
use HMS\Entities\Profile;
88
use Illuminate\Http\Request;
9+
use libphonenumber\RegionCode;
910
use HMS\Repositories\MetaRepository;
1011
use HMS\Repositories\UserRepository;
1112
use HMS\Repositories\ProfileRepository;
13+
use Propaganistas\LaravelPhone\PhoneNumber;
1214

1315
class ProfileManager
1416
{
@@ -85,7 +87,8 @@ public function create(
8587
$profile->setAddressCity($addressCity);
8688
$profile->setAddressCounty($addressCounty);
8789
$profile->setAddressPostcode($addressPostcode);
88-
$profile->setContactNumber($contactNumber);
90+
$e164 = PhoneNumber::make($contactNumber, RegionCode::GB)->formatE164();
91+
$profile->setContactNumber($e164);
8992

9093
if (! empty($dateOfBirth)) {
9194
$profile->setDateOfBirth(new Carbon($dateOfBirth));
@@ -142,7 +145,8 @@ public function updateUserProfileFromRequest(User $user, Request $request)
142145
}
143146

144147
if ($request['contactNumber']) {
145-
$profile->setContactNumber($request['contactNumber']);
148+
$e164 = PhoneNumber::make($request['contactNumber'], RegionCode::GB)->formatE164();
149+
$profile->setContactNumber($e164);
146150
}
147151

148152
// Nullable field

app/Http/Controllers/Auth/RegisterController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function validator(array $data)
8686
'addressCity' => 'required|max:100',
8787
'addressCounty' => 'required|max:100',
8888
'addressPostcode' => 'required|max:10',
89-
'contactNumber' => 'required|max:50',
89+
'contactNumber' => 'required|max:50|phone:GB',
9090
'dateOfBirth' => 'nullable|date_format:Y-m-d',
9191
]);
9292
}

app/Http/Controllers/MembershipController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public function updateDetails(User $user, Request $request)
237237
'addressCity' => 'required|max:100',
238238
'addressCounty' => 'required|max:100',
239239
'addressPostcode' => 'required|max:10',
240-
'contactNumber' => 'required|max:50',
240+
'contactNumber' => 'required|max:50|phone:GB',
241241
'dateOfBirth' => 'nullable|date_format:Y-m-d',
242242
]);
243243

app/Http/Controllers/UserController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function update(Request $request, User $user)
119119
'addressCity' => 'sometimes|required|max:100',
120120
'addressCounty' => 'sometimes|required|max:100',
121121
'addressPostcode' => 'sometimes|required|max:10',
122-
'contactNumber' => 'sometimes|required|max:50',
122+
'contactNumber' => 'sometimes|required|max:50|phone:GB',
123123
'dateOfBirth' => 'sometimes|nullable|date_format:Y-m-d',
124124
'unlockText' => 'sometimes|nullable|max:95',
125125
]);

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"pragmarx/google2fa-laravel": "^1.0",
3232
"pragmarx/recovery": "^0.1.0",
3333
"predis/predis": "^1.1",
34+
"propaganistas/laravel-phone": "^4.2",
3435
"spatie/laravel-cookie-consent": "^2.0",
3536
"tremby/laravel-git-version": "^1.1"
3637
},

composer.lock

Lines changed: 236 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/lang/en/validation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
'not_in' => 'The selected :attribute is invalid.',
9494
'not_regex' => 'The :attribute format is invalid.',
9595
'numeric' => 'The :attribute must be a number.',
96+
'phone' => 'The :attribute field contains an invalid number.',
9697
'present' => 'The :attribute field must be present.',
9798
'regex' => 'The :attribute format is invalid.',
9899
'required' => 'The :attribute field is required.',

0 commit comments

Comments
 (0)