tebros/laravel-email-confirmation

为 Laravel 框架集成的电子邮件确认。

1.2.0 2018-01-30 20:43 UTC

This package is auto-updated.

Last update: 2024-09-25 07:46:57 UTC


README

Latest Version on Packagist Software License Total Downloads

此包将电子邮件确认集成到默认的 Laravel 认证中。

它为 Laravel 5.5 开发和测试过,但应也能与其他版本的 Laravel 一起使用。

安装

使用 composer 需求此包。

安装会自动在 routes/web.php 文件中追加一个函数调用。请不要将其注释掉!

composer require tebros/laravel-email-confirmation

如果尚未执行,请运行 make:auth 命令。

如果您以前已执行过此命令,请跳过此步骤。

php artisan make:auth

创建所需表 users_confirmation 的迁移。

php artisan migrate

编辑 app/Http/Controllers/Auth/RegisterController.php 文件。

编辑相当简单。要挂钩到默认的 Laravel 认证过程,您需要更改顶部的 RegistersUsers 特性。

//comment out the line like this or just override it
//use RegistersUsers;

use \Tebros\EmailConfirmation\Traits\RegistersUsers; //use this trait instead of the default

编辑 app/Http/Controllers/Auth/LoginController.php 文件。

如果账户未确认,则需要显示正确的消息。

//comment out the line like this or just override it
//use AuthenticatesUsers;

use \Tebros\EmailConfirmation\Traits\AuthenticatesUsers; //use this trait instead of the default

确保您的 config/mail.php 文件包含以下重要设置

  • MAIL_DRIVER
  • MAIL_HOST
  • MAIL_PORT
  • MAIL_USERNAME, MAIL_PASSWORD
  • MAIL_FROM_ADDRESS, MAIL_FROM_NAME

此外,确保您的 config/app.php 文件包含以下重要设置

  • APP_NAME
  • APP_URL

配置和发布

安装后,您可以使用 confirm 路由名称来链接“重新发送确认电子邮件”页面。

重要!您应编辑您的 auth/login.blade.php 视图,并添加此链接以请求新的确认电子邮件!

<div class="form-group">
    <div class="col-md-8 col-md-offset-4">
        <button type="submit" class="btn btn-primary">
            Login
        </button>

        <a class="btn btn-link" href="{{ route('password.request') }}">
            Forgot Your Password?
        </a>

        <a class="btn btn-link" href="{{ route('confirm') }}">
            Resend Confirmation Link?
        </a>
    </div>
</div>

如果您想配置电子邮件确认,请运行以下命令。

您可以根据需要修改 config/emailconfirmation.php 文件。

php artisan vendor:publish --tag=emailconfirmation-config

要更改消息或文本,您可以在 lang/vendor/emailconfirmation 目录中修改文件。

运行以下命令来完成此操作。

php artisan vendor:publish --tag=emailconfirmation-translation

如果您不想使用默认的 Laravel 视图,您可以在 views/vendor/emailconfirmation 目录中修改视图。

运行以下命令来完成此操作。

php artisan vendor:publish --tag=emailconfirmation-views

更新

您可以通过运行以下命令来更新包,或使用 composer update 更新所有依赖项。

composer update tebros/laravel-email-confirmation

如果您想更新已发布的文件,如 config/emailconfirmation.phplang/vendor/emailconfirmationviews/vendor/emailconfirmation,您可以使用以下命令。

注意!这些命令将覆盖您的发布文件。因此,如果您不想丢失它们,请备份您的配置、视图或语言文件!

php artisan vendor:publish --tag=emailconfirmation-config --force
php artisan vendor:publish --tag=emailconfirmation-translation --force
php artisan vendor:publish --tag=emailconfirmation-views --force

卸载

您应在您的 routes/web.php 文件中删除以下两行。

// Register routes for email confirmation. The uri is "/confirm"
Tebros\EmailConfirmation\Utils::routes();

编辑 app/Http/Controllers/Auth/RegisterController.php 文件和 app/Http/Controllers/Auth/LoginController.php 文件以删除 Laravel 钩子。

//remove the comment that the orifinal trait is used
use RegistersUsers;

//remove the whole line or comment it out
//use \Tebros\EmailConfirmation\Traits\RegistersUsers; 
//remove the comment that the orifinal trait is used
use AuthenticatesUsers;

//remove the whole line or comment it out
//use \Tebros\EmailConfirmation\Traits\AuthenticatesUsers; 

现在只需键入以下命令。

composer remove tebros/laravel-email-confirmation

许可证

此包是开源软件,根据 MIT 许可证 许可。