首页 > 解决方案 > 如何在 laravel 背包中使用电子邮件验证用户?

问题描述

所以我想验证用户是否已经注册,他们必须先验证他们的帐户,然后才能登录他们的帐户。

 Mail::send([],[], function($message) use($input) {
                
            $message->to($input['email'])
                    ->subject('Your New Password ')
                    ->setBody(
                        '<html><h2>Please click button below to verify your email</h2>
                        <br> <form method ="POST" action="{{ 
                         url(`verification/{'.$input['email'].'}`) }}">
                            <input type="submit" value="Verify Now" />
                        </form>
                        </html>','text/html'
                    );
            $message->from(env('MAIL_USERNAME','victoriussaputra@gmail.com'),'Victorius');
        });
        return $this->sendResponse($success, 'Please verify your email to login');

这个想法是,当用户在他们的电子邮件中单击“立即验证”按钮时,它会自动运行 API 来通过将验证从 0 更新为 1 来验证用户。

$query = DB::table('users')
        ->select(DB::raw('COUNT(users.id) as totalemail'))
        ->where('email',$email)
        ->first();
        if($query->totalemail>=1)
        {
            $update = DB::table('users')
            ->where('email',$email)
            ->update([
                'verification'=> 1
            ]); 
            return $this->sendResponse($update, 'Success');
        }
        else{
            return $this->sendError('Unauthorised.', ['error'=>'Unauthorised']);
        }

但是,当我通过 gmail 单击电子邮件中的按钮时,它只是刷新了 gmail 页面,但没有更新已验证的列。

这是我用于更新验证和注册的 API 路由

Route::post('verification/{email}','App\Http\Controllers\API\RegisterController@updateVerification'); Route::post('register', 'App\Http\Controllers\API\RegisterController@register');

标签: laravel-backpack

解决方案


推荐阅读