Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rhalp10 committed May 13, 2019
1 parent 386cc51 commit a90ecdf
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 7 deletions.
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

97 changes: 92 additions & 5 deletions authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
</div>
</div>
<div class="col" style=" background-color: #f0f0f0; border: 1px solid #1d8f1d; border-radius:0px 5px 5px 0px;" >
<form class="form-signin" id="authentication_form" method="POST">

<div class="text-center mb-4">
<img class="mb-4" src="img/logo.png" width="72" height="72">
<h1 class="h3 mb-3 font-weight-normal">Login</h1>
<h1 class="h3 mb-3 font-weight-normal" id="f_text">Login</h1>
</div>

<div id="f_login">
<form class="form-signin" id="login_form" method="POST">
<div class="form-label-group">
<input type="text" id="inputEmail" class="form-control" placeholder="Username" name="username" required autofocus>
<label for="inputEmail">Username</label>
Expand All @@ -48,13 +49,61 @@
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>

<input type="hidden" name="operation" value="submit_login">
<button class="btn btn-lg btn-primary btn-block" type="submit" style="background-color: #1d8f1d" name="submit_login">Sign in</button>
<div class="text-center">
Don't have an account? <a href="#" id="a_sign">Sign up</a>
</div>
</form>
</div>
<div id="f_register">
<form class="form-signin" id="register_form" method="POST">
<div class="form-row">
<div class="form-group col-md-6">
<label for="acc_username">Username</label>
<input type="text" class="form-control" id="acc_username" name="acc_username" placeholder="" value="" required="">
</div>
<div class="form-group col-md-6">
<label for="acc_email">Email:</label>
<input type="email" class="form-control" id="acc_email" name="acc_email" placeholder="" value="" required="">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="acc_name">Full Name</label>
<input type="text" class="form-control" id="acc_name" name="acc_name" placeholder="" value="" required="">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6">
<label for="acc_pass" id="l_acc_pass">Password</label>
<input type="password" class="form-control" id="acc_pass" name="acc_pass" placeholder="" value="" required="">
</div>
<div class="form-group col-md-6">
<label for="acc_cpass" id="l_acc_cpass">Confirm:</label>
<input type="password" class="form-control" id="acc_cpass" name="acc_cpass" placeholder="" value="" required="">
</div>
</div>

<div class="form-row">
<div class="form-group col-md-12">
<label for="acc_add">Address</label>
<input type="text" class="form-control" id="acc_add" name="acc_add" placeholder="" value="" required="">
</div>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit" style="background-color: #1d8f1d" name="submit_register">Register</button>
<div class="text-center">
Already have an account? <a href="#" id="a_login">Login</a>
</div>
</form>
</div>

<p class="mt-5 mb-3 text-muted text-center">&copy; <?php
$fromYear = 2019;
$thisYear = (int)date('Y');
echo $fromYear . (($fromYear != $thisYear) ? '-' . $thisYear : '');?> CVSU Main Indang - Saka, All rights reserved</p>
</form>

</div>
</div>

Expand All @@ -65,7 +114,8 @@
include('x-script.php');
?>
<script type="text/javascript">
$(document).on('submit', '#authentication_form', function(event){
$('#f_register').hide();
$(document).on('submit', '#login_form', function(event){
event.preventDefault();

$.ajax({
Expand All @@ -89,5 +139,42 @@
});

});
$(document).on('submit', '#register_form', function(event){
event.preventDefault();

$.ajax({
url:"data-register.php",
method:'POST',
data:new FormData(this),
contentType:false,
processData:false,
type: 'html',
success:function(data)
{
var newdata = JSON.parse(data);
console.log(newdata);
if (newdata.success) {
alert(newdata.success);
$('#f_login').show();
$('#f_register').hide();
}
else{
alert(newdata.error);
}
}
});

});
$(document).on('click', '#a_sign', function(){

$('#f_text').text('Register');
$('#f_login').hide();
$('#f_register').show();
});
$(document).on('click', '#a_login', function(){
$('#f_text').text('Login');
$('#f_login').show();
$('#f_register').hide();
});
</script>
</html>
77 changes: 77 additions & 0 deletions data-register.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

include('dbconfig.php');
include('data-md5.php');
$output = array();

$acc_username = $_POST["acc_username"];
$acc_name = $_POST["acc_name"];

$acc_email = $_POST["acc_email"];
$acc_pass = $_POST["acc_pass"];
$acc_cpass = $_POST["acc_cpass"];
$acc_address = $_POST["acc_add"];

$acc_username = stripslashes($acc_username);
$acc_name =stripslashes($acc_name);

$acc_email = stripslashes($acc_email);
$acc_pass = stripslashes($acc_pass);
$acc_cpass = stripslashes($acc_cpass);
$acc_address = stripslashes($acc_address);

$acc_username = mysqli_real_escape_string($conn,$acc_username);
$acc_name = mysqli_real_escape_string($conn,$acc_name);
$acc_email =mysqli_real_escape_string($conn,$acc_email);
$acc_pass = mysqli_real_escape_string($conn,$acc_pass);
$acc_cpass = mysqli_real_escape_string($conn,$acc_cpass);
$acc_address = mysqli_real_escape_string($conn,$acc_address);


if ($acc_pass != $acc_cpass) {
$output['error'] = "Password not match";
}
else{
$newpass = encryptIt($acc_pass);

$sql = "SELECT * FROM `user` WHERE user_Name = '$acc_username'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
$output['error'] = 'Username already used';

}
else {
$sql = "INSERT INTO `user` (
`user_ID`,
`lvl_ID`,
`user_img`,
`user_Fullname`,
`user_Name`,
`user_Pass`,
`user_Email`,
`user_Address`,
`user_Registered`)
VALUES (
NULL,
1,
NULL,
'$acc_name',
'$acc_username',
'$newpass',
'$acc_email',
'$acc_address',
CURRENT_TIMESTAMP);";

if ($result = mysqli_query($conn, $sql)) {
$output['success'] = 'Successfully Register';
}
else{
$output['error'] = 'Failed to Register';
}

}

}
echo json_encode($output,true);
?>

0 comments on commit a90ecdf

Please sign in to comment.