0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravelでメール本人認証機能(Auth/ui)

0
Posted at

auth/uiでメール認証機能を有効化

仮登録(ユーザー名、メール、パスワード)

メール認証

本登録完了

修正するファイル

・web.php(ルート)
・Model\User.php(モデル)
・Controller.php(認証ブロックを付けたいコントローラ(ここでは、HomeController))

web.php

.php
Auth::routes(['verify' => true]);
//------------------------------
// Auth::routes();

User.php

User.php
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
use Illuminate\Auth\MustVerifyEmail;
// ーーーーーーーーーーーーーーーーーーーーーーーーーーー
// use Illuminate\Contracts\Auth\MustVerifyEmail;
:
:
Class User extends Authenticatable implements MustVerifyEmailContract
// ーーーーーーーーーーーーーーーーーーーーーー
// class User extends Authenticatable
{

Controller.php

HomeController.php
    public function __construct()
    {
        $this->middleware('verified');
        //----------------------------
        //$this->middleware('auth');
    }

余談

認証メールの解説

スクリーンショット 2021-08-23 12.18.53.png

ボタンのリンクは以下のような形

.bash
/email/verify/(ユーザーID)/hash?expires=(有効期限)$signature=(署名)
.bash
# user->id = 3のユーザー
http://127.0.0.1/email/verify/3/8ea6137184b4298b2f550f5834ee31f80f59b304?expires=1629685982&signature=aeb6ffb3681bd6f3fcb4c0341db5596aea982c59eb0232eb1d30ce398c143044

# user->id = 1のユーザー
http://127.0.0.1/email/verify/1/abd800ce5b346703821c385da2aa4aad5ace231b?expires=1629685921&signature=58d608c85f75beec85c6019343d29a1113ad60b31962fa94aaaebcd9e9d189b3

以下はパスワードリセット

.bash
http://127.0.0.1/password/reset/a115872add0ed417936c99c576a55d0bb4c6f3b19b5b21054ae0ae289044c6f3?email=c%40t
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?