我正在为具有自定义电子邮件和密码列的用户使用具有自定义表的自定义防护。 我可以使用我的自定义电子邮件列,但密码错误。似乎我无法覆盖getAuthPassword()并获取:
未定义索引:密码。 供应商/laravel/framework/src/Illuminate/Auth/GenericUser.php:54
知道我错过了什么吗?我一直在搜索并尝试了几个小时,但被卡住了。 谢谢
我的auth.php:
return [ 'defaults' => [ 'guard' => 'ceusuario', 'passwords' => 'ceusuarios', ], 'guards' => [ 'ceusuario' => [ 'driver' => 'session', 'provider' => 'ceusuarios', ], ], 'providers' => [ 'ceusuarios' => [ 'driver' => 'database', 'table' => 'Empresas_Usuarios', 'model' => App\CEUsuario::class, ], ], 'passwords' => [ 'ceusuarios' => [ 'provider' => 'ceusuarios', 'table' => 'password_resets', 'expire' => 60, 'throttle' => 60, ], ], ]
我的模型CEUsuario.php
namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class CEUsuario extends Authenticatable { use Notifiable; const CREATED_AT = 'FechaAlta'; const UPDATED_AT = 'FechaModificado'; protected $table = 'Empresas_Usuarios'; protected $guard = 'ceusuario'; protected $fillable = [ 'EmailUsario', 'Password', 'IdTipoUsuario', 'CodigoUsuario', 'Nombre', 'Apellido1', 'Apellido2', 'NIF', 'IdCargoEmpresa', 'TelefonoUsuario', 'EstadoUsuario', ]; protected $hidden = [ 'Password', 'remember_token', ]; public function getReminderEmail() { return $this->EmailUsuario; } public function getAuthPassword(){ return $this->Password; } }
我的控制器CEUsuariosController.php
namespace App\Http\Controllers\Auth; use Auth; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Http\Controllers\Auth\LoginController as DefaultLoginController; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; class CEUsuariosController extends DefaultLoginController { protected $redirectTo = '/home'; public function __construct() { $this->middleware('guest:ceusuario')->except('logout'); } public function showLoginForm() { return view('auth.login'); } public function login(Request $request) { $this->validator($request); //dd(Hash::make($request->input('password'))); $attributes = [ 'EmailUsuario' => request('ceemail'), 'password' => request('password') ]; $authLogin = $this->guard()->attempt($attributes, $request->filled('remember')); dd($authLogin); if($authLogin){ //Authentication passed... return redirect() ->intended(route('home')) ->with('status','You are Logged in as Admin!'); } //Authentication failed... return $this->loginFailed(); } public function username() { return 'EmailUsuario'; } public function loginUsername() { return 'EmailUsuario'; } protected function guard() { return Auth::guard('ceusuario'); } private function loginFailed(){ return redirect() ->back() ->withInput() ->with('error','Error en el login, por favor intentelo otra vez.'); } private function validator(Request $request) { //validation rules. $rules = [ 'ceemail' => 'required|email|exists:Empresas_Usuarios,EmailUsuario|min:5|max:191', 'cepassword' => 'required|string|min:6|max:255' ]; //validate the request. $validator = Validator::make($request->all(), $rules); //custom validation error messages. $messages = [ 'email.exists' => 'Alguno de los datos enviados no son correctos.', ]; // check if the validator failed ----------------------- if ($validator->fails()) { // get the error messages from the validator return redirect() ->back() ->withInput() ->with('error','The inputs are not correct.'); } else { // validation successful --------------------------- } } }
我的路由器web.php
Route::namespace('Auth')->group(function(){ //Auth::routes(); Route::get('/login','CEUsuariosController@showLoginForm')->name('login'); Route::post('/login','CEUsuariosController@login'); Route::post('/logout','CEUsuariosController@logout')->name('logout'); Route::get('/home', 'HomeController@index')->name('home'); });
我的桌子Empresas_Usuarios
带有列: