Skip to content

Commit

Permalink
Profile: add phone number verification
Browse files Browse the repository at this point in the history
This forces us to take GB numbers and then we store them in e164 ready for nexmo

fix #210
  • Loading branch information
dpslwk committed May 26, 2019
1 parent 41cdfb3 commit c4e8fd3
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 6 deletions.
8 changes: 6 additions & 2 deletions app/HMS/User/ProfileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
use HMS\Entities\User;
use HMS\Entities\Profile;
use Illuminate\Http\Request;
use libphonenumber\RegionCode;
use HMS\Repositories\MetaRepository;
use HMS\Repositories\UserRepository;
use HMS\Repositories\ProfileRepository;
use Propaganistas\LaravelPhone\PhoneNumber;

class ProfileManager
{
Expand Down Expand Up @@ -85,7 +87,8 @@ public function create(
$profile->setAddressCity($addressCity);
$profile->setAddressCounty($addressCounty);
$profile->setAddressPostcode($addressPostcode);
$profile->setContactNumber($contactNumber);
$e164 = PhoneNumber::make($contactNumber, RegionCode::GB)->formatE164();
$profile->setContactNumber($e164);

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

if ($request['contactNumber']) {
$profile->setContactNumber($request['contactNumber']);
$e164 = PhoneNumber::make($request['contactNumber'], RegionCode::GB)->formatE164();
$profile->setContactNumber($e164);
}

// Nullable field
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function validator(array $data)
'addressCity' => 'required|max:100',
'addressCounty' => 'required|max:100',
'addressPostcode' => 'required|max:10',
'contactNumber' => 'required|max:50',
'contactNumber' => 'required|max:50|phone:GB',
'dateOfBirth' => 'nullable|date_format:Y-m-d',
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/MembershipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function updateDetails(User $user, Request $request)
'addressCity' => 'required|max:100',
'addressCounty' => 'required|max:100',
'addressPostcode' => 'required|max:10',
'contactNumber' => 'required|max:50',
'contactNumber' => 'required|max:50|phone:GB',
'dateOfBirth' => 'nullable|date_format:Y-m-d',
]);

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function update(Request $request, User $user)
'addressCity' => 'sometimes|required|max:100',
'addressCounty' => 'sometimes|required|max:100',
'addressPostcode' => 'sometimes|required|max:10',
'contactNumber' => 'sometimes|required|max:50',
'contactNumber' => 'sometimes|required|max:50|phone:GB',
'dateOfBirth' => 'sometimes|nullable|date_format:Y-m-d',
'unlockText' => 'sometimes|nullable|max:95',
]);
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"pragmarx/google2fa-laravel": "^1.0",
"pragmarx/recovery": "^0.1.0",
"predis/predis": "^1.1",
"propaganistas/laravel-phone": "^4.2",
"spatie/laravel-cookie-consent": "^2.0",
"tremby/laravel-git-version": "^1.1"
},
Expand Down
237 changes: 236 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions resources/lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
'not_in' => 'The selected :attribute is invalid.',
'not_regex' => 'The :attribute format is invalid.',
'numeric' => 'The :attribute must be a number.',
'phone' => 'The :attribute field contains an invalid number.',
'present' => 'The :attribute field must be present.',
'regex' => 'The :attribute format is invalid.',
'required' => 'The :attribute field is required.',
Expand Down

0 comments on commit c4e8fd3

Please sign in to comment.