承接 kaoken/laravel-confirmation-email 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

Travis composer version licence laravel version

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!)

  • model is a user model class
  • provider is the user table name
  • email_confirmation should modify the class derived fromMailable as necessary. Used to send confirmation mail.
  • email_registration should modify the class derived fromMailable as necessary. Mail sent when complete registering.
  • table is the name of the table used for this service
  • If expire does 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.

  • database
    • migrations
      • 2017_09_14_000001_create_confirmation_users_table.php
  • resources
    • lang
      • en
        • confirmation.php
      • ja
        • confirmation.php
    • views
      • vendor
        • confirmation
          • mail
            • confirmation.blade.php
            • registration.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();
    }

E-Mail

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

MIT

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 kaoken/laravel-confirmation-email 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 75
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-14