feat: implement JWT-based authentication system with repository, service, and middleware layers
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace WorkbloomERP\Module\Auth\DTO;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class LoginDTO {
|
||||
public function __construct(
|
||||
public readonly string $login,
|
||||
public readonly string $senha
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Instancia e valida a partir dos dados da requisição.
|
||||
*
|
||||
* @param array $data
|
||||
* @return self
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public static function fromArray(array $data): self {
|
||||
$login = trim((string)($data['login'] ?? $data['email'] ?? $data['nome_usuario'] ?? ''));
|
||||
$senha = (string)($data['senha'] ?? $data['password'] ?? '');
|
||||
|
||||
$errors = [];
|
||||
|
||||
if ($login === '') {
|
||||
$errors['login'] = 'O campo login (e-mail ou nome de usuário) é obrigatório.';
|
||||
}
|
||||
|
||||
if ($senha === '') {
|
||||
$errors['senha'] = 'O campo senha é obrigatório.';
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
throw new InvalidArgumentException(json_encode($errors, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
return new self(
|
||||
login: $login,
|
||||
senha: $senha
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user