register finish + login to do
continuous-integration/drone/push Build is passing Details

pull/12/head
samuel 1 year ago
parent b967e9615f
commit 7b65a4bd23

@ -39,8 +39,8 @@ class AuthController {
if (!empty($fails)) {
$bad_fields = [];
foreach ($fails as $err){
if ($err instanceof FieldValidationFail){
foreach ($fails as $err) {
if ($err instanceof FieldValidationFail) {
$bad_fields[] = $err->getFieldName();
}
}
@ -50,12 +50,12 @@ class AuthController {
$fails = $this->model->validationRegister($request['username'], $request["password"], $request['confirmpassword'], $request['email']);
if (empty($fails)) {
$results = $this->model->getUserFields($request['email']);
return ViewHttpResponse::twig("display_register_confirm.html.twig", ['results' => $results]);
return ViewHttpResponse::twig("display_register_confirm.html.twig", ['username' => $results['username'], 'email' => $results['email']]);
}
$bad_fields = [];
foreach ($fails as $err){
if ($err instanceof FieldValidationFail){
foreach ($fails as $err) {
if ($err instanceof FieldValidationFail) {
$bad_fields[] = $err->getFieldName();
}
}

@ -15,14 +15,24 @@ class AuthGateway {
$this->con = $con;
}
public function insertAccount(string $username, string $hash, string $email) {
public function mailExist(string $email):bool{
return $this->getUserFields($email) != null;
}
public function insertAccount(string $username, string $hash, string $email) {
$this->con->exec("INSERT INTO AccountUser VALUES (:username,:hash,:email)", [':username' => [$username, PDO::PARAM_STR],':hash'=> [$hash, PDO::PARAM_STR],':email'=>[$email, PDO::PARAM_STR]]);
}
public function getUserFields (string $email):array{
return $this->con->fetch ("SELECT username,email FROM AccountUser WHERE email = :email",[':email'=>[$email, PDO::PARAM_STR]]);
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;
}
}

@ -24,7 +24,11 @@ class AuthModel {
$errors[] = new FieldValidationFail("confirmpassword","passwords not equals");
}
else{
if ($this->gateway->mailExist($email)){
$errors[] = new FieldValidationFail("email","email already exist");
}
if(empty($errors)){
$hash = password_hash($password,PASSWORD_DEFAULT);
$this->gateway->insertAccount($username,$hash,$email);
}

@ -8,10 +8,10 @@
<center><h1>Nouveau Compte</h1></center>
{% for row in results %}
<h2>Votre pseudo : {{ row['username']}}</h2>
<h2>Votre Email : {{ row['email']}}</h2>
{% endfor %}
<h2>Votre pseudo : {{ username }}</h2>
<h2>Votre Email : {{ email }}</h2>
</body>
</html>
Loading…
Cancel
Save