-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
182 lines (159 loc) · 6.32 KB
/
index.html
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex,follow" />
<title>Login</title>
<link href="css/style.css" media="screen" rel="stylesheet">
<link href="css/reset.css" media="screen" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,600italic,700italic,800italic,400,300,600,800" rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
</head>
<body>
<div class="container">
<div class="flat-design-form">
<ul class="tabs">
<li><a class="active" href="#login" id="login-tab"><span id="login_icon"></span> Login</a></li>
<li><a href="#register" id="register-tab"><span id="signup_icon"></span> Register</a></li>
</ul>
<div class="form-display show" id="login">
<h1>Login</h1>
<form action="" novalidate="">
<fieldset>
<ul>
<li>
<div class="item">
<input data-validate-length-range="6" name="name" id="username" placeholder="Username" required="required" type="text">
</div>
</li>
<li>
<div class="item">
<input data-validate-length-range="6" name="password" id="password" placeholder="Password" required="required" type="password">
</div>
</li>
<li><input class="button-login" type="button" value="Login"></li>
</ul>
</fieldset>
</form>
</div>
<div class="form-display hide" id="register">
<h1>Register</h1>
<form action="" novalidate="">
<fieldset>
<ul>
<li>
<div class="item">
<input data-validate-length-range="6" name="name" id="register_username" placeholder="Username" required="required" type="text">
</div>
</li>
<li>
<div class="item">
<input data-validate-length="6,8" name="password" placeholder="Password" id="register_password" required="required" type="text">
</div>
</li>
<li>
<div class="item">
<input class='email' name="email" placeholder="Email" id="register_email" required="required" type="email">
</div>
</li>
<li><input class="button-register" id='send' type="button" value="Sign Up"></li>
</ul>
</fieldset>
</form>
</div>
</div>
</div>
<script src="js/main.js"></script>
<script src="js/validator.js"></script>
<script>
// initialize the validator function
// validate a field on "blur" event, a 'select' on 'change' event & a '.reuired' classed multifield on 'keyup':
$('form')
.on('blur', 'input[required], input.optional, select.required', validator.checkField)
.on('change', 'select.required', validator.checkField)
.on('keypress', 'input[required][pattern]', validator.keypress);
$('.multi.required')
.on('keyup blur', 'input', function() {
validator.checkField.apply($(this).siblings().last()[0]);
});
// bind the validation to the form submit event
//$('#send').click('submit');//.prop('disabled', true);
$('form').submit(function(e) {
e.preventDefault();
var submit = true;
// evaluate the form using generic validaing
if (!validator.checkAll($(this))) {
submit = false;
print = "Enter the condition";
}
if (submit)
this.submit();
return false;
});
</script>
<script>
// Script to call LoginAPI
// Parameters: username, password
$('.button-login').click(function(){
console.log($("#username").val());
$.ajax({
url: 'https://localhost/quiz-app/login.php',
type: 'POST',
dataType:'json',
data: { "username": $("#username").val(),"password": $("#password").val() },
success: function(response) {
console.log(response);
var res_json = JSON.parse(JSON.stringify(response));
if (res_json["status"] == 1)
{
document.cookie = "username="+res_json["username"];
console.log(res_json["username"]);
window.location = "dashboard.html";
}
else
{
alert('Invalid Credentials!');
}
},
error: function(data){
console.log(data);
console.log("Error in api call.");
}
});
});
</script>
<script>
// Script to call RegisterAPI
// Parameters: username, password, Email
$('.button-register').click(function(){
console.log($("#username").val());
$.ajax({
//url: 'https://localhost:3000/tasks',
url: 'https://localhost/quiz-app/register.php',
// url: 'login.php',
type: 'POST',
dataType:'json',
data: { "email":$("#register_email").val(),"username": $("#register_username").val(),"password": $("#register_password").val() },
success: function(response) {
console.log(response);
//var res_json = JSON.parse(JSON.stringify(response));
var res_json = response;
if (res_json["status"] == 1)
{
alert('User Registered. Please login again.');
window.location = "index.html";
}
else
{
alert(res_json["message"]);
}
},
error: function(data){
console.log(data);
console.log("Error in api call of register.");
}
});
});
</script>
</body>
</html>