add and edit documentation, clean code
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
49cdcb8972
commit
89c3e72c8f
@ -0,0 +1,28 @@
|
||||
@startuml
|
||||
|
||||
class AuthController {
|
||||
+ displayRegister() : HttpResponse
|
||||
+ displayBadFields(viewName : string, fails : array) : HttpResponse
|
||||
+ confirmRegister(request : array) : HttpResponse
|
||||
+ displayLogin() : HttpResponse
|
||||
+ confirmLogin() : HttpResponse
|
||||
}
|
||||
AuthController --> "- model" AuthModel
|
||||
|
||||
class AuthModel {
|
||||
+ register(username : string, password : string, confirmPassword : string, email : string): array
|
||||
+ getAccount(email : string):array
|
||||
+ login(email : string, password : string)
|
||||
}
|
||||
AuthModel --> "- gateway" AuthGateway
|
||||
|
||||
class AuthGateway {
|
||||
-con : Connection
|
||||
|
||||
+ mailExists(email : string) : bool
|
||||
+ insertAccount(username : string, hash : string, email : string)
|
||||
+ getUserHash(email : string):string
|
||||
+ getAccount (email : string): array
|
||||
}
|
||||
|
||||
@enduml
|
@ -1,8 +0,0 @@
|
||||
@startuml
|
||||
|
||||
class FrontController {
|
||||
- router : AltoRouter
|
||||
|
||||
}
|
||||
|
||||
@enduml
|
@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace IQBall\Core\Data;
|
||||
|
||||
use http\Url;
|
||||
|
||||
/**
|
||||
* This class implements the User and
|
||||
*/
|
||||
class AccountUser implements User {
|
||||
private string $name;
|
||||
private Url $profilePicture;
|
||||
private int $age;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param Url $profilePicture
|
||||
* @param int $age
|
||||
*/
|
||||
public function __construct(string $name, Url $profilePicture, int $age) {
|
||||
$this->name = $name;
|
||||
$this->profilePicture = $profilePicture;
|
||||
$this->age = $age;
|
||||
}
|
||||
|
||||
|
||||
public function getName(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getProfilePicture(): Url {
|
||||
return $this->profilePicture;
|
||||
}
|
||||
|
||||
public function getAge(): int {
|
||||
return $this->age;
|
||||
}
|
||||
|
||||
public function setName(string $name): void {
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function setProfilePicture(Url $profilePicture): void {
|
||||
$this->profilePicture = $profilePicture;
|
||||
}
|
||||
|
||||
public function setAge(int $age): void {
|
||||
$this->age = $age;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace IQBall\Core\Data;
|
||||
|
||||
class TeamInfo {
|
||||
private int $id;
|
||||
private string $name;
|
||||
private string $picture;
|
||||
private Color $mainColor;
|
||||
private Color $secondColor;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
* @param string $picture
|
||||
* @param Color $mainColor
|
||||
* @param Color $secondColor
|
||||
*/
|
||||
public function __construct(int $id, string $name, string $picture, Color $mainColor, Color $secondColor) {
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->picture = $picture;
|
||||
$this->mainColor = $mainColor;
|
||||
$this->secondColor = $secondColor;
|
||||
}
|
||||
|
||||
|
||||
public function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getPicture(): string {
|
||||
return $this->picture;
|
||||
}
|
||||
|
||||
public function getMainColor(): Color {
|
||||
return $this->mainColor;
|
||||
}
|
||||
|
||||
public function getSecondColor(): Color {
|
||||
return $this->secondColor;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace IQBall\Core\Data;
|
||||
|
||||
use http\Url;
|
||||
|
||||
/**
|
||||
* Public information about a user
|
||||
*/
|
||||
interface User {
|
||||
/**
|
||||
* @return string the user's name
|
||||
*/
|
||||
public function getName(): string;
|
||||
|
||||
/**
|
||||
* @return Url The user's profile picture image URL
|
||||
*/
|
||||
|
||||
public function getProfilePicture(): Url;
|
||||
|
||||
/**
|
||||
* @return int The user's age
|
||||
*/
|
||||
public function getAge(): int;
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace IQBall\Core\Gateway;
|
||||
|
||||
use IQBall\Core\Connection;
|
||||
use PDO;
|
||||
|
||||
class AuthGateway {
|
||||
private Connection $con;
|
||||
|
||||
/**
|
||||
* @param Connection $con
|
||||
*/
|
||||
public function __construct(Connection $con) {
|
||||
$this->con = $con;
|
||||
}
|
||||
|
||||
|
||||
public function mailExist(string $email): bool {
|
||||
return $this->getUserFields($email) != null;
|
||||
}
|
||||
|
||||
|
||||
public function insertAccount(string $username, string $hash, string $email): void {
|
||||
$this->con->exec("INSERT INTO AccountUser(username, hash, email) VALUES (:username,:hash,:email)", [':username' => [$username, PDO::PARAM_STR],':hash' => [$hash, PDO::PARAM_STR],':email' => [$email, PDO::PARAM_STR]]);
|
||||
}
|
||||
|
||||
public function getUserHash(string $email): string {
|
||||
$results = $this->con->fetch("SELECT hash FROM AccountUser WHERE email = :email", [':email' => [$email, PDO::PARAM_STR]]);
|
||||
return $results[0]['hash'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return array<string,string>|null
|
||||
*/
|
||||
public function getUserFields(string $email): ?array {
|
||||
$results = $this->con->fetch("SELECT username,email FROM AccountUser WHERE email = :email", [':email' => [$email, PDO::PARAM_STR]]);
|
||||
$firstRow = $results[0] ?? null;
|
||||
return $firstRow;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace IQBall\Core\Gateway;
|
||||
|
||||
use IQBall\Core\Connection;
|
||||
use IQBall\Core\Data\Member;
|
||||
use IQBall\Core\Data\MemberRole;
|
||||
use PDO;
|
||||
|
||||
class MemberGateway {
|
||||
private Connection $con;
|
||||
|
||||
/**
|
||||
* @param Connection $con
|
||||
*/
|
||||
public function __construct(Connection $con) {
|
||||
$this->con = $con;
|
||||
}
|
||||
|
||||
/**
|
||||
* insert member to a team
|
||||
* @param int $idTeam
|
||||
* @param int $userId
|
||||
* @param string $role
|
||||
* @return void
|
||||
*/
|
||||
public function insert(int $idTeam, int $userId, string $role): void {
|
||||
$this->con->exec(
|
||||
"INSERT INTO Member(id_team, id_user, role) VALUES (:id_team, :id_user, :role)",
|
||||
[
|
||||
":id_team" => [$idTeam, PDO::PARAM_INT],
|
||||
":id_user" => [$userId, PDO::PARAM_INT],
|
||||
":role" => [$role, PDO::PARAM_STR],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $teamId
|
||||
* @return Member[]
|
||||
*/
|
||||
public function getMembersOfTeam(int $teamId): array {
|
||||
$rows = $this->con->fetch(
|
||||
"SELECT a.id,m.role,a.email,a.username FROM Account a,Team t,Member m WHERE t.id = :id AND m.id_team = t.id AND m.id_user = a.id",
|
||||
[
|
||||
":id" => [$teamId, PDO::PARAM_INT],
|
||||
]
|
||||
);
|
||||
|
||||
return array_map(fn($row) => new Member($row['id_user'], $row['id_team'], MemberRole::fromName($row['role'])), $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* remove member from given team
|
||||
* @param int $idTeam
|
||||
* @param int $idMember
|
||||
* @return void
|
||||
*/
|
||||
public function remove(int $idTeam, int $idMember): void {
|
||||
$this->con->exec(
|
||||
"DELETE FROM Member WHERE id_team = :id_team AND id_user = :id_user",
|
||||
[
|
||||
":id_team" => [$idTeam, PDO::PARAM_INT],
|
||||
":id_user" => [$idMember, PDO::PARAM_INT],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue