kaoken/laravel-confirmation-email
Composer 安装命令:
composer require kaoken/laravel-confirmation-email
包简介
Laravel sends confirmation mail after Auth user first registration, complete registration is done after accessing designated address.
README 文档
README
Laravel sends confirmation mail after Auth user first registration, complete registration is done after accessing designated address.
Table of content
Install
composer:
composer require kaoken/laravel-confirmation-email
Setting
Add to config\app.php as follows:
'providers' => [ ... // add Kaoken\LaravelConfirmation\ConfirmationServiceProvider::class ], 'aliases' => [ ... // add 'Confirmation' => Kaoken\LaravelConfirmation\Facades\Confirmation::class ],
Example of adding to config\auth.php
add 'confirmation' => 'users',.
[
...
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
// add
'confirmation' => 'users',
],
...
]
When the Auth user is users(Make sure Auth user name is table name!)
modelis a user model classprovideris the user table nameemail_confirmationshould modify the class derived fromMailable as necessary. Used to send confirmation mail.email_registrationshould modify the class derived fromMailable as necessary. Mail sent when complete registering.tableis the name of the table used for this service- If
expiredoes not manipulate X hours after registration, the 1st registered user is deleted.
'confirmations' => [ 'users' => [ 'model' => App\User::class, 'path' => 'user/register/', 'email_confirmation' => Kaoken\LaravelConfirmation\Mail\ConfirmationMailToUser::class, 'email_registration' => Kaoken\LaravelConfirmation\Mail\RegistrationMailToUser::class, 'table' => 'confirmation_users', 'expire' => 24, ] ],
Command
php artisan vendor:publish --tag=confirmation
After execution, the following directories and files are added.
databasemigrations2017_09_14_000001_create_confirmation_users_table.php
resourceslangenconfirmation.php
jaconfirmation.php
viewsvendorconfirmationmailconfirmation.blade.phpregistration.blade.php
registration.blade.php
Migration
Migration file 2017_09_14_000001_create_confirmation_users_table.php should be modified as necessary.
php artisan migrate
Add to kernel
Add it to the schedule method of app\Console\Kernel.php.
This is used to delete users who passed 24 hours after 1st registration.
protected function schedule(Schedule $schedule) { ... $schedule->call(function(){ Confirmation::broker('user')->deleteUserAndToken(); )->hourly(); }
In the configuration config\auth.php with the above setting,
Kaoken\LaravelConfirmation\Mail\ConfirmationMailToUser of email_confirmation
is used as a confirmation mail at the time of 1st registration.
The template uses views\vendor\confirmation\confirmation.blade.php.
Kaoken\LaravelConfirmation\Mail\RegistrationMailToUser of email_registration
is used as a mail informing that the complete registration was done.
The template uses views\vendor\confirmation\registration.blade.php.
Change according to the specifications of the application.
controller
Example of 1st registration, complete registration, login
<?php namespace App\Http\Controllers; use App\User; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Validator; use Kaoken\LaravelConfirmation\Controllers\AuthenticatesUsers; use Kaoken\LaravelConfirmation\Controllers\ConfirmationUser; class RegisterUserController extends Controller { use AuthenticatesUsers, ConfirmationUser; /** * Use with AuthenticatesUsers trait. * @var string */ protected $broker = 'users'; /** * 1st registration View * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function getFirstRegister() { // Be prepared by yourself. return view('first_step_register'); } /** * 1st registration * @param Request $request * @return \Illuminate\Http\JsonResponse|mixed */ public function postFirstRegister(Request $request) { $all = $request->only(['name', 'email', 'password']); $validator = Validator::make($all,[ 'name' => 'required|max:24', 'email' => 'required|unique:users,email|max:255|email', 'password' => 'required|between:6,32' ]); if ($validator->fails()) { return redirect('first_register') ->withErrors($validator) ->withInput(); } $all['password'] = bcrypt($all['password']); if ( !$this->createUserAndSendConfirmationLink($all) ) { return redirect('first_register') ->withErrors(['confirmation'=>'仮登録に失敗しました。']); } // Move to the page notifying 1st registration return redirect('first_register_ok'); } }
Be sure to add $broker.
Route
From the above controller!
Route::group([ 'middleware' => ['guest:user'] ], function(){ Route::get('login', 'AuthController@login'); } ); Route::get('register', 'AuthController@getFirstRegister'); Route::post('register', 'AuthController@postFirstRegister'); Route::get('register/{email}/{token}', 'AuthController@getCompleteRegistration');
Auth Model
Auth user model example
Added of Kaoken\LaravelConfirmation\HasConfirmation;
<?php namespace App; use Kaoken\LaravelConfirmation\HasConfirmation; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable, HasConfirmation; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; }
By using the confirmed() method, we decide whether it is a registered user.
When using social login, it is good to incorporate confirmed() so that it can be determined.
Events
See inside the vendor\kaoken\laravel-confirmation-email\src\Events directory!
BeforeCreateUserEvent
Called before the user is created.
Warning: When this event is invoked, a DB transaction related to Auth user creation is in progress.
If you create an exception in the listener, the Auth user creation of the target is immediately rolled back.
BeforeDeleteUsersEvent
Called before deleting expired users.
This is only called if you deleteUserAndToken(true) the method argument to true in Confirmation::broker('hoge')->deleteUserAndToken();.
Warning: When this event is called, the DB transaction associated with expired Auth user deletion is in progress.
If you create an exception with the listener, the target Auth user deletion is immediately rolled back.
CreatedUserEvent
Called after Auth user is created.
ConfirmationEvent
After sending the confirmation mail, An Auth user is created and called.
RegistrationEvent
Called after Auth user complete registration.
License
kaoken/laravel-confirmation-email 适用场景与选型建议
kaoken/laravel-confirmation-email 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 75 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 09 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「confirmation-email」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kaoken/laravel-confirmation-email 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kaoken/laravel-confirmation-email 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kaoken/laravel-confirmation-email 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
Boot a Laravel project on any machine with one command: app:serve installs missing tools (PHP, Node, Composer, Herd, Docker), creates .env, sets up the database, runs migrations, builds assets, starts a queue worker and serves via Herd, Sail or artisan serve; app:down cleanly stops everything it sta
Branded, diagnostic error pages (500, 403, 404, 419, 503) for Filament — native Filament UI, dark mode and translations out of the box.
Turn any PDF into a Pingen-ready A4 letter (generated address cover page + A4 normalisation + safe margins) and send it through the Pingen print & mail API. Laravel-first.
统计信息
- 总下载量: 75
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-09-14