diff --git a/src/controller/EmailValidationController.php b/src/controller/EmailValidationController.php new file mode 100644 index 0000000000000000000000000000000000000000..b8397adde4e97f89c830a703f042be73a9a819b4 --- /dev/null +++ b/src/controller/EmailValidationController.php @@ -0,0 +1,25 @@ +<?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 diff --git a/src/controller/UsernameValidationController.php b/src/controller/UsernameValidationController.php new file mode 100644 index 0000000000000000000000000000000000000000..377fb113dd1ee8421a23d1ced37ab5e36dc2d8dd --- /dev/null +++ b/src/controller/UsernameValidationController.php @@ -0,0 +1,21 @@ +<?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 diff --git a/src/view/register.html b/src/view/register.html index 4e51a2f1f34dfd4bd6a12aef8cb2f2ab6f0aadd0..8438a3df9bfa4d20d1278c71ddce6a2a660e59a9 100644 --- a/src/view/register.html +++ b/src/view/register.html @@ -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> diff --git a/src/view/script.js b/src/view/script.js index ab16c24a97abccaa1c7ca41386258175781d57ea..ef52f8ebb5b84221116d7cf84bae413c5a59b5f1 100644 --- a/src/view/script.js +++ b/src/view/script.js @@ -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