-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
91 lines (84 loc) · 2.8 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
$link = false;
include('../db_connect.php');
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<link rel="stylesheet" href="battleShip.css" />
</head>
<body>
<h1>Welcome to Battle Ship!</h1>
<h2>Login</h2>
<form action="/" data-type="login" id="loginForm">
Username: <input class="field" type="text" name="name"><br>
Password: <input class="field" type="password" name="password"><br>
<div class="insert">Email: <input class="field" type="email" name="email"></div><br>
<input type="submit">
</form>
<div id="actionBtn" data-type="forgotPw" style="text-decoration:underline;cursor:pointer">forgot password</div>
<div id="result"></div>
<script>
$("#loginForm").submit(function(event) {
event.preventDefault();
var type = $(this).attr('data-type');
var $form = $(this),
un = $form.find('input[name="name"]').val(),
pw = $form.find('input[name="password"]').val(),
url = $form.attr('action');
var dataToSend = {
password:pw
}
var email = $form.find('input[name="email"]').val();
if(type == 'forgotPw'){
dataToSend.email = email;
dataToSend.name = un;
} else if(type == 'insert'){
dataToSend.email = email;
dataToSend.name = un;
}else{
dataToSend.username = un;
}
var postingUrl = (type == 'login')? 'login.php':'insert.php';
var posting = $.post(postingUrl, dataToSend);
posting.always(function(dataToSend) {
console.log(dataToSend);
//dataToSend = JSON.parse(dataToSend.responseText);
// $("#result").empty().text(dataToSend.message);
})
});
$("#actionBtn").on('click',function(event) {
//clear form
$('.field').val('');
$("#result").empty();
//get new params for page
var type = $(this).attr('data-type');
var pageTitle = 'Forgot Password';
var formType = 'backToLogin';
if(type == 'backToLogin'){
$(this).attr('data-type','forgotPw')
.text('Register');
$('.insert').hide();
pageTitle = 'Login';
formType = 'ForgotPw';
}else{
$(this).attr('data-type','backToLogin').text('Back');
$('.insert').show();
}
//set new form and button type
$('#loginForm').attr('data-type',type);
$('h2').text(pageTitle);
})
</script>
</body></html>
<?php
mysqli_close($link);
?>