when logging in, query fails, because "email" not on "usuario", it's in "persona"
unknown column 'email' in 'where clause' (sql: select * `usuario` `email` = admin@localhost limit 1)
it's not solution change database model, not "persona" "usuario", "usuario" "persona".
tried set relationships:
class persona extends model implements authenticatablecontract, authorizablecontract, canresetpasswordcontract {....} public function usuario() { return $this->hasone('app\usuario'); } //----------------------------------------------------// class usuario extends model implements authenticatablecontract, authorizablecontract, canresetpasswordcontract { {....} public function persona() { return $this->hasone('app\persona'); }
both tables have same key.
but query doesn't change, though maybe laravel make "inner join" somewhere, don't know if laravel can automatically, tried change query don't know located.
i thought in solution this, looks easy, don't know if way =/
- get email , passwd post
- get id, email , passwd bd sql
- if [email , passwd match] auth::loginusingid(id); [else] return errors.
as far know, auth::loginusingid(id); acts successful auth::attempt()... solution i'll need know how implement later throttles , "remember" option separately... thoughts welcome :d
i found solution: changed postlogin() inside authcontroller, can preserve throttles , remember features, , core still unchanged, here's code if can others:
//------------------------------------ // auth\authcontroller.php //------------------------------------ protected function postlogin(request $request) { $this->validate($request, [ $this->loginusername() => 'required', 'password' => 'required', ]); // if class using throttleslogins trait, can automatically throttle // login attempts application. we'll key username , // ip address of client making these requests application. $throttles = $this->isusingthrottlesloginstrait(); if ($throttles && $this->hastoomanyloginattempts($request)) { return $this->sendlockoutresponse($request); } $credentials = $this->getcredentials($request); //here's custom sql, can retrieve "user" , "pass" anywhere in db $usuario = \db::select(' select persona.nombre, usuario.password persona inner join usuario on persona.id_persona = usuario.id_persona persona.email = ? limit 1', array($credentials['email'])); // instead of: // if (auth::attempt($credentials, $request->has('remember'))) { if ($usuario && hash::check($credentials['password'], $usuario[0]->password)) { auth::loginusingid($usuario[0]->id_persona, $request->has('remember')); // put custom data need user/session session::put('nombre', $usuario[0]->nombre); return $this->handleuserwasauthenticated($request, $throttles); } // if login attempt unsuccessful increment number of attempts // login , redirect user login form. of course, when // user surpasses maximum number of attempts locked out. if ($throttles) { $this->incrementloginattempts($request); } return redirect($this->loginpath()) ->withinput($request->only($this->loginusername(), 'remember')) ->witherrors([ $this->loginusername() => $this->getfailedloginmessage(), ]); }
Comments
Post a Comment