2017 © Pedro Peláez
 

library laravel-email-reset

Request to change the e-mail address of the Auth user, change it after moving to the specified URL of the confirmation e-mail.

image

kaoken/laravel-email-reset

Request to change the e-mail address of the Auth user, change it after moving to the specified URL of the confirmation e-mail.

  • Tuesday, January 9, 2018
  • by kaoken
  • Repository
  • 1 Watchers
  • 1 Stars
  • 85 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 183 % Grown

The README.md

laravel-email-reset

Request to change the e-mail address of the Auth user, change it after moving to the specified URL of the confirmation e-mail., (*1)

Travis branch composer version licence laravel version, (*2)

Table of content, (*3)

Install

composer:, (*4)

composer require kaoken/laravel-email-reset

Setting

Add to config\app.php as follows:

    'providers' => [
        ...
        // add
        Kaoken\LaravelMailReset\MailResetServiceProvider::class
    ],

    'aliases' => [
        ...
        // add
        'MailReset' => Kaoken\LaravelMailReset\Facades\MailReset::class
    ],

Example of adding to config\auth.php

add 'email_reset' => 'users',., (*5)

[
    ...
    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
        // add
        'email_reset' => 'users',
    ],
    ...
]
  • model is a user model class
  • email_confirmation should modify the class derived fromMailable as necessary. Used to send confirmation mail.
  • table is the name of the table used for this service
  • If expire does not manipulate X hours after registration, the 1st change email is deleted.
    'email_resets' => [
        'users' => [
            'model' => App\User::class,
            'email_reset' => Kaoken\LaravelMailReset\Mail\MailResetConfirmationToUser::class,
            'table' => 'mail_reset_users',
            'expire' => 1,
        ]
    ],

Command

php artisan vendor:publish --tag=mail-reset

After execution, the following directories and files are added., (*6)

  • database
    • migrations
    • 2017_09_21_000001_create_mail_reset_users_table.php
  • resources
    • lang
    • en
      • mail_reset.php
    • ja
      • mail_reset.php
    • views
    • vendor
      • confirmation
      • mail
        • confirmation.blade.php
    • complete.blade.blade.php

Migration

Migration file 2017_09_21_000001_create_mail_reset_users_table.php should be modified as necessary., (*7)

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 1 hour after 1st registration., (*8)

    protected function schedule(Schedule $schedule)
    {
        ...
        $schedule->call(function(){
            MailReset::broker('users')->deleteUserAndToken();
        )->hourly();
    }

E-Mail

In the configuration config\auth.php with the above setting, Kaoken\LaravelMailReset\Mail\MailResetConfirmationToUser::class of email_reset is used as a confirmation email when changing mail. The template is views\vendor\mail_reset\mail\confirmation.blade.php Is used. Change according to the specifications of the application., (*9)

controller

Example of changing e-mail address, (*10)

```php <?php namespace App\Http\Controllers; use Auth; use MailReset; use App\User; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Validator; use Kaoken\LaravelMailReset\Controllers\MailResetUsers;, (*11)

class MailResetController extends Controller {
use MailResetUsers; /** * use trit MailResetUsers * @var string */ protected $broker = 'users';, (*12)

 /**
  * Mail address change view
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function getChangeMail()
 {
     // 各自で用意する
     return view('change_email');
 }

 /**
  * Change user's email address
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse|mixed
  */
 public function postChangeMail(Request $request)
 {
     $all = $request->only(['email']);
     $validator = Validator::make($all,[
         'email' => 'required|unique:users,email|max:255|email',
     ]);

     if ($validator->fails()) {
         return redirect('change_email')
             ->withErrors($validator)
             ->withInput();
     }

     switch ( $this->sendMailAddressChangeLink(Auth::guard('customer')->user()->id, $all['email']) ) {
         case MailReset::INVALID_USER:
             redirect('first_register')
                 ->withErrors(['mail_reset'=>'Invalid user.']);
             break;
         case MailReset::SAME_EMAIL_EXIST:
             redirect('first_register')
                 ->withErrors(['mail_reset'=>'The same mail address already exists.']);
             break;
         case MailReset::INVALID_CONFIRMATION:
         default:
             redirect('first_register')
                 ->withErrors(['mail_reset'=>'An unexpected error occurred.']);
     }
     return redirect('change_email_ok');
 }

} ``` Be sure to write use MailResetUsers and $broker in the class., (*13)

Route

From the above controller!, (*14)

Route::group([
        'middleware' => ['auth:user'],
    ],
    function(){
        Route::get('user/mail/reset', 'MailResetController@getChangeMail');
        Route::post('user/mail/reset', 'MailResetController@postChangeMail');
    }
);
Route::get('user/mail/reset/{id}/{email}/{token}', 'MailResetController@getChangeMailAddress');

Events

See inside the vendor\kaoken\laravel-email-reset\src\Events directory!, (*15)

ChangedMailAddressEvent

Called after the mail address has been completely changed., (*16)

MailResetConfirmationEvent

It is called after saving the change candidate of the mail address., (*17)

License

MIT, (*18)

The Versions

09/01 2018

dev-master

9999999-dev https://github.com/kaoken/laravel-email-reset

Request to change the e-mail address of the Auth user, change it after moving to the specified URL of the confirmation e-mail.

  Sources   Download

MIT

The Requires

 

laravel laravel-email-reset

09/01 2018

1.0.3

1.0.3.0 https://github.com/kaoken/laravel-email-reset

Request to change the e-mail address of the Auth user, change it after moving to the specified URL of the confirmation e-mail.

  Sources   Download

MIT

The Requires

 

laravel laravel-email-reset

22/09 2017

1.0.0

1.0.0.0 https://github.com/kaoken/laravel-email-reset

Request to change the e-mail address of the Auth user, change it after moving to the specified URL of the confirmation e-mail.

  Sources   Download

MIT

The Requires

 

laravel laravel-email-reset