<%@ include file="/idb1/shop/SQL.jsp" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.lang.Integer" %>
<%

String nr = request.getParameter("nr"); 
String pwd = request.getParameter("pwd");
boolean authentic = false;

/*
At this point a connection to the WU's database should be established to check the users
number and password. If the database returns that the entered password is valid the boolean
variable authentic should change to true.
After a conversdation with Mathias Frey it was decided that this login should remain
a dummy login.
*/

authentic = true;
nr = nr.replaceAll("h", "");

if(authentic == true && nr!=null && pwd!=null && !nr.equals("")){
	ResultSet res = queryDB("select id from bachelor_user where number="+new Integer(nr)); 
	if(res.next()){
		//registered user -> set session attribute for identification
		session.setAttribute("user", res.getString("id"));
		out.println("<meta HTTP-EQUIV='REFRESH' content='0; url=myReservations.jsp'>");

	}else{
		//new user -> add to database + set session attribute
		updateDB("insert into bachelor_user(number, type) values("+nr+"+,'matrNr')");
		session.setAttribute("user", nr); 
		out.println("<meta HTTP-EQUIV='REFRESH' content='0; url=myReservations.jsp'>");
	}
	

}else{

	out.println("<meta HTTP-EQUIV='REFRESH' content='0; url=index.jsp'>");
}
%>