Skip to content
Extraits de code Groupes Projets
Valider f4f3d9d9 rédigé par Charles OLYMPIO's avatar Charles OLYMPIO
Parcourir les fichiers

Ajout des connexions au module User

parent bff12540
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -9,3 +9,11 @@ CREATE TABLE users ( ...@@ -9,3 +9,11 @@ CREATE TABLE users (
PRIMARY KEY (id), PRIMARY KEY (id),
CONSTRAINT pseudo UNIQUE (pseudo) CONSTRAINT pseudo UNIQUE (pseudo)
) ; ) ;
CREATE TABLE connexions (
id serial,
pseudo text NOT NULL,
token text NOT NULL,
PRIMARY KEY (id),
CONSTRAINT token UNIQUE (token)
) ;
<?php
namespace User\Controller;
use User\Model\UserTable;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class UserController extends AbstractActionController
{
// Add this property:
private $table;
// Add this constructor:
public function __construct(ConnexionTable $table)
{
$this->table = $table;
}
public function indexAction()
{
return new ViewModel([
'users' => $this->table->fetchAll(),
]);
}
public function registerAction()
{
}
public function connectAction()
{
}
public function getUserAction()
{
}
public function getUserByNameAction()
{
}
public function getUserByPseusoAction()
{
}
public function getRoleAction()
{
}
public function disconnectAction()
{
}
public function editAction()
{
}
public function deleteAction()
{
}
public function HashPassword()
{
}
}
?>
<?php
namespace User\Model;
class Connexion
{
public $id;
public $pseudo;
public $token;
public function exchangeArray(array $data)
{
$this->id = !empty($data['id']) ? $data['id'] : null;
$this->pseudo = !empty($data['pseudo']) ? $data['pseudo'] : null;
$this->token = !empty($data['token']) ? $data['token'] : null;
}
}
?>
<?php
namespace Connexion\Model;
use RuntimeException;
use Zend\Db\TableGateway\TableGatewayInterface;
class ConnexionTable
{
private $tableGateway;
public function __construct(TableGatewayInterface $tableGateway)
{
$this->tableGateway = $tableGateway;
}
public function fetchAll()
{
return $this->tableGateway->select();
}
public function getConnexion($id)
{
$id = (int) $id;
$rowset = $this->tableGateway->select(['id' => $id]);
$row = $rowset->current();
if (! $row) {
throw new RuntimeException(sprintf(
'Could not find row with identifier %d',
$id
));
}
return $row;
}
public function saveConnexion(Connexion $Connexion)
{
$data = [
'pseudo' => $Connexion->pseudo,
'token' => $Connexion->token,
];
$id = (int) $Connexion->id;
if ($id === 0) {
$this->tableGateway->insert($data);
return;
}
if (! $this->getConnexion($id)) {
throw new RuntimeException(sprintf(
'Cannot update Connexion with identifier %d; does not exist',
$id
));
}
$this->tableGateway->update($data, ['id' => $id]);
}
public function deleteConnexion($id)
{
$this->tableGateway->delete(['id' => (int) $id]);
}
}
?>
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter