身份验证::尝试通过但失败的中间件("身份验证");和 auth()->user() 为空



我的中间件没有通过,我的auth((->user((为空,但尝试通过

这是我的模型,我没有使用users表,我使用的是customer而不是那个。此外,我的列名对于密码和电子邮件也有所不同。

<?php
namespace AppUsers;
use IlluminateFoundationAuthUser as Authenticatable;
use IlluminateNotificationsNotifiable;
class Customer extends Authenticatable
{
use Notifiable;
protected $table = 'customer';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'FirstName', 'LastName', 'EmailAddress', 'PasswordSalt', 'DateOfBirth', 'AccountNumber', 'AddressLine1',
'AddressLatitude', 'AddressLongitude', 'AdressLine2', 'City', 'Country', 'What3WordsString', 'PrimaryPhoneNumber',
'AlternatePhoneNumber', 'CompanyName', 'AccountTypeId', 'RouteId', 'IdentificationType', 'CreditLimit', 'IsSuspended',
'SuspensionReason', 'HasInsurance', 'AcceptCompanyCheques', 'IsCreditCardCustomer', 'IsOnlinePurchaseTaxExempted',
'IsEnabled', 'IsApproved', 'NeedsVerification', 'IsAccountFlagged', 'AccountFlaggedReason', 'AccountFlaggedDate',
'FlaggedBy', 'RewardPoints', 'RewardCardNumber', 'CreationSource', 'LastActive', 'LastUpdateSource'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'PasswordSalt',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function getAuthPassword()
{
return $this->PasswordSalt;
}
}

LoginController:这个通行证,但当进入帐户时失败,因为它没有通过中间件。(我知道为什么(

public function checkLogin(LoginRequest $request)
{
$userData = [
'EmailAddress' => $request->get('log'),
'password' => $request->get('pwd'),
];
if(Auth::attempt($userData)) {
return redirect()->action('AccountController@get');
}
return back()->with('error', 'Wrong Login Details');
}

Account Controller:
public function get()
{
$userId = auth()->user()->id;
$account = $this->getAccountQuery($userId);
$accountData = $this->formatAccount($account, $userId);
return  view('account')->with($accountData);
}


Auth.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'customer',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'customer',
],
'api' => [
'driver' => 'token',
'provider' => 'customer',
'hash' => false,
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'customer' => [
'driver' => 'eloquent',
'model' => AppUsersCustomer::class,
],
// 'users' => [
//     'driver' => 'database',
//     'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'customer' => [
'provider' => 'customer',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the amount of seconds before a password confirmation
| times out and the user is prompted to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/
'password_timeout' => 10800,
];

我的路线::

/*|--------------------------------------------------------------------------|Web路由|--------------------------------------------------------------------------||在这里,您可以为您的应用程序注册网络路由。这些|路由由组中的RouteServiceProvider加载|包含"web"中间件组。现在创造一些伟大的东西!|*/

Route::get('/', function () {
return view('index.welcome');
});
Route::get("''", function () {
return view('index.welcome');
});
Route::get('home', function () {
return view('index.welcome');
});
Route::get('home#sc_tab_1', function () {
return view('index.welcome');
});
Route::get('home#user-popUp', function () {
return view('index.welcome');
})->name('login');
Route::post('log', 'AuthLoginController@checkLogin');
Route::get('logOut', 'AuthLoginController@logout')->middleware('auth');
Route::get('home#calculator', function () {
return view('index.welcome');
});
Route::get('contacts', function () {
return view('contacts');
});
Route::get('signUp', function () {
return view('signUp');
});
Route::get('ourServices', function () {
return view('services.ourServices');
});
Route::get('air', function () {
return view('services.air');
});
Route::get('ocean', function () {
return view('services.ocean');
});
Route::get('shopper', function () {
return view('services.shopper');
});
Route::get('delivery', function () {
return view('services.delivery');
});
Route::get('customs', function () {
return view('customs');
});
Route::get('restricted', function () {
return view('restricted');
});
Route::get('insurance', function () {
return view('insurance');
});
Route::get('rates', function () {
return view('rates');
});
Route::get('faqs', function () {
return view('faqs');
});
Route::get('terms', function () {
return view('terms');
});
Route::get('privacy', function () {
return view('privacy');
});
Route::post('register', 'AuthRegisterController@create');
Route::post('newsletter', 'NewsletterController@insert');
Route::get('registerConfirmation', function () {
return view('registerConfirmation');
});
Route::get('account', 'AccountController@get')->middleware('auth');
Route::post('account', 'AccountController@update')->middleware('auth');
Route::post('authUser', 'ContactController@update')->middleware('auth');
Route::get('prealert', function () {
return view('prealert');
})->middleware('auth');
Route::post('prealert','PreAlertPreAlertController@insert')->middleware('auth');
Route::get('packages', 'PackagesPackageController@get')->middleware('auth');
Route::get('invoice', 'InvoicesInvoiceController@get')->middleware('auth');
Route::get('checkOut', function () {
return view('checkout');
})->middleware('auth');
Route::get('checkOut2', function () {
return view('checkout2');
})->middleware('auth');
Route::get('checkOut3', function () {
return view('checkout3');
})->middleware('auth');

用户密码是否存储在名为"PasswordSalt"的db列中?如果不是,是"pwd"吗?

我会看看getAuthPassword((方法。也许当您在Customer模型中重写它时,您无法对用户进行身份验证。

相关内容

  • 没有找到相关文章

最新更新