Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 152 additions & 57 deletions JS/registerCheck.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,186 @@
var registerButton = GetByID('registerButton');
registerButton.onclick = function(){
var errors = [];
var name = document.getElementsByName('Name')[0];
var surname = document.getElementsByName('Surname')[0];
var telephone = document.getElementsByName('telephone')[0];
var email = document.getElementsByName('email')[0];
var pass1 = document.getElementsByName('password1')[0];
var pass2 = document.getElementsByName('password2')[0];
name.style.border = '0px solid black';
surname.style.border = '0px solid black';
telephone.style.border = '0px solid black';
email.style.border = '0px solid black';
pass1.style.border = '0px solid black';
pass2.style.border = '0px solid black';
var checker = 0;

if (name.value !== ""){
if (name.value[0] !== name.value[0].toUpperCase()){
errors.push('Your name must start with a capital letter.');
name.style.border = '2px solid red';

var registerButton = GetByID('registerButton');

registerButton.onclick = function(){
var errors = [];
var name = document.getElementsByName('Name')[0];
var surname = document.getElementsByName('Surname')[0];
var telephone = document.getElementsByName('telephone')[0];
var email = document.getElementsByName('email')[0];
var pass1 = document.getElementsByName('password1')[0];
var pass2 = document.getElementsByName('password2')[0];
name.style.border = '0px solid black';
surname.style.border = '0px solid black';
telephone.style.border = '0px solid black';
email.style.border = '0px solid black';
pass1.style.border = '0px solid black';
pass2.style.border = '0px solid black';
var checker = 0;

if (name.value !== ""){
if (name.value[0] !== name.value[0].toUpperCase()){
errors.push('Your name must start with a capital letter.');
name.style.border = '2px solid red';
}
else {
checker++;
}
}
else {
name.style.border = '2px solid red';
}
if (surname.value !== ""){
if (surname.value[0] !== surname.value[0].toUpperCase()){
errors.push('Your surname must start with a capital letter.');
surname.style.border = '2px solid red';
}
else {
checker++;
}
}
else {
surname.style.border = '2px solid red';
}
if (telephone.value !== ""){
if (isNaN(telephone.value)){
telephone.style.border = '2px solid red';
}
else {
checker++;
}
}
else {
telephone.style.border = '2px solid red';
}
if (email.value !== ""){
var checkedEmail = 0;
for (var x in email.value){
if (email.value[x] == '@'){
checkedEmail++;
}
else {
checker++;
else if (email.value[x] == '.'){
checkedEmail++;
}
}
if (checkedEmail >= 2){
checker++;
}
else {
name.style.border = '2px solid red';
email.style.border = '2px solid red';
}
}
else {
email.style.border = '2px solid red';
}
if (pass1.value !== "" && pass2.value !== ""){
if (pass1.value !== pass2.value){
errors.push('Passwords are not equal.');
pass1.style.border = '2px solid red';
pass2.style.border = '2px solid red';
}
else {
checker++;
}
if (surname.value !== ""){
if (surname.value[0] !== surname.value[0].toUpperCase()){
errors.push('Your surname must start with a capital letter.');
surname.style.border = '2px solid red';
}
else {
pass1.style.border = '2px solid red';
pass2.style.border = '2px solid red';
}
var getparameters = location.search.substr(1).split("&");

for (var index = 0; index < getparameters.length; index++) {
var tmp = getparameters[index].split("=");
if (tmp[1] == 'company') var isCompany = true;
}
if (isCompany){
var companyname = document.getElementsByName('companyName')[0];
var companyID = document.getElementsByName('companyID')[0];
var companytelephone = document.getElementsByName('companyTelephone')[0];
var companyemail = document.getElementsByName('companyEmail')[0];
var companySector = document.getElementsByName('sector')[0];

companyname.style.border = '0px solid black';
companyID.style.border = '0px solid black';
companytelephone.style.border = '0px solid black';
companyemail.style.border = '0px solid black';
companySector.style.border = '0px solid black';

if (companyname.value !== ""){
if (companyname.value[0] !== companyname.value[0].toUpperCase()){
errors.push('Your Company name must start with a capital letter.');
companyname.style.border = '2px solid red';
}
else {
checker++;
}
}
else {
surname.style.border = '2px solid red';
else{
companyname.style.border = '2px solid red';
}
if (telephone.value !== ""){
if (isNaN(telephone.value)){
telephone.style.border = '2px solid red';


if (companyID.value !== ""){
//check for social security number
checker++;
}
else{
companyID.style.border = '2px solid red';
}


if (companytelephone.value !== ""){
if (isNaN(companytelephone.value)){
companytelephone.style.border = '2px solid red';
}
else {
checker++;
}
}
else {
telephone.style.border = '2px solid red';
companytelephone.style.border = '2px solid red';
}
if (email.value !== ""){

if (companyemail.value !== ""){
var checkedEmail = 0;
for (var x in email.value){
if (email.value[x] == '@'){
for (var x in companyemail.value){
if (companyemail.value[x] == '@'){
checkedEmail++;
}
else if (email.value[x] == '.'){
else if (companyemail.value[x] == '.'){
checkedEmail++;
}
}
if (checkedEmail == 2){
if (checkedEmail >= 2){
checker++;
}
else {
email.style.border = '2px solid red';
companyemail.style.border = '2px solid red';
}
}
else {
email.style.border = '2px solid red';
companyemail.style.border = '2px solid red';
}
if (pass1.value !== "" && pass2.value !== ""){
if (pass1.value !== pass2.value){
errors.push('Passwords are not equal.');
pass1.style.border = '2px solid red';
pass2.style.border = '2px solid red';
}
else {
checker++;
}

if (companySector.value !== ''){
checker++;
}
else {
pass1.style.border = '2px solid red';
pass2.style.border = '2px solid red';
else{
companySector.style.border = '2px solid red';
}

if (checker == 5){
GetByID('register').submit();
}

if (isCompany){
var totalcheck = 10;
}
else {
var totalcheck = 5;
}


if (checker == totalcheck){
var forms = document.getElementsByTagName('form');
for (var x in forms){
forms[x].submit();
}
}
}
}
112 changes: 69 additions & 43 deletions PHP/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,74 @@
</head>
<body>
<?php
require_once('mysqli_connect.php');
function check_login($dbc, $email = '', $pass = '') {
$errors = array(); // Initialize error array.
// Validate the email address:
if (empty($email)) {
$errors[] = 'Please, enter your email address';
} else {
$e = mysqli_real_escape_string($dbc, trim($email));
}
// Validate the password:
if (empty($pass)) {
$errors[] = 'Please, enter your password.';
} else {
$p = mysqli_real_escape_string($dbc, trim($pass));
}
//Validate if in the DB the BusinessID field is Null or not:
if (is_null($BussID)){
// enter as Individual
} else {
// enter as Business
}
if (empty($errors)) { // If everything's OK.
// Retrieve the Name and Surname for that email/password combination:
$q = "SELECT Name, Surname, BusinessID FROM Individuals WHERE Email='$e' AND EncryptedPassword=SHA1('$p') AND BusinessID='$BussID'";
$r = @mysqli_query ($dbc, $q); // Run the query.

// Check the result:
if (mysqli_num_rows($r) == 1) {
// Fetch the record:
$row = mysqli_fetch_array ($r, MYSQLI_ASSOC);
$errors = array(); // Initialize error array.
// Validate the email address:
if (empty($email)) {
$errors[] = 'Please, enter your email address';
} else {
$e = mysqli_real_escape_string($dbc, trim($email));
}
// Validate the password:
if (empty($pass)) {
$errors[] = 'Please, enter your password.';
} else {
$p = mysqli_real_escape_string($dbc, trim($pass));
}

// Return true and the record:
return array(true, $row);

} else { // Not a match!
$errors[] = 'The email address and password entered do not match those on file.';
}
if (empty($errors)) { // If everything's OK.
// Retrieve the Name and Surname for that email/password combination:

$q = "SELECT Name, Surname, BusinessID FROM Individuals WHERE Email='$e' AND EncryptedPassword=SHA1('$p')";
$r = @mysqli_query ($dbc, $q); // Run the query.

// Check the result:
if (mysqli_num_rows($r) == 1) {
// Fetch the record:
$row = mysqli_fetch_array ($r, MYSQLI_ASSOC);

// Return true and the record:
return array(true, $row);

} else { // Not a match!
$errors[] = 'The email address and password entered do not match those on file.';
}

} // End of empty($errors) IF.

// Return false and the errors:
return array(false, $errors);
} // End of check_login() function.
?>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$login_result = check_login($dbc, $_POST['user_email'], $_POST['user_pass']);

if ($login_result[0]){

echo "Thanks " . $login_result[1]['Name'] . " " . $login_result[1]['Surname'] . "!";
echo '<br>';
//Validate if in the DB the BusinessID field is Null or not:
if (is_null($login_result[1]['BusinessID'])){
session_start();
$_SESSION["individual"]=$login_result[1]['Name'] . " " . $login_result[1]['Surname'];
header("Location: main.php");
}
else {
session_start();
$_SESSION["company"]=$login_result[1]['Name'] . " " . $login_result[1]['Surname'] . " " . $login_result[1]['BusinessID'];
// lock $row
header("Location: main.php");
}



}
}



} // End of empty($errors) IF.

// Return false and the errors:
return array(false, $errors);
} // End of check_login() function.
?>
<div id="entry_container">
<div id="about" class="box">
Expand All @@ -67,11 +93,11 @@ function check_login($dbc, $email = '', $pass = '') {
</div>
<div id="login" class="box">
<span class="title">OnTime</span>
<form>
<form method="post">
<div>
<input class="input text" type="text" placeholder="Email">
<input name="user_email" class="input text" type="text" placeholder="Email" value="<?php if (isset($_POST['user_email'])){echo $_POST['user_email'];}?>">
<br>
<input class="input text" type="password" placeholder="Password">
<input name="user_pass" class="input text" type="password" placeholder="Password">
</div>
<br>
<div id="submits">
Expand All @@ -81,7 +107,7 @@ function check_login($dbc, $email = '', $pass = '') {
</form>
</div>
</div>
<?php include('footer.html'); ?>
<?php include('footer.php'); ?>
<div id="flag" class="modal">
<div class="modal-content">
<div id="individual" class="box">I'm an individual</div>
Expand Down
Loading