forked from tom.biard/ScienceQuest
Compare commits
9 Commits
Author | SHA1 | Date |
---|---|---|
|
071dfee14b | 8 months ago |
|
01b52cd301 | 8 months ago |
|
0877094043 | 8 months ago |
|
1b1410fffd | 8 months ago |
|
7664afc138 | 9 months ago |
|
e792740e4e | 9 months ago |
|
6fdc58151d | 9 months ago |
|
ddf5ee0a43 | 9 months ago |
|
3c94c2dde4 | 9 months ago |
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/Neutral.iml" filepath="$PROJECT_DIR$/.idea/Neutral.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,26 @@
|
||||
PHP SAE
|
||||
|
||||
|
||||
Actions disponibles pour admin :
|
||||
- connexion
|
||||
- déconnexion
|
||||
- gestion scientifique
|
||||
- accéder stats site
|
||||
|
||||
Actions users :
|
||||
- créer partie
|
||||
- rejoindre partie
|
||||
- historique scientifiques trouvés
|
||||
|
||||
|
||||
Vues nécessaires :
|
||||
- Accueil
|
||||
- création partie
|
||||
- rejoindre partie
|
||||
- la partie (dépend des jeux)
|
||||
- historique des scientifiques trouvés
|
||||
|
||||
Pour admin
|
||||
- connexion (pop-up si possible)
|
||||
- Gestion des scientifiques (genre une liste et on peut les supprimer)
|
||||
- ajouter scientifique
|
@ -0,0 +1 @@
|
||||
<?php
|
@ -0,0 +1,35 @@
|
||||
<html>
|
||||
|
||||
<body>
|
||||
test
|
||||
|
||||
<?php
|
||||
use model\Connection;
|
||||
|
||||
require_once("Connection.php");
|
||||
|
||||
//A CHANGER
|
||||
$user= 'sasa';
|
||||
$pass='sasa';
|
||||
$dsn='mysql:host=localhost;dbname=siteperso';
|
||||
try{
|
||||
$con=new Connection($dsn,$user,$pass);
|
||||
|
||||
$query = "SELECT * FROM categorie WHERE id=:id";
|
||||
|
||||
|
||||
echo $con->executeQuery($query, array(':id' => array(1, PDO::PARAM_INT) ) );
|
||||
|
||||
$results=$con->getResults();
|
||||
Foreach ($results as $row)
|
||||
print $row['titre'];
|
||||
|
||||
|
||||
}
|
||||
catch( PDOException $Exception ) {
|
||||
echo 'erreur';
|
||||
echo $Exception->getMessage();}
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace model;
|
||||
|
||||
class AdminGateway
|
||||
{
|
||||
private \PDO $con;
|
||||
|
||||
public function __construct(\PDO $con)
|
||||
{
|
||||
$this->con=$con;
|
||||
}
|
||||
|
||||
public function login(string $username, string $password): bool
|
||||
{
|
||||
$sql = "SELECT * FROM admin WHERE username=:username";
|
||||
$stmt = $this->con->prepare($sql);
|
||||
$stmt->bindValue(':username', $username);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetch();
|
||||
if ($result && password_verify($password, $result['password'])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function getHashedPassword(string $username): string
|
||||
{
|
||||
$sql = "SELECT password FROM user WHERE username=:username";
|
||||
$stmt = $this->con->prepare($sql);
|
||||
$stmt->bindValue(':username', $username);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetch();
|
||||
return $result['password'];
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace model;
|
||||
|
||||
use PDO;
|
||||
|
||||
class Connection extends PDO {
|
||||
|
||||
private $stmt;
|
||||
|
||||
public function __construct(string $dsn, string $username, string $password) {
|
||||
|
||||
parent::__construct($dsn,$username,$password);
|
||||
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
}
|
||||
|
||||
|
||||
/** * @param string $query
|
||||
* @param array $parameters *
|
||||
* @return bool Returns `true` on success, `false` otherwise
|
||||
*/
|
||||
|
||||
public function executeQuery(string $query, array $parameters = []) : bool{
|
||||
$this->stmt = parent::prepare($query);
|
||||
foreach ($parameters as $name => $value) {
|
||||
$this->stmt->bindValue($name, $value[0], $value[1]);
|
||||
}
|
||||
|
||||
return $this->stmt->execute();
|
||||
}
|
||||
|
||||
public function getResults() : array {
|
||||
return $this->stmt->fetchall();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace model;
|
||||
|
||||
class ScientistGateway
|
||||
{
|
||||
private $con;
|
||||
|
||||
function __construct(Connection $co) {
|
||||
$this->con = $co;
|
||||
}
|
||||
|
||||
// function findByName(string $name) :? Scientist {
|
||||
// $usr = null;
|
||||
// }
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace model;
|
||||
|
||||
class UserGateway
|
||||
{
|
||||
private \PDO $con;
|
||||
private \PDOStatement $stmt;
|
||||
public function __construct(\PDO $con, \PDOStatement $stmt)
|
||||
{
|
||||
$this->con=$con;
|
||||
$this->stmt=$stmt;
|
||||
}
|
||||
|
||||
public function login(string $username, string $password): bool
|
||||
{
|
||||
$sql = "SELECT * FROM user WHERE username=:username";
|
||||
$stmt = $this->con->prepare($sql);
|
||||
$stmt->bindValue(':username', $username);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetch();
|
||||
if ($result && password_verify($password, $result['password'])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function addUser(string $username, string $password): void
|
||||
{
|
||||
$sql = "INSERT INTO user (username, password) VALUES (:username, :password)";
|
||||
$stmt = $this->con->prepare($sql);
|
||||
$stmt->bindValue(':username', $username);
|
||||
$stmt->bindValue(':password', $password);
|
||||
$stmt->execute();
|
||||
}
|
||||
public function deleteUser(int $id): void
|
||||
{
|
||||
$sql = "DELETE FROM user WHERE id=:id";
|
||||
$stmt = $this->con->prepare($sql);
|
||||
$stmt->bindValue(':id', $id);
|
||||
$stmt->execute();
|
||||
}
|
||||
public function updateUser(int $id, string $username, string $password): void
|
||||
{
|
||||
$sql = "UPDATE user SET username=:username, password=:password WHERE id=:id";
|
||||
$stmt = $this->con->prepare($sql);
|
||||
$stmt->bindValue(':id', $id);
|
||||
$stmt->bindValue(':username', $username);
|
||||
$stmt->bindValue(':password', $password);
|
||||
$stmt->execute();
|
||||
}
|
||||
public function getUser(int $id): User
|
||||
{
|
||||
$sql = "SELECT * FROM user WHERE id=:id";
|
||||
$stmt = $this->con->prepare($sql);
|
||||
$stmt->bindValue(':id', $id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetch();
|
||||
return new User($result['id'], $result['username'], $result['password']);
|
||||
}
|
||||
public function getUsers(): array
|
||||
{
|
||||
$sql = "SELECT * FROM user";
|
||||
$stmt = $this->con->prepare($sql);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetchAll();
|
||||
$users = [];
|
||||
foreach ($result as $user) {
|
||||
$users[] = new User($user['id'], $user['username'], $user['password']);
|
||||
}
|
||||
return $users;
|
||||
}
|
||||
public function getHashedPasswordById(int $id): string
|
||||
{
|
||||
$sql = "SELECT password FROM user WHERE id=:id";
|
||||
$stmt = $this->con->prepare($sql);
|
||||
$stmt->bindValue(':id', $id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetch();
|
||||
return $result['password'];
|
||||
}
|
||||
public function getUserId(string $username): int
|
||||
{
|
||||
$sql = "SELECT id FROM user WHERE username=:username";
|
||||
$stmt = $this->con->prepare($sql);
|
||||
$stmt->bindValue(':username', $username);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetch();
|
||||
return $result['id'];
|
||||
}
|
||||
public function getUserByUsernameAndPassword(string $username, string $password): User
|
||||
{
|
||||
$sql = "SELECT * FROM user WHERE username=:username AND password=:password";
|
||||
$stmt = $this->con->prepare($sql);
|
||||
$stmt->bindValue(':username', $username);
|
||||
$stmt->bindValue(':password', $password);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetch();
|
||||
return new User($result['id'], $result['username'], $result['password']);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace model;
|
||||
|
||||
class Admin extends User
|
||||
{
|
||||
private string $email;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param string $email
|
||||
*/
|
||||
public function __construct(int $id, string $username, string $password, string $email)
|
||||
{
|
||||
parent::__construct($id, $username, $password);
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail(): string
|
||||
{
|
||||
return parent::getUsername();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*/
|
||||
public function setEmail(string $email): void
|
||||
{
|
||||
parent::setUsername($email);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace model;
|
||||
|
||||
enum Difficulty
|
||||
{
|
||||
case Easy;
|
||||
case Medium;
|
||||
case Hard;
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace model;
|
||||
|
||||
class Scientist
|
||||
{
|
||||
private int $id;
|
||||
private string $name;
|
||||
private string $firstName;
|
||||
private string $photo;
|
||||
private string $description;
|
||||
private Theme $theme;
|
||||
private Difficulty $difficulty;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
* @param string $firstName
|
||||
* @param string $photo
|
||||
* @param string $description
|
||||
* @param Theme $theme
|
||||
* @param Difficulty $difficulty
|
||||
*/
|
||||
public function __construct(int $id, string $name, string $firstName, string $photo, string $description, Theme $theme, Difficulty $difficulty)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->firstName = $firstName;
|
||||
$this->photo = $photo;
|
||||
$this->description = $description;
|
||||
$this->theme = $theme;
|
||||
$this->difficulty = $difficulty;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstName(): string
|
||||
{
|
||||
return $this->firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $firstName
|
||||
*/
|
||||
public function setFirstName(string $firstName): void
|
||||
{
|
||||
$this->firstName = $firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPhoto(): string
|
||||
{
|
||||
return $this->photo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $photo
|
||||
*/
|
||||
public function setPhoto(string $photo): void
|
||||
{
|
||||
$this->photo = $photo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
*/
|
||||
public function setDescription(string $description): void
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Theme
|
||||
*/
|
||||
public function getTheme(): Theme
|
||||
{
|
||||
return $this->theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Theme $theme
|
||||
*/
|
||||
public function setTheme(Theme $theme): void
|
||||
{
|
||||
$this->theme = $theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Difficulty
|
||||
*/
|
||||
public function getDifficulty(): Difficulty
|
||||
{
|
||||
return $this->difficulty;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Difficulty $difficulty
|
||||
*/
|
||||
public function setDifficulty(Difficulty $difficulty): void
|
||||
{
|
||||
$this->difficulty = $difficulty;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace model;
|
||||
|
||||
enum Theme
|
||||
{
|
||||
case Maths;
|
||||
case Physics;
|
||||
case Chemistry;
|
||||
case Biology;
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace model;
|
||||
|
||||
class User
|
||||
{
|
||||
private int $id;
|
||||
private string $username;
|
||||
private string $password;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
*/
|
||||
|
||||
public function __construct(int $id, string $username, string $password)
|
||||
{
|
||||
$this->id=$id;
|
||||
$this->username=$username;
|
||||
$this->password=$password;
|
||||
}
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
public function getUsername(): string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
public function setUsername(string $username): void
|
||||
{
|
||||
$this->username=$username;
|
||||
}
|
||||
public function setPassword(string $password): void
|
||||
{
|
||||
$this->password=$password;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue