Commit 944bf227 authored by Ian De La Cruz's avatar Ian De La Cruz

Added a login flow. Partial fix for Issue #2

parent bdefb981
......@@ -8,6 +8,7 @@
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="http://www.parsecdn.com/js/parse-1.6.6.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</head>
<body>
<header>
......@@ -15,11 +16,11 @@
<a href="index.html"><img src="img/logo.png" width="40px"></a>
<h1 style="display:inline-block; margin:0; padding-top:10px; padding-left:15px;">Bus Ticket Reservation System</h1>
<a href="adminAccount.html" style="color:white;padding:15px 20px;"><i class="fa fa-plus fa-2x"></i></a>
<h1>Bus Ticket Reservation System</h1>
<a href="login.html"><i class="fa fa-2x fa-user"></i></a>
</nav>
</header>
<div class="wrapper">
<div class="wrapper" id="parent">
<div class="card button">
<a href="schedule.html" id="admin">
<img src="img/scheduling.png" width="50%">
......
Parse.initialize("waBL5APV9kwdeqnm1kQ34BivGHQjjHQr1I58ubmJ", "01foVLqzLntdIIplsOJCOkfCGTL63wti1rcUlVCD");
var Schedule = Parse.Object.extend("Schedule");
var login = function(){
event.preventDefault();
var uname = document.getElementById("login_uname").value,
pass = document.getElementById("login_pass").value;
Parse.User.logIn(uname, pass, {
success: function(user){
// console.log("success");
window.location = "index.html";
},
error: function(user, error){
console.log("Error " + error.code + " " + error.message);
}
});
}
var logout = function(){
event.preventDefault();
Parse.User.logOut();
location.href="login.html";
}
$('#reload').submit(function(event){
event.preventDefault();
......@@ -38,7 +57,7 @@ $('#reload').submit(function(event){
console.log("Saved.");
},
error: function(error){
console.log("Error " + error);
console.log("Error " + error.code + " " + error.message);
}
});
}
......@@ -52,61 +71,16 @@ $('#reload').submit(function(event){
//save
});
$("#create_schedule").submit(function(event){
event.preventDefault();
var destination = document.getElementById("destination").value,
initial = document.getElementById("initial").value,
etd = document.getElementById("etd").value,
eta = document.getElementById("eta").value,
company = document.getElementById("bus_company").value,
plate = document.getElementById("plate_number").value,
seats = document.getElementById("seats_available").value,
fare = document.getElementById("fare").value;
// console.log(typeof "plate");
var newSchedule = new Schedule();
newSchedule.save({
destination:destination,
startingTerminal: initial,
arrival: eta,
departure: etd,
busCompany: company,
busPlate: plate,
seatsAmount: seats,
ticketPrice: fare
}, {
success: function(newSchedule) {
// Execute any logic that should take place after the object is saved.
alert('New object created with objectId: ' + newSchedule.id);
console.log('New object created with objectId: ' + newSchedule.id);
},
error: function(newSchedule, error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and message.
alert('Failed to create new object, with error code: ' + error.message);
}
});
alert(destination);
});
var query = new Parse.Query(Schedule);
var id;
query.find({
success: function(results) {
console.log("Successfully retrieved " + results.length);
// Do something with the returned Parse.Object values
for (var i = 0; i < results.length; i++) {
var object = results[i];
id = object.id;
console.log(object);
}
},
error: function(error) {
status.error("Error: " + error.code + " " + error.message);
}
});
\ No newline at end of file
window.onload = function(){
var currentUser = Parse.User.current();
var currLoc = location.href;
if (!currentUser && currLoc.indexOf("login.html") == -1 ) {
location.href = "login.html";
} else {
var parent = document.getElementById("parent");
var outBtn = document.createElement("button");
outBtn.setAttribute("onclick", "logout()");
outBtn.innerHTML = "Logout";
parent.appendChild(outBtn);
}
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>uBus | Admin System</title>
<meta name="description" content="uBus Ticket Reservation System administrator tools.">
<link rel="icon" type="image/x-icon" href="img/favicon.ico">
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="http://www.parsecdn.com/js/parse-1.6.6.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</head>
<body>
<header>
<nav>
<a href="index.html"><img src="img/logo.png" width="40px"></a>
<h1 style="display:inline-block; margin:0; padding-top:10px; padding-left:15px;">Bus Ticket Reservation System</h1>
<a href="adminAccount.html" style="color:white;padding:15px 20px;"><i class="fa fa-plus fa-2x"></i></a>
<a href="login.html"><i class="fa fa-2x fa-user"></i></a>
</nav>
</header>
<div class="wrapper">
<form method="post" id="adminLogin">
<input type="text" placeholder="Username" id="login_uname">
<input type="password" placeholder="Password" id="login_pass">
<button type="button" onclick="login()">Log-In</button>
</form>
</div>
</body>
</html>
......@@ -14,8 +14,8 @@
<nav>
<a href="index.html"><img src="img/logo.png" width="40px"></a>
<a href="javascript:void(0);"><img src="img/add.png" width="40px"></a>
<a href="javascript:void(0);"><img src="img/search.png" width="40px"></a>
<a href="javascript:void(0);"><i class="fa fa-2x fa-plus" style="color:white; padding-top:5px; padding-right:10px;"></i></a>
<a href="javascript:void(0);"><i class="fa fa-2x fa-search" style="color:white; padding-top:5px; padding-right:10px;"></i></a>
</nav>
</header>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment