diff --git a/app/HMS/User/ProfileManager.php b/app/HMS/User/ProfileManager.php index 84e229816..a3a7b09b0 100644 --- a/app/HMS/User/ProfileManager.php +++ b/app/HMS/User/ProfileManager.php @@ -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 { @@ -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)); @@ -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 diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 3531b52ee..a9d7a3ed4 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -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', ]); } diff --git a/app/Http/Controllers/MembershipController.php b/app/Http/Controllers/MembershipController.php index 73eb6f6fd..7744ad5ee 100644 --- a/app/Http/Controllers/MembershipController.php +++ b/app/Http/Controllers/MembershipController.php @@ -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', ]); diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 94758e297..c7cd72bea 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -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', ]); diff --git a/composer.json b/composer.json index 696c4c2c3..04863cdda 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/composer.lock b/composer.lock index fcf5135d3..d9caf33f9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d7ecc5f76279fbb6b6a72253c13faf66", + "content-hash": "21dbaeeced53691a11b7628534515d59", "packages": [ { "name": "bacon/bacon-qr-code", @@ -1656,6 +1656,123 @@ ], "time": "2019-03-17T18:16:12+00:00" }, + { + "name": "giggsey/libphonenumber-for-php", + "version": "8.10.12", + "source": { + "type": "git", + "url": "https://github.com/giggsey/libphonenumber-for-php.git", + "reference": "6187402b4949ca7edc439ed4a0396922eeb13dfa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/giggsey/libphonenumber-for-php/zipball/6187402b4949ca7edc439ed4a0396922eeb13dfa", + "reference": "6187402b4949ca7edc439ed4a0396922eeb13dfa", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "giggsey/locale": "^1.7", + "php": ">=5.3.2" + }, + "require-dev": { + "pear/pear-core-minimal": "^1.9", + "pear/pear_exception": "^1.0", + "pear/versioncontrol_git": "^0.5", + "phing/phing": "^2.7", + "php-coveralls/php-coveralls": "^1.0|^2.0", + "phpunit/phpunit": "^4.8.36|^5.0", + "symfony/console": "^2.8|^3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + } + }, + "autoload": { + "psr-4": { + "libphonenumber\\": "src/" + }, + "exclude-from-classmap": [ + "/src/data/", + "/src/carrier/data/", + "/src/geocoding/data/", + "/src/timezone/data/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Joshua Gigg", + "email": "giggsey@gmail.com", + "homepage": "https://giggsey.com/" + } + ], + "description": "PHP Port of Google's libphonenumber", + "homepage": "https://github.com/giggsey/libphonenumber-for-php", + "keywords": [ + "geocoding", + "geolocation", + "libphonenumber", + "mobile", + "phonenumber", + "validation" + ], + "time": "2019-05-14T11:30:38+00:00" + }, + { + "name": "giggsey/locale", + "version": "1.7.1", + "source": { + "type": "git", + "url": "https://github.com/giggsey/Locale.git", + "reference": "b8030fc8df13cdfbecba318588de2d52b49c9b50" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/giggsey/Locale/zipball/b8030fc8df13cdfbecba318588de2d52b49c9b50", + "reference": "b8030fc8df13cdfbecba318588de2d52b49c9b50", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "pear/pear-core-minimal": "^1.9", + "pear/pear_exception": "^1.0", + "pear/versioncontrol_git": "^0.5", + "phing/phing": "~2.7", + "phpunit/phpunit": "^4.8|^5.0", + "satooshi/php-coveralls": "^1.0", + "symfony/console": "^2.8|^3.0|^4.0", + "symfony/filesystem": "^2.8|^3.0|^4.0", + "symfony/finder": "^2.8|^3.0|^4.0", + "symfony/process": "^2.8|^3.0|^4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Giggsey\\Locale\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Joshua Gigg", + "email": "giggsey@gmail.com", + "homepage": "http://giggsey.com/" + } + ], + "description": "Locale functions required by libphonenumber-for-php", + "time": "2019-04-26T07:28:50+00:00" + }, { "name": "guzzlehttp/guzzle", "version": "6.3.3", @@ -2942,6 +3059,60 @@ ], "time": "2019-05-20T20:21:14+00:00" }, + { + "name": "league/iso3166", + "version": "2.1.2", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/iso3166.git", + "reference": "5e8f504eea3f13e45fa397da86313371b3eb20d5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/iso3166/zipball/5e8f504eea3f13e45fa397da86313371b3eb20d5", + "reference": "5e8f504eea3f13e45fa397da86313371b3eb20d5", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.12", + "phpunit/phpunit": "^5.7.11 || ^6.0 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\ISO3166\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com" + } + ], + "description": "ISO 3166-1 PHP Library", + "homepage": "https://github.com/thephpleague/iso3166", + "keywords": [ + "3166", + "3166-1", + "ISO 3166", + "countries", + "iso", + "library" + ], + "time": "2019-03-14T08:34:44+00:00" + }, { "name": "league/oauth2-server", "version": "7.4.0", @@ -4405,6 +4576,70 @@ ], "time": "2016-06-16T16:22:20+00:00" }, + { + "name": "propaganistas/laravel-phone", + "version": "4.2.1", + "source": { + "type": "git", + "url": "https://github.com/Propaganistas/Laravel-Phone.git", + "reference": "2f14f65aee9c200f1d50c58474ac6dfb8281b646" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Propaganistas/Laravel-Phone/zipball/2f14f65aee9c200f1d50c58474ac6dfb8281b646", + "reference": "2f14f65aee9c200f1d50c58474ac6dfb8281b646", + "shasum": "" + }, + "require": { + "giggsey/libphonenumber-for-php": "^7.0|^8.0", + "illuminate/support": ">=5.0,<5.9", + "illuminate/validation": ">=5.0,<5.9", + "league/iso3166": "^2.0", + "php": ">=7.1" + }, + "require-dev": { + "orchestra/testbench": "*", + "phpunit/phpunit": "*" + }, + "suggest": { + "propaganistas/laravel-intl": "Adds internationalization functions, including a compatible and fully translated country list API." + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Propaganistas\\LaravelPhone\\PhoneServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Propaganistas\\LaravelPhone\\": "src/" + }, + "files": [ + "src/helpers.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Propaganistas", + "email": "Propaganistas@users.noreply.github.com" + } + ], + "description": "Adds phone number functionality to Laravel and Lumen based on Google's libphonenumber API.", + "keywords": [ + "laravel", + "libphonenumber", + "lumen", + "phone", + "validation" + ], + "time": "2019-05-17T10:11:37+00:00" + }, { "name": "psr/container", "version": "1.0.0", diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index e1d879f33..7b9682ca6 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -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.',