Created
January 22, 2020 15:22
-
-
Save robsonsuzin/edb8147198f0dfb6c48c0a64eb188dd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* list user data | |
*/ | |
public function login(array $data): void | |
{ | |
$data = json_decode($data['data'], true); | |
$this->email = $data['email']; | |
$request = $this->requestLimit("authLogin", 5, 60); | |
if (!$request) { | |
return; | |
} | |
$data = filter_var_array($data, FILTER_SANITIZE_STRIPPED); | |
if (!is_email($data['email'])) { | |
$this->call( | |
400, | |
"invalid_data", | |
"O e-mail informado não é válido" | |
)->back(); | |
return; | |
} | |
if (!is_passwd($data['password'])) { | |
$this->call( | |
400, | |
"invalid_data", | |
"A senha informada não é válida" | |
)->back(); | |
return; | |
} | |
$user = (new User())->findByEmail($data['email']); | |
if (!$user) { | |
$this->call( | |
400, | |
"invalid_data", | |
"O e-mail informado não está cadastrado" | |
)->back(); | |
return; | |
} | |
if (!passwd_verify($data['password'], $user->password)) { | |
$this->call( | |
400, | |
"invalid_data", | |
"A senha informada não confere" | |
)->back(); | |
return; | |
} | |
unset($user->data()->password, $user->data()->forget); | |
// Setar Caminho absoluto da imagem | |
$user->photo = $user->photo(); | |
if($user->data()->genre == 'male') $user->data()->genre = 'Masculino'; | |
if($user->data()->genre == 'female') $user->data()->genre = 'Feminino'; | |
$token = array( | |
"sub" => $user->data()->id, // Entidade à quem o token pertence, normalmente o ID do usuário | |
"iss" => CONF_URL_TEST, // Emissor do Token | |
"aud" => CONF_URL_TEST, // Destinatário do token, representa a aplicação que irá usá-lo | |
"iat" => (new \DateTime())->getTimestamp(), // Timestamp de quando o token foi criado | |
"exp" => (new \DateTime())->getTimestamp() + 3600, | |
"dados" => [ | |
'name' => $user->fullName(), | |
'email' => $user->data()->email | |
] | |
); | |
$jwt = JWT::encode($token, $this->key); | |
// $decoded = JWT::decode($jwt, $key, array('HS256')); // Decodificar o Token | |
$response["token"] = $jwt; | |
$user->data()->created_at = date_fmt_br($user->data()->created_at); | |
$response['user'] = $user->data(); | |
$response['company'] = $user->company()->data(); | |
$response['companyaddress'] = $user->company()->getAddress(); | |
$this->back($response); | |
return; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment