Git Product home page Git Product logo

laravel-email-verification's Introduction

Build Status Total Downloads Latest Stable Version License

⚠️ Deprecation Warning: This package is deprecated. I recommend using Laravel's built in email verification.

Introduction

The Laravel Email Verification package is built for Laravel 5.4 and later to easily handle a user verification and validate the e-mail. It is inspired by crypto-based password resets and the email verification package by jrean.

  • Crypto-based email verification. No need to store a temporary token in the database!
  • Event based: No need to override your register() method.
  • Using the Laravel 5.3 notification system.
  • Allow certain routes for verified users only using the IsEmailVerified middleware.
  • Let the users resend the verification email at anytime.
  • Ready for Localization.

Configuration

To get started, use Composer to add the package to your project's dependencies:

composer require josiasmontag/laravel-email-verification

In Laravel 5.5 the service provider will automatically get registered. In older versions of the framework just register the Lunaweb\EmailVerification\Providers\EmailVerificationServiceProvider in your config/app.php configuration file:

'providers' => [
    // Other service providers...

    Lunaweb\EmailVerification\Providers\EmailVerificationServiceProvider::class,
],

Migration

The table representing the user must be updated with a verified column. This update will be performed by the migrations included with this package.

To run the migrations from this package use the following command:

php artisan migrate --path="/vendor/josiasmontag/laravel-email-verification/database/migrations"

The package tries to guess your user table by checking what is set in the auth providers users settings. If this key is not found, the default App\User will be used to get the table name.

To customize the migration, publish it with the following command:

php artisan vendor:publish --provider="Lunaweb\EmailVerification\Providers\EmailVerificationServiceProvider" --tag="migrations"

User Model

The model representing the User must implement the CanVerifyEmail interface. The package comes with a CanVerifyEmail trait for a quick implementation. You can customize this trait in order to change the activation email.

use Illuminate\Foundation\Auth\User as Authenticatable;
use Lunaweb\EmailVerification\Traits\CanVerifyEmail;
use Lunaweb\EmailVerification\Contracts\CanVerifyEmail as CanVerifyEmailContract;

class User extends Authenticatable implements CanVerifyEmailContract
{

    use CanVerifyEmail;

    // ...
}

Register Controller

The package offers a VerifiesEmail trait for your RegisterController. You must update the middleware exception to allow verify routes to be access by authenticated users.

use Lunaweb\EmailVerification\Traits\VerifiesEmail;

class RegisterController extends Controller
{

    use RegistersUsers, VerifiesEmail;


    public function __construct()
    {
          $this->middleware('guest', ['except' => ['verify', 'showResendVerificationEmailForm', 'resendVerificationEmail']]);
          $this->middleware('auth', ['only' => ['showResendVerificationEmailForm', 'resendVerificationEmail']]);
    }

    // ...

}

There is no need to override register(). As default, the package listens for the Illuminate\Auth\Events\Registered event and sends the verification mail. You can disable this behavior using the listen_registered_event setting.

Routes

The package adds the following routes.

Route::get('register/verify', 'App\Http\Controllers\Auth\RegisterController@verify')->name('verifyEmailLink');
Route::get('register/verify/resend', 'App\Http\Controllers\Auth\RegisterController@showResendVerificationEmailForm')->name('showResendVerificationEmailForm');
Route::post('register/verify/resend', 'App\Http\Controllers\Auth\RegisterController@resendVerificationEmail')->name('resendVerificationEmail');

Middleware

To register the IsEmailVerified middleware add the following to the $routeMiddleware array within the app/Http/Kernel.php file:

protected $routeMiddleware = [
    // …
    'isEmailVerified' => \Lunaweb\EmailVerification\Middleware\IsEmailVerified::class,

Apply the middleware on your routes:

Route::group(['middleware' => ['web', 'auth', 'isEmailVerified']], function () {
    …

Events

The package emits 2 events:

  • Lunaweb\EmailVerification\Events\EmailVerificationSent
  • Lunaweb\EmailVerification\Events\UserVerified

Resend the verification mail

Using the isEmailVerified Middleware, the following form is shown to the user. It allows the user to correct his email address and resend the verification mail.

Screenshot

You can manually point the user to this form using the showResendVerificationEmailForm route (Default: register/verify/resend).

To programmatically resend the verification mail:

$this->app->make('Lunaweb\EmailVerification\EmailVerification')->sendVerifyLink($user);

Customize the verification mail

Therefore, override sendEmailVerificationNotification() of your User model. Example:

class User implements CanVerifyEmailContract
{

    use CanVerifyEmail;

    /**
     * Send the email verification notification.
     *
     * @param  string  $token   The verification mail reset token.
     * @param  int  $expiration The verification mail expiration date.
     * @return void
     */
    public function sendEmailVerificationNotification($token, $expiration)
    {
        $this->notify(new MyEmailVerificationNotification($token, $expiration));
    }
}

Customize the resend form

php artisan vendor:publish --provider="Lunaweb\EmailVerification\Providers\EmailVerificationServiceProvider" --tag="views"

The template can be found in resources/views/vendor/emailverification/resend.blade.php

Customize the messages / localization

php artisan vendor:publish --provider="Lunaweb\EmailVerification\Providers\EmailVerificationServiceProvider" --tag="translations"

The localization files can be found in resources/lang/vendor/emailverification

laravel-email-verification's People

Contributors

antonzapevalov avatar daneswood-matt avatar dylan-dpc avatar josiasmontag avatar tominon avatar yahav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-email-verification's Issues

programmatically sending email verification error

I am going to integrate email verification with React and I need to implement the sending email verification API.

$this->app->make('Lunaweb\EmailVerification\EmailVerification')->sendVerifyLink($user);

so, when I run this code, it occurs error.
Illuminate\Auth\RequestGuard::getDispatcher does not exist

I think this error is coming from service provider (Auth::getDispatcher())
$this->app->singleton(\Lunaweb\EmailVerification\EmailVerification::class, function ($app) {
return new EmailVerification(
Auth::getProvider(),
Auth::getDispatcher(),
config('app.key'),
config('emailverification.expire', 1440)
);
});

My laravel version is 5.6.x

after upgrade to Laravel 5.7: Declaration of Lunaweb\EmailVerification\Traits\CanVerifyEmail::sendEmailVerificationNotification($token, $expiration) should be compatible with Illuminate\Foundation\Auth\User::sendEmailVerificationNotification()

class User extends Authenticatable implements CanVerifyEmailContract, PlanSubscriberInterface
{
ErrorException (E_WARNING)
Declaration of Lunaweb\EmailVerification\Traits\CanVerifyEmail::sendEmailVerificationNotification($token, $expiration) should be compatible with Illuminate\Foundation\Auth\User::sendEmailVerificationNotification()

Any idea what its all about?

Ability to skip verification

Hi, thanks 🙏 for this great package, very useful and is working good.
I've a case use where I'm inviting people to this laravel application via email and my boss asked me to skip the verification if the user has been invited via email since he already clicked on the "Accept Invite" button on the email so it's kind of already verified.

I've tried to modify the SendUserVerificationMail which is responsable to listen for Registered events and send the email to this:

if (Session::has('invite_token')) {

        $event->user->forceFill([
          'verified' => true
        ])->save();

} else {

        if (config('emailverification.listen_registered_event', true)) {

          $sent = resolve('Lunaweb\EmailVerification\EmailVerification')->sendVerifyLink($event->user);
          Session::flash($sent == EmailVerification::VERIFY_LINK_SENT ? 'success' : 'error', trans($sent));

        }

}

in hope of make it working and skip the isEmailVerified middleware but unfortunatelly is not working and still goes to the verification resend page but with the message "You are already verified" since I changed the verified flag on the user profile after a good registration.

Any idea about how I can archive this result? basically in this particular case I need to skip the email verification.

FatalThrowableError

I have followed your instructions and complement the steps. I have laravel 5.5
when I click the register in my views, I get

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR)
  Type error: Argument 1 passed to Lunaweb\EmailVerification\EmailVerification::createToken() must 
  be an instance of Lunaweb\EmailVerification\Contracts\CanVerifyEmail, instance of App\User given, 
  called in /Users/sam/site/vendor/josiasmontag/laravel-email-verification/src/EmailVerification.php 
  on line 127

when I check my database the user values gets insert into the user table. What might be the cause.

Email verification for other model?

Can I implement CanVerifyEmailContract on model Comment? I need do email verification for comments system. When guest create comment, he can write email, name, and body of comment. When guest send comment, I need verify email him.

No views copied after publish

After run:

php artisan vendor:publish --provider="Lunaweb\EmailVerification\Providers\EmailVerificationServiceProvider" --tag="views"

Any view files are copied. Can someone check this?

Class 'Lunaweb\User\Http\Controllers\Controller' not found

Laravel 5.5

In your readme.md file you override default Controller to custom Lunaweb\User\Http\Controllers\Controller in file RegisterController.php. Why?

use Lunaweb\EmailVerification\Traits\VerifiesEmail;
use Lunaweb\User\Http\Controllers\Controller;

class RegisterController extends Controller
{

    use RegistersUsers, VerifiesEmail;


    public function __construct()
    {
          $this->middleware('guest', ['except' => ['verify', 'showResendVerificationEmailForm', 'resendVerificationEmail']]);
          $this->middleware('auth', ['only' => ['showResendVerificationEmailForm', 'resendVerificationEmail']]);
    }

    // ...

}

And that Controller not found)))

image

whole package

can you upload the whole package, i am new to laravel so it a lot confusing for me,

[enhancement] multi-auth email verification

Hi there,
Nice package. if you have the time you could add the ability to verify email for multi-auth system.
either way if you have any pointers on how to go about it, that would be great. thanks.

Verifcation mail never sent

Hi,

$this->app->make('Lunaweb\EmailVerification\EmailVerification')->sendVerifyLink($user);

does not do anything, no errors, no emails sent.

Sending emails (via mailgun) is all set up and working.

What am I missing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.