0
Good night.
I’m doing a job for college that involves logging in..
I’m using the post to pull the requisitions and is giving me the following error:
<br />
<b>Notice</b>: Trying to get property 'senha' of non-object in
<b>C:\wamp64\www\programacao-internet-2\biblioteca_\UsuarioController.php</b> on line <b>28</b><br />
Post type, the url: localhost:8080/api/login and in the body:
{
"email":"[email protected]",
"senha": 5667
}
My Usuariocontroller.php file looks like this:
public function autenticar($request, $response, $args){
$body = $request->getParsedBody();
$dao = new UsuarioDAO;
$usuario = $dao->buscarPorEmail($body['email']);
if($usuario->senha == $body['senha']){
$token = array(
'user' => strval($usuario->id),
'nome' => $usuario->nome
);
$jwt = JWT::encode($token, $this->key);
return $response->withJson(['token' =>$jwt, 201])
->withHeader('Content-Type', 'application/json');
}else{
return $response->withStatus(401);
}
}
Can someone help me? Thanks in advance!
This error means that you are trying to access an attribute of a variable that is not an object. From the looks of it, the error is in the "searchPorEmail()" function, because that’s where you’re trying to extract attributes from an object.
– andre_luiss
Hello Thaty, your question lacks details, it is important you [Dit] your question and explain objectively and punctually the difficulty found, accompanied by a [mcve] problem and attempt to solution. To better enjoy the site, understand and avoid closures and negativities worth reading the Stack Overflow Survival Guide in English. That way we can help you.
– Guilherme Nascimento