Auth :: попытка передачи, но сбой промежуточного программного обеспечения ('auth'); и auth () -> user () - ноль - PullRequest
0 голосов
/ 01 апреля 2020

Мое промежуточное программное обеспечение не проходит, и мой auth () -> user () имеет значение NULL, но попытка передачи

Это моя модель, я не использую таблицу пользователей, вместо нее я использую customer , Кроме того, имена моих столбцов различаются для пароля и для электронной почты.

<?php

namespace App\Users;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

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' => App\Users\Customer::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,

];

Мои маршруты ::

/ * | --------------------- -------------------------------------------------- --- | Веб-маршруты | ----------------------------------------------- --------------------------- | | Здесь вы можете зарегистрировать веб-маршруты для вашего приложения. Эти | маршруты загружаются 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', 'Auth\LoginController@checkLogin');
Route::get('logOut', 'Auth\LoginController@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', 'Auth\RegisterController@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','PreAlert\PreAlertController@insert')->middleware('auth');
Route::get('packages', 'Packages\PackageController@get')->middleware('auth');
Route::get('invoice', 'Invoices\InvoiceController@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');

1 Ответ

0 голосов
/ 01 апреля 2020

Пароль пользователя хранится в столбце БД с именем "PasswordSalt"? Если нет, это "pwd"?

Я бы взглянул на метод getAuthPassword (). Возможно, когда вы переопределяете это в модели Customer, вы не можете аутентифицировать пользователя.

...