在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):mohammad-fouladgar/laravel-mobile-verification开源软件地址(OpenSource Url):https://github.com/mohammad-fouladgar/laravel-mobile-verification开源编程语言(OpenSource Language):PHP 96.7%开源软件介绍(OpenSource Introduction):Laravel Mobile VerificationIntroductionMany web applications require users to verify their mobile phone numbers before using the application. Rather than forcing you to re-implement this on each application, this package provides convenient methods for sending and verifying mobile phone verification requests. Version Compatibility
InstallationYou can install the package via composer: composer require fouladgar/laravel-mobile-verification ConfigurationTo get started, you should publish the
Token StorageAfter generating a token, we need to store it in a storage. This package supports two drivers: // config/mobile_verifier.php
<?php
return [
/**
|Supported drivers: "cache", "database"
*/
'token_storage' => 'cache',
]; DatabaseIt means after migrating, a table will be created which your application needs to store verification tokens.
// config/mobile_verifier.php
<?php
return [
'user_table' => 'users',
'mobile_column' => 'mobile',
'token_table' => 'mobile_verification_tokens',
//...
]; CacheWhen using the All right! Now you should migrate the database:
Depending on the Model PreparationIn the following, make sure your <?php
namespace App;
use Fouladgar\MobileVerification\Contracts\MustVerifyMobile as IMustVerifyMobile;
use Fouladgar\MobileVerification\Concerns\MustVerifyMobile;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable implements IMustVerifyMobile
{
use Notifiable, MustVerifyMobile;
// ...
} SMS ClientYou can use any SMS service for sending verification messages(it depends on your choice). For sending notifications via this package, first you need to implement the This method will return your SMS service API results via a <?php
namespace App;
use Fouladgar\MobileVerification\Contracts\SMSClient;
use Fouladgar\MobileVerification\Notifications\Messages\Payload;
class SampleSMSClient implements SMSClient
{
protected $SMSService;
/**
* @param Payload $payload
*
* @return mixed
*/
public function sendMessage(Payload $payload):mixed
{
// preparing SMSService ...
return $this->SMSService
->send($payload->getTo(), $payload->getToken());
}
// ...
}
Next, you should set the your // config/mobile_verifier.php
<?php
return [
'sms_client' => App\SampleSMSClient::class,
//...
]; UsageNow you are ready for sending a verification message! You just need to dispatch the <?php
use Illuminate\Auth\Events\Registered;
// Register user
event(new Registered($user));
//... At this point, a notification message has been sent to user automatically, and you've done half of the job! RoutingThis package includes the VerifyIn order to use this route, you should send
ResendIf you need to resend a verification message, you can use this route
// config/mobile_verifier.php
<?php
return [
'middleware' => ['auth:sanctum'],
//...
]; Customize Routes and ControllerIn order to change default routes prefix or routes themselves, you can customize them in config file: // config/mobile_verifier.php
<?php
return [
'routes_prefix' => 'auth',
'routes' => [
'verify' => '/mobile/verify',
'resend' => '/mobile/resend',
],
//...
]; Also, this package allows you to override default controller. To achieve this, you can extend your controller from // config/mobile_verifier.php
<?php
return [
'controller_namespace' => 'App\Http\Controllers',
//...
];
<?php
namespace App\Http\Controllers;
use Fouladgar\MobileVerification\Http\Controllers\BaseVerificationController;
class MobileVerificationController extends BaseVerificationController
{
/**
* Where to redirect users after verification.
*
* @var string
*/
protected $redirectTo = '/home';
}
Protecting RoutesRoute middleware can be used to only allow verified users to access a given route. This package ships with a verified middleware, which is defined at Route::get('profile', function () {
// Only verified users may enter...
})->middleware('mobile.verified'); Using QueueBy default, this package does not process sending verification messages in the queue. But if you want your sending messages to be queued, you may change // config/mobile_verifier.php
<?php
return [
/**
| Supported drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null"
*/
'queue' => [
'connection' => 'sync',
'queue' => 'default',
'tries' => 3,
'timeout' => 60,
]
]; Translates and ViewsTo publish translation file you may use this command:
If you are not using AJAX requests, you should have some views which we provided you some information through session variables. In case of errors, you just need to use laravel default // lang/vendor/MobileVerification/en/mobile_verification.php
<?php
return [
'successful_verification' => 'Your mobile has been verified successfully.',
'successful_resend' => 'The token has been resent successfully.',
'already_verified' => 'Your mobile already has been verified.',
//etc...
]; EventThis package dispatch an event during the mobile verification process. You may attach listeners to this event in your /**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'Fouladgar\MobileVerification\Events\Verified' => [
'App\Listeners\LogVerifiedUser',
],
]; Testingcomposer test ChangelogPlease see CHANGELOG for more information what has changed recently. ContributingPlease see CONTRIBUTING for details. SecurityIf you discover any security related issues, please email [email protected] instead of using the issue tracker. LicenseLaravel-Mobile-Verification is released under the MIT License. See the bundled LICENSE file for details. Built with |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论