-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create mvc files for register feature
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
//Controllers handle the logic of the application | ||
|
||
declare(strict_types=1); | ||
|
||
function is_input_empty(string $fullname, string $email, string $username, string $password){ | ||
if(empty ($fullname) || empty ($email) || empty ($username) || empty ($password)){ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function is_email_invalid(string $email){ | ||
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function is_username_taken(object $pdo, string $username){ | ||
if(get_username($pdo, $username)){ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function is_email_registered(object $pdo, string $email){ | ||
if(get_email($pdo, $email)){ | ||
return true; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
// Models actually interact with the database | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
function get_username(object $pdo, string $username){ | ||
$query = "SELECT username FROM users WHERE username = :username"; // :username is a named placeholder | ||
$stmt = $pdo->prepare($query); // prepare the query | ||
$stmt->bindParam(":username", $username, PDO::PARAM_STR); // bind the $username variable to the :username placeholder | ||
$stmt->execute(); // execute the query | ||
|
||
$result = $stmt->fetch(PDO::FETCH_ASSOC); //fetch the result from the query | ||
return $result; | ||
} | ||
|
||
function get_email(object $pdo, string $email){ | ||
$query = "SELECT email FROM users WHERE email = :email"; // :email is a named placeholder | ||
$stmt = $pdo->prepare($query); // prepare the query | ||
$stmt->bindParam(":email", $email, PDO::PARAM_STR); // bind the $email variable to the :email placeholder | ||
$stmt->execute(); // execute the query | ||
|
||
$result = $stmt->fetch(PDO::FETCH_ASSOC); //fetch the result from the query | ||
return $result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
//Views are responsible for displaying the data to the user | ||
|
||
declare(strict_types=1); | ||
|
||
function check_and_print_register_errors(){ | ||
if(isset($_SESSION["errors_register"])){ | ||
$errors = $_SESSION["errors_register"]; | ||
if(count($errors) > 0){ | ||
echo "<section class='error'>"; | ||
echo "<h1 class='error__title'>Errors occurred while registering: </h1>"; | ||
foreach($errors as $error){ | ||
echo "<p class='error__item'>$error</p>"; | ||
} | ||
echo "</section>"; | ||
unset($_SESSION["errors_register"]); | ||
} | ||
|
||
} | ||
} |