Skip to content
Snippets Groups Projects
Commit 70ba879e authored by Iqbal's avatar Iqbal
Browse files

Added email and username validation functionality.

parent 95c871a0
Branches
No related merge requests found
<?php
/**
* Created by PhpStorm.
* User: iqbal
* Date: 05/10/17
* Time: 23:14
*/
include_once "../controller/Controller.php";
include_once "../model/User.php";
$emailInput = $_REQUEST['q'];
$pdo = DB::getInstance();
if ($emailInput !== "") {
if (filter_var($emailInput, FILTER_VALIDATE_EMAIL)) {
if (User::GetUserBy("email", $emailInput, $pdo)) {
echo "unavailable";
} else {
echo "available";
}
} else {
echo "unavailable";
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: iqbal
* Date: 05/10/17
* Time: 23:12
*/
include_once "../controller/Controller.php";
include_once "../model/User.php";
$usernameInput = $_REQUEST['q'];
$pdo = DB::getInstance();
if ($usernameInput !== "") {
if (User::GetUserBy("username", $usernameInput, $pdo)) {
echo "unavailable";
} else {
echo "available";
}
}
\ No newline at end of file
......@@ -36,7 +36,7 @@
Username:
</td>
<td>
<input onkeyup="checkAvailability(this.value, 'username', '../model/usernameList.php')" id="username" type="text" placeholder="Username" name="username">
<input id="username" type="text" placeholder="Username" name="username">
</td>
</tr>
<tr>
......@@ -44,7 +44,7 @@
Email:
</td>
<td>
<input onkeyup="checkAvailability(this.value, 'email', '../model/emailList.php')" id="email" type="email" placeholder="Email address" name="email">
<input id="email" type="email" placeholder="Email address" name="email">
</td>
</tr>
<tr>
......
......@@ -41,6 +41,9 @@ var isPasswordFilled = false;
var isEmailFilled = false;
var isPhoneFilled = false;
var isPasswordMatch = false;
var isUsernameAvailable = false;
var isEmailAvailable = false;
document.getElementById("confirm-password").onkeyup = function () {
var confirmField = document.getElementById("confirm-password");
......@@ -64,6 +67,8 @@ document.getElementById("name").onkeyup = function () {
document.getElementById("username").onkeyup = function () {
isUsernameFilled = checkRequiredField("username");
checkAvailability(this.value, "username", '../controller/UsernameValidationController.php');
isUsernameAvailable = this.classList.contains("available");
};
document.getElementById("password").onkeyup = function () {
......@@ -72,6 +77,8 @@ document.getElementById("password").onkeyup = function () {
document.getElementById("email").onkeyup = function () {
isEmailFilled = checkRequiredField("email");
checkAvailability(this.value, "email", '../controller/EmailValidationController.php');
isEmailAvailable = this.classList.contains("available");
};
document.getElementById("phone").onkeyup = function () {
......@@ -86,9 +93,11 @@ document.getElementById("register-form").onkeyup = function () {
isPasswordFilled &&
isEmailFilled &&
isPhoneFilled &&
isPasswordMatch) {
isPasswordMatch &&
isUsernameAvailable &&
isEmailAvailable) {
submitBtn.removeAttribute("disabled");
} else {
submitBtn.setAttribute("disabled", "true");
}
}
\ No newline at end of file
};
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment