Skip to content
Snippets Groups Projects
Commit fd7f305e authored by Boris's avatar Boris
Browse files

cookie

parent d34b7229
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,16 @@ public class StartServer {
public static boolean verificationSession(spark.Request req)
{
String c = req.cookie("session-id");
if (c == null) return false;
else{
return true;
}
}
public static void displayLocalHost(int portNb, String suffix)
{
System.out.println("http://localhost:"+portNb+"/"+suffix);
......@@ -47,7 +57,7 @@ public class StartServer {
displayLocalHost(portNb, "profs");
get("/profs", (req, res) -> {
if (authentified)
if (verificationSession(req))
{
return ProfGUI.getAllProfs();
}
......@@ -60,7 +70,7 @@ public class StartServer {
});
get("/welcome",(req,res) -> {
if (authentified)
if (verificationSession(req))
{
return ProfGUI.getWelcomePage(connected);
}
......@@ -86,31 +96,28 @@ public class StartServer {
post("/login",(req,res)->{
String username = req.queryParams("userName");
String password = req.queryParams("password");
List<ProfEntity> profs = Core.Prof.getAll();
ProfEntity found = null;
for (ProfEntity prof: profs) {
if (prof.getUserName().compareTo(username) == 0){
found = prof;
break;
}
}
//List<ProfEntity> profs = Core.Prof.getAll();
ProfEntity found = Core.Prof.getLoginPair(username, password);
if (found != null) {
if (found.getPassword().compareTo(password) == 0) {
authentified = true;
connected = found;
spark.Session s = req.session(true);
s.attribute("user",found.getUserName());
String id = s.id();
res.cookie("session-id",id);
res.redirect("/welcome");
System.out.println(found);
return null;
}
}
return "<!DOCTYPE html><html>Incorrect<a href=\'/login\'>Reessayer</a></html>";
});
get("/eleves",(req,res)->{
if (authentified) {
if (verificationSession(req)) {
return EleveGUI.getAllEleves();
}
else {
......@@ -157,7 +164,7 @@ public class StartServer {
});
post("/eleves/gommette/ajout", (req,res)->{
if (!authentified)
if (!verificationSession(req))
{
res.redirect("/login");
return null;
......@@ -204,7 +211,7 @@ public class StartServer {
get("/gommettes", (req,res) ->{
if (authentified) {
if (verificationSession(req)) {
return GommetteGUI.getAllGommettes();
}
else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment