Skip to content

Instantly share code, notes, and snippets.

@NandoKstroNet
Created July 18, 2024 05:12
Show Gist options
  • Save NandoKstroNet/c276d1edcd71fefeb9bb4ca2e9349e35 to your computer and use it in GitHub Desktop.
Save NandoKstroNet/c276d1edcd71fefeb9bb4ca2e9349e35 to your computer and use it in GitHub Desktop.
Conteúdos apoio curso API REST com PHP & VueJS / https://codeexperts.com.br
<?php
Router::post('cadastro', '\Code\App\Controller\AuthController@cadastro');
Router::post('login', '\Code\App\Controller\AuthController@login');
<?php
namespace Code\App\Repository;
use Code\App\Model\Usuario;
use Code\App\Model\UsuarioPerfil;
use Code\Framework\Database\Model\Model;
use Code\Framework\Database\Repository\RepositoryInterface;
class UsuarioRepository implements RepositoryInterface
{
public function getModel(): Model
{
return new Usuario();
}
public function buscarUsuarioPeloEmail(string $email)
{
return $this->getModel()->query()->select(['email' => $email], linha: true);
}
public function cadastrarUsuario(array $data, UsuarioPerfil $perfil)
{
$usuario = $this->getModel();
$usuario->nome = $data['nome'];
$usuario->sobrenome = $data['sobrenome'];
$usuario->email = $data['email'];
$usuario->senha = password_hash($data['senha'], PASSWORD_DEFAULT);
$usuario->salvar();
$perfil->usuario_id = $usuario->id;
$perfil->telefone = $data['telefone'];
$perfil->celular = $data['celular'];
$perfil->salvar();
return $usuario;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment