Laravel 6 Auth注册表表单未执行电子邮件验证



我是Laravel的新手刚刚安装了Laravel 6 Auth。执行了注册和登录。我知道,当我注册用户时,它会在成功注册后自动登录,而不是向我显示验证刀片和发送电子邮件的视图。我不知道为什么这么做,我查看了很多教程,并比较了我的模型、控制器、视图和路由脚本。它与此链接建议的相同

这是我的Registrationcontroller.php

<?php
namespace AppHttpControllersAuth;
use AppHttpControllersController;
use AppProvidersRouteServiceProvider;
use AppUser;
use IlluminateFoundationAuthRegistersUsers;
use IlluminateSupportFacadesHash;
use IlluminateSupportFacadesValidator;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
// protected $redirectTo = RouteServiceProvider::HOME;
protected $redirectTo = RouteServiceProvider::VERIFICATION;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
//$this->middleware(['auth','verified']);
}
/**
* Get a validator for an incoming registration request.
*
* @param  array  $data
* @return IlluminateContractsValidationValidator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'], 
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param  array  $data
* @return AppUser
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}
VerificationController.php
<?php
namespace AppHttpControllersAuth;
use AppHttpControllersController;
use AppProvidersRouteServiceProvider;
use IlluminateFoundationAuthVerifiesEmails;
class VerificationController extends Controller
{
/*
|--------------------------------------------------------------------------
| Email Verification Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling email verification for any
| user that recently registered with the application. Emails may also
| be re-sent if the user didn't receive the original email message.
|
*/
use VerifiesEmails;
/**
* Where to redirect users after verification.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}
}

用户模型Users.php

<?php
namespace App;
use IlluminateContractsAuthMustVerifyEmail;
use IlluminateFoundationAuthUser as Authenticatable;
use IlluminateNotificationsNotifiable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}

routes.php文件是

<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('auth/login');
});
Auth::routes();
Auth::routes(['/verify' => true]);
// Only verified users may enter...
Route::get('/home', 'HomeController@index')->name('home');
//Route::get('/verify', 'AuthVerificationController@index')->name('verify');

//Route::get('/home', 'HomeController@index')->name('home');
//Route::resource('clients','ClientsController@index');
//Clients
Route::get('/clients', 'ClientsController@index')->name('clients');
Route::get('/addclient', 'ClientsController@create')->name('addclient');
Route::post('/addclient', 'ClientsController@store')->name('addclient');
//Members
Route::get('/members', 'MembersController@index')->name('members');
Route::get('/addmember', 'MembersController@create')->name('addmember');
Route::post('/addmember', 'MembersController@store')->name('addmember');
//Events
Route::get('/events', 'EventsController@index')->name('events');
Route::get('/addevent', 'EventsController@create')->name('addevent');
Route::post('/addevent', 'EventsController@store')->name('addevent');
Auth::routes();
//Route::get('/home', 'HomeController@index')->name('home');

路由服务提供商RouteServiceProvider.php

<?php
namespace AppProviders;
use IlluminateFoundationSupportProvidersRouteServiceProvider as ServiceProvider;
use IlluminateSupportFacadesRoute;
class RouteServiceProvider extends ServiceProvider
{
/**
* This namespace is applied to your controller routes.
*
* In addition, it is set as the URL generator's root namespace.
*
* @var string
*/
protected $namespace = 'AppHttpControllers';
/**
* The path to the "home" route for your application.
*
* @var string
*/
public const HOME = '/home';
public const VERIFICATION = '/verify';
//public const VERIFICATION = 'password/verify';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
//
parent::boot();
}
/**
* Define the routes for the application.
*
* @return void
*/
public function map()
{
$this->mapApiRoutes();
$this->mapWebRoutes();
//
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
}

.env文件

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:appkey
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=version2
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=ENTER_YOUR_EMAIL_ADDRESS(GMAIL)
MAIL_PASSWORD=ENTER_YOUR_GMAIL_PASSWORD
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=my email address
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

能帮我解决这个问题吗?

您必须在模型中使用MustVerifyEmail

class User extends Authenticatable implements MustVerifyEmail
{
....
}

相关内容

  • 没有找到相关文章

最新更新