Skip to content
Permalink
a5cfbf2425
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
62 lines (60 sloc) 2.04 KB
{% extends 'base.html' %}
{% block title %}
Login page
{% endblock %}
<script>
var users = new Array("customer1", "customer2", "admin");
var passwords = new Array("p455w0rd", "p455w0rd", "p455w0rd");
function check_pass(user, pass) <!-- creating a function in java script that checks if the password is correct and redirects users to the correct website -->
<!-- depending on wheter it's a customer or admin it redirects to a different website -->
{
for(var i = 0; i < users.length; i++){
if((user == users[i]) && (pass == passwords[i]))
return true;
}
return false;
} <!-- checks if the correct user and password has been entered using a for loop and returns a true or false statement -->
function check()
{
var user = document.form1.user.value;
var pass = document.form1.pass.value;
if(!check_pass(user, pass)){
alert('Incorrect password!'); //return information to the user that the credentials he used did not match the passwords saved in the system
}
else{
if (user == "admin") {
document.location.href = "admin.html"; //If the user is the admin the website redirects the user to the website with the option of adding stock
}else{
document.location.href = "stock.html"; //otherwise the user is directed to the stock website where he can see the normal website
}
}
}
</script>
{% block content %}
<title>Bookstore</title>
</head>
<body>
<div>
<h1>Login</h1>
<CENTER> <!-- Simple login table -->
<H2>Enter username and password:</H2>
<FORM NAME = "form1">
<TABLE border="1"><TR>
<TD bordercolor="#FFFFFF">Username:</TD>
<TD bordercolor="#FFFFFF">
<INPUT TYPE="text" NAME="user">
</TD>
</TR><TR>
<TD bordercolor="#FFFFFF">Password:</TD>
<TD bordercolor="#FFFFFF">
<INPUT TYPE="password" NAME="pass">
</TD>
</TR><TR>
<TD colspan="2" align="center" bordercolor="#FFFFFF">
<INPUT TYPE="button" VALUE="Enter" onClick="check();"> <!-- When the button is pressed the website runs the check() function -->
</TD>
</TR></TABLE>
</FORM>
</div>
</TABLE>
{% endblock %}