diff --git a/ZendSkeletonApplication-master/data/schema.sql b/ZendSkeletonApplication-master/data/schema.sql index 69a44194630192dce79d2796c11ad0415b2c7b9d..d95e8201a18abe92f949f97e43c191931db1580b 100644 --- a/ZendSkeletonApplication-master/data/schema.sql +++ b/ZendSkeletonApplication-master/data/schema.sql @@ -9,3 +9,11 @@ CREATE TABLE users ( PRIMARY KEY (id), CONSTRAINT pseudo UNIQUE (pseudo) ) ; + +CREATE TABLE connexions ( + id serial, + pseudo text NOT NULL, + token text NOT NULL, + PRIMARY KEY (id), + CONSTRAINT token UNIQUE (token) +) ; diff --git a/ZendSkeletonApplication-master/module/User/src/Controller/ConnexionController.php b/ZendSkeletonApplication-master/module/User/src/Controller/ConnexionController.php new file mode 100644 index 0000000000000000000000000000000000000000..9cdefc8b3024aa7cc13e5a055d2199d20d3c34d5 --- /dev/null +++ b/ZendSkeletonApplication-master/module/User/src/Controller/ConnexionController.php @@ -0,0 +1,68 @@ +<?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() + { + } + + +} + ?> diff --git a/ZendSkeletonApplication-master/module/User/src/Model/Connexion.php b/ZendSkeletonApplication-master/module/User/src/Model/Connexion.php new file mode 100644 index 0000000000000000000000000000000000000000..ba4266b2b250a03784baa629eaa132c944fd350f --- /dev/null +++ b/ZendSkeletonApplication-master/module/User/src/Model/Connexion.php @@ -0,0 +1,18 @@ +<?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; + + } +} + ?> diff --git a/ZendSkeletonApplication-master/module/User/src/Model/ConnexionTable.php b/ZendSkeletonApplication-master/module/User/src/Model/ConnexionTable.php new file mode 100644 index 0000000000000000000000000000000000000000..a3439d7ff2b173d0118fe6346519bc95836fe5de --- /dev/null +++ b/ZendSkeletonApplication-master/module/User/src/Model/ConnexionTable.php @@ -0,0 +1,66 @@ +<?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]); + } +} + + ?>