All Projects → protonemedia → Laravel Verify New Email

protonemedia / Laravel Verify New Email

Licence: mit
This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.

Projects that are alternatives of or similar to Laravel Verify New Email

Blog System In Laravel
Complete Blog System in Laravel
Stars: ✭ 89 (-1.11%)
Mutual labels:  laravel, laravel-framework
Backup
MySQL Database backup package for Laravel
Stars: ✭ 66 (-26.67%)
Mutual labels:  laravel, laravel-framework
Laravel Compass
A REST client inside your Laravel app
Stars: ✭ 1,002 (+1013.33%)
Mutual labels:  laravel, laravel-framework
Larawiz
Larawiz is a easy project scaffolder for Laravel
Stars: ✭ 28 (-68.89%)
Mutual labels:  laravel, laravel-framework
Laravel 5 Messenger
A Simple Laravel 5, 6, 7 & 8 Messenger with Pusher Capabilities
Stars: ✭ 75 (-16.67%)
Mutual labels:  laravel, laravel-framework
Laravel Qrcode Ecommerce
This is a complete laravel project that handles qrcodes, payments, api/microservices, and ecommerce
Stars: ✭ 36 (-60%)
Mutual labels:  laravel, laravel-framework
Laravel Potion
laravel - Potion is a pure PHP asset manager for Laravel 5 based off of Assetic.
Stars: ✭ 63 (-30%)
Mutual labels:  laravel, laravel-framework
Laravel Ecommerce Example
Code for YouTube series on building a Laravel E-Commerce application.
Stars: ✭ 759 (+743.33%)
Mutual labels:  laravel, laravel-framework
Laraupdater
Enable Laravel App Self-Update. Allow your Laravel Application to auto-update itself.
Stars: ✭ 75 (-16.67%)
Mutual labels:  laravel, laravel-framework
Pingcrm Svelte
🦊 Ping CRM Svelte - A demo app to illustrate how Inertia.js works with Laravel and Svelte (hosted on a heroku free dyno).
Stars: ✭ 74 (-17.78%)
Mutual labels:  laravel, laravel-framework
Laravel Blog 5.6.5
Learning Laravel by making simple Blog
Stars: ✭ 12 (-86.67%)
Mutual labels:  laravel, laravel-framework
Brandenburg
Laravel Authentication Package
Stars: ✭ 79 (-12.22%)
Mutual labels:  laravel, laravel-framework
Laravel Restaurant Pos
Restaurant POS
Stars: ✭ 27 (-70%)
Mutual labels:  laravel, laravel-framework
Laravel Ip Gateway
Laravel IP Gateway
Stars: ✭ 37 (-58.89%)
Mutual labels:  laravel, laravel-framework
Laravel Stager
Laravel Stager State Machine, Its purpose is to add state machine functionality to models
Stars: ✭ 16 (-82.22%)
Mutual labels:  laravel, laravel-framework
Laravel Course
Laravel Essentials Udemy course Full Source Code
Stars: ✭ 59 (-34.44%)
Mutual labels:  laravel, laravel-framework
Snooze
A package to simplify automating future notifications and reminders in Laravel
Stars: ✭ 515 (+472.22%)
Mutual labels:  laravel, laravel-framework
Laravel Open Source Projects
A Web Artisan list of categorized OPEN SOURCE PROJECTS built with Laravel PHP Framework.
Stars: ✭ 676 (+651.11%)
Mutual labels:  laravel, laravel-framework
Gtrader
a trading strategy trainer, back-tester and bot
Stars: ✭ 71 (-21.11%)
Mutual labels:  laravel, laravel-framework
Laravel Schedulable
Schedule and unschedule eloquent models elegantly without cron jobs
Stars: ✭ 78 (-13.33%)
Mutual labels:  laravel, laravel-framework

Laravel Verify New Email

Latest Version on Packagist run-tests Quality Score Total Downloads

Laravel supports verifying email addresses out of the box. This package adds support for verifying new email addresses. When a user updates its email address, it won't replace the old one until the new one is verified. Super easy to set up, still fully customizable. If you want it can be used as a drop-in replacement for the built-in Email Verification features as this package supports unauthenticated verification and auto-login. Support for Laravel 6.0 and higher and requires PHP 7.3 or higher.

Blogpost

If you want to know more about the background of this package, please read the blogpost.

Support

We proudly support the community by developing Laravel packages and giving them away for free. Keeping track of issues and pull requests takes time, but we're happy to help! If this package saves you time or if you're relying on it professionally, please consider supporting the maintenance and development.

Installation

You can install the package via composer:

