Skip to content

Commit

Permalink
Merge pull request #40 from sk-upadhyay/main
Browse files Browse the repository at this point in the history
Feat: Filter genuine email #21
  • Loading branch information
aswinikalyan30 authored May 24, 2024
2 parents 3a2def0 + 8654a62 commit 217310f
Show file tree
Hide file tree
Showing 4 changed files with 287 additions and 190 deletions.
212 changes: 119 additions & 93 deletions login.php
Original file line number Diff line number Diff line change
@@ -1,134 +1,160 @@
<!DOCTYPE html>
<html lang="en">
<?php
<?php
session_start();
include('./db_connect.php');
ob_start();
// if(!isset($_SESSION['system'])){
include ('./db_connect.php');
ob_start();
// if(!isset($_SESSION['system'])){

$system = $conn->query("SELECT * FROM system_settings")->fetch_array();
foreach($system as $k => $v){
$_SESSION['system'][$k] = $v;
}
// }
ob_end_flush();
$system = $conn->query("SELECT * FROM system_settings")->fetch_array();
foreach ($system as $k => $v) {
$_SESSION['system'][$k] = $v;
}
// }
ob_end_flush();
?>
<?php
if(isset($_SESSION['login_id']))
header("location:index.php?page=home");
<?php
if (isset($_SESSION['login_id']))
header("location:index.php?page=home");

?>
<?php include 'header.php' ?>

<style>
.login-logo {
text-align: center;
margin-bottom: 20px; /* Adjust as needed */
margin-bottom: 20px;
/* Adjust as needed */
}

.login-logo img {
width: 200px; /* Set the width as per your requirements */
height: auto; /* This maintains the image's aspect ratio */
width: 200px;
/* Set the width as per your requirements */
height: auto;
/* This maintains the image's aspect ratio */
}
</style>

<body class="hold-transition login-page bg-white">

<h2><b>COER AQMS</b></h2>
<div class="login-box">
<div class="login-logo">
<a href="#" class="text-white"></a>
</div>
<!-- /.login-logo -->
<div class="login-box">
<div class="login-logo">
<a href="#" class="text-white"></a>
</div>
<!-- /.login-logo -->


<div class="card">
<div class="card-body login-card-body">
<div class="card">
<div class="card-body login-card-body">
<div class="login-logo">
<img src="profpraisal.png" alt="Your Image Alt Text">
<img src="profpraisal.png" alt="Your Image Alt Text">
</div>
<form action="" id="login-form">
<!-- <div class="card">
<!-- <div class="card">
<div class="card-body login-card-body">
<form action="" id="login-form"> -->
<div class="input-group mb-3">
<input type="email" class="form-control" name="email" required placeholder="Email">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-envelope"></span>
</div>
</div>
</div>
<div class="input-group mb-3">
<input type="password" class="form-control" name="password" required placeholder="Password">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
<div class="input-group mb-3">
<input type="email" class="form-control" name="email" required placeholder="Email">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-envelope"></span>
</div>
</div>
</div>
</div>
<div class="form-group mb-3">
<label for="">Login As</label>
<select name="login" id="" class="custom-select custom-select-sm">
<option value="3">Student</option>
<option value="2">Faculty</option>
<option value="1">Admin</option>
</select>
</div>
<div class="row">
<div class="col-8">
<div class="icheck-primary">
<input type="checkbox" id="remember">
<label for="remember">
Remember Me
</label>
<div class="input-group mb-3">
<input type="password" class="form-control" name="password" required placeholder="Password">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock" onclick="togglePasswordVisibility()"></span>
<span class="fas fa-eye" style="display:none;" onclick="togglePasswordVisibility()"></span>
</div>
</div>
</div>
<!-- /.col -->
<div class="col-4">
<button type="submit" class="btn btn-primary btn-block">Sign In</button>
<div class="form-group mb-3">
<label for="">Login As</label>
<select name="login" id="" class="custom-select custom-select-sm">
<option value="3">Student</option>
<option value="2">Faculty</option>
<option value="1">Admin</option>
</select>
</div>
<p class="mb-1">
Don't have an account? <a href="signup.php" class="text-center">Sign up</a>
</p>
<div class="row">
<div class="col-8">
<div class="icheck-primary">
<input type="checkbox" id="remember">
<label for="remember">
Remember Me
</label>
</div>
</div>
<!-- /.col -->
<div class="col-4">
<button type="submit" class="btn btn-primary btn-block">Sign In</button>
</div>
<p class="mb-1">
Don't have an account? <a href="signup.php" class="text-center">Sign up</a>
</p>

<!-- /.col -->
</div>
</form>
<!-- /.col -->
</div>
</form>
</div>
<!-- /.login-card-body -->
</div>
<!-- /.login-card-body -->
</div>
</div>
<!-- /.login-box -->
<script>
$(document).ready(function(){
$('#login-form').submit(function(e){
e.preventDefault()
start_load()
if($(this).find('.alert-danger').length > 0 )
$(this).find('.alert-danger').remove();
$.ajax({
url:'ajax.php?action=login',
method:'POST',
data:$(this).serialize(),
error:err=>{
console.log(err)
end_load();
<!-- /.login-box -->
<script>
$(document).ready(function () {
$('#login-form').submit(function (e) {
e.preventDefault()
start_load()
if ($(this).find('.alert-danger').length > 0)
$(this).find('.alert-danger').remove();
$.ajax({
url: 'ajax.php?action=login',
method: 'POST',
data: $(this).serialize(),
error: err => {
console.log(err)
end_load();

},
success:function(resp){
if(resp == 1){
location.href ='index.php?page=home';
}else{
$('#login-form').prepend('<div class="alert alert-danger">Username or password is incorrect.</div>')
end_load();
}
}
},
success: function (resp) {
if (resp == 1) {
location.href = 'index.php?page=home';
} else {
$('#login-form').prepend('<div class="alert alert-danger">Username or password is incorrect.</div>')
end_load();
}
}
})
})
})
})
})
</script>
<?php include 'footer.php' ?>
</script>
<script>
function togglePasswordVisibility() {
var passwordInput = document.querySelector('[name="password"]');
var lockIcon = document.querySelector('.fa-lock');
var eyeIcon = document.querySelector('.fa-eye');

// Check if the password is currently visible
if (passwordInput.type === 'password') {
// If hidden, change to 'text' to show it and toggle icons
passwordInput.type = 'text';
lockIcon.style.display = 'none';
eyeIcon.style.display = 'block';
} else {
// If visible, change to 'password' to hide it and toggle icons
passwordInput.type = 'password';
lockIcon.style.display = 'block';
eyeIcon.style.display = 'none';
}
}

</script>
<?php include 'footer.php' ?>

</body>

</html>
47 changes: 20 additions & 27 deletions process_signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,33 @@
include('./db_connect.php');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if(isset($_POST['user_type']) && $_POST['user_type'] === 'student'){
$CUID = $_POST['CUID'];
$firstName = $_POST['firstname'];
$lastName = $_POST['lastname'];
$email = $_POST['email'];
$password = password_hash($_POST['password'], PASSWORD_BCRYPT); // Hash the password for security

// Insert the user data into the student_list table
$insert_query = "INSERT INTO student_list (school_id, firstname, lastname, email, password) VALUES ('$CUID', '$firstName', '$lastName', '$email', '$password')";
if ($conn->query($insert_query) === TRUE) {
echo "successful";
} else {
// Handle any database insert errors for the student_list table
echo "Error: " . $insert_query . "<br>" . $conn->error;
}
}
if(isset($_POST['user_type']) && $_POST['user_type'] === 'faculty'){
$CUID = $_POST['CUID'];
$firstName = $_POST['firstname'];
$lastName = $_POST['lastname'];
$email = $_POST['email'];
$password = password_hash($_POST['password'], PASSWORD_BCRYPT); // Hash the password for security
// Determine the table based on user type
$table = $_POST['user_type'] === 'student' ? 'student_list' : 'faculty_list';

// Check if the CUID already exists in the table
$check_query = "SELECT * FROM $table WHERE school_id = '$CUID'";
$check_result = $conn->query($check_query);

// Insert the user data into the student_list table
$insert_query = "INSERT INTO faculty_list (school_id, firstname, lastname, email, password) VALUES ('$CUID', '$firstName', '$lastName', '$email', '$password')";
if ($conn->query($insert_query) === TRUE) {
echo "successful";
if ($check_result->num_rows > 0) {
// CUID already exists
$response = ['status' => 'error', 'message' => 'CUID already registered'];
} else {
// Handle any database insert errors for the student_list table
echo "Error: " . $insert_query . "<br>" . $conn->error;
// CUID does not exist, proceed with insertion
$insert_query = "INSERT INTO $table (school_id, firstname, lastname, email, password) VALUES ('$CUID', '$firstName', '$lastName', '$email', '$password')";
if ($conn->query($insert_query) === TRUE) {
$response = ['status' => 'success', 'message' => 'Registration successful'];
} else {
// Handle any database insert errors
$response = ['status' => 'error', 'message' => 'Error: ' . $insert_query . '<br>' . $conn->error];
}
}
}
}

// Close the database connection if needed
$conn->close();
?>
// Send the response to the AJAX call
echo json_encode($response);
}
Loading

0 comments on commit 217310f

Please sign in to comment.