composer require protonemedia/laravel-verify-new-email

Configuration

Publish the database migration, config file and email view:

php artisan vendor:publish --provider="ProtoneMedia\LaravelVerifyNewEmail\ServiceProvider"

You can set the redirect path in the verify-new-email.php config file. The user will be redirected to this path after verification.

The expire time of the verification URLs can be changed by updating the auth.verification.expire setting and defaults to 60 minutes.

Usage

Add the MustVerifyNewEmail trait to your User model and make sure it implements the framework's MustVerifyEmail interface as well.

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use ProtoneMedia\LaravelVerifyNewEmail\MustVerifyNewEmail;

class User extends Authenticatable implements MustVerifyEmail
{
    use MustVerifyNewEmail, Notifiable;
}

Now your User model has a few new methods:

// generates a token and sends a verification mail to '[email protected]'.
$user->newEmail('[email protected]');

// returns the currently pending email address that needs to be verified.
$user->getPendingEmail();

// resends the verification mail for '[email protected]'.
$user->resendPendingEmailVerificationMail();

// deletes the pending email address
$user->clearPendingEmail();

The newEmail method doesn't update the user, its current email address stays current until the new one if verified. It stores a token (associated to the user and new email address) in the pending_user_emails table. Once the user verifies the email address by clicking the link in the mail, the user model will be updated and the token will be removed from the pending_user_emails table.

The resendPendingEmailVerificationMail does exactly the same, it just grabs the new email address from the previous attempt.

Login after verification

The user that verified its email address will be logged in automatically. You can disable this by chaning the login_after_verification configuration setting to false.

Overriding the default Laravel Email Verification

The default Laravel implementation requires the user to be logged in before it can verify its email address. If you want to use this package's logic to handle that first verification flow as well, override the sendEmailVerificationNotification method as shown below.

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use ProtoneMedia\LaravelVerifyNewEmail\MustVerifyNewEmail;

class User extends Authenticatable implements MustVerifyEmail
{
    use MustVerifyNewEmail, Notifiable;

    public function sendEmailVerificationNotification()
    {
        $this->newEmail($this->getEmailForVerification());
    }
}

Customization

You can change the content of the verification mail by editing the published views which can be found in the resources/views/vendor/verify-new-email folder. The verifyNewEmail.blade.php view will be sent when verifying updated email addresses. The verifyFirstEmail.blade.php view will be sent when a User verifies its initial email address for the first time (after registering). Alternatively you set your own custom Mailables classes in the config file:

<?php

return [

    'mailable_for_first_verification' => \ProtoneMedia\LaravelVerifyNewEmail\Mail\VerifyFirstEmail::class,

    'mailable_for_new_email' => \ProtoneMedia\LaravelVerifyNewEmail\Mail\VerifyNewEmail::class,

];

You can also override the sendPendingEmailVerificationMail method to change the behaviour of sending the verification mail:

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use ProtoneMedia\LaravelVerifyNewEmail\MustVerifyNewEmail;
use ProtoneMedia\LaravelVerifyNewEmail\PendingUserEmail;

class User extends Authenticatable implements MustVerifyEmail
{
    use MustVerifyNewEmail, Notifiable;

    public function sendPendingEmailVerificationMail(PendingUserEmail $pendingUserEmail)
    {
        // send the mail...
    }
}

The package has a controller to handle the activation of the new email address. You can specify a custom route in the config file which will be used to generate the verification URL. The token will be passed in as a parameter and the URL will be signed.

<?php

return [

    'route' => 'user.email.verify',

];

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Other Laravel packages

  • Laravel Analytics Event Tracking: Laravel package to easily send events to Google Analytics.
  • Laravel Blade On Demand: Laravel package to compile Blade templates in memory.
  • Laravel Cross Eloquent Search: Laravel package to search through multiple Eloquent models.
  • Laravel Eloquent Scope as Select: Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery.
  • Laravel Eloquent Where Not: This Laravel package allows you to flip/invert an Eloquent scope, or really any query constraint.
  • Laravel FFMpeg: This package provides an integration with FFmpeg for Laravel. The storage of the files is handled by Laravel's Filesystem.
  • Laravel Form Components: Blade components to rapidly build forms with Tailwind CSS Custom Forms and Bootstrap 4. Supports validation, model binding, default values, translations, includes default vendor styling and fully customizable!
  • Laravel Mixins: A collection of Laravel goodies.
  • Laravel Paddle: Paddle.com API integration for Laravel with support for webhooks/events.
  • Laravel WebDAV: WebDAV driver for Laravel's Filesystem.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].