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

Plus d'authentified ni de connected

parent 00cbec84
Branches main
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ import java.sql.Date; ...@@ -8,6 +8,7 @@ import java.sql.Date;
import java.util.*; import java.util.*;
import static spark.Spark.*; import static spark.Spark.*;
import java.text.*; import java.text.*;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
...@@ -21,8 +22,6 @@ public class StartServer { ...@@ -21,8 +22,6 @@ public class StartServer {
//.\gradlew run //.\gradlew run
public static boolean authentified = false;
public static ProfEntity connected = null;
public static String SEL = "MangeMesCookies"; public static String SEL = "MangeMesCookies";
...@@ -52,10 +51,7 @@ public class StartServer { ...@@ -52,10 +51,7 @@ public class StartServer {
_Initializer.Init(); _Initializer.Init();
// Debug:
connected = _Initializer.DEBUG_BORIS_ADMIN;
authentified = true;
//Defining our routes //Defining our routes
//displayLocalHost(portNb, "users"); //displayLocalHost(portNb, "users");
get("/users", (req, res) -> { get("/users", (req, res) -> {
...@@ -100,6 +96,9 @@ public class StartServer { ...@@ -100,6 +96,9 @@ public class StartServer {
get("/welcome",(req,res) -> { get("/welcome",(req,res) -> {
if (verificationSession(req)) if (verificationSession(req))
{ {
int id = Integer.parseInt(req.session().attribute("user-id").toString());
ProfEntity connected = Core.Prof.getById(id);
return ProfGUI.getWelcomePage(connected); return ProfGUI.getWelcomePage(connected);
} }
else else
...@@ -136,9 +135,8 @@ public class StartServer { ...@@ -136,9 +135,8 @@ public class StartServer {
if (found != null) { if (found != null) {
connected = found;
spark.Session s = req.session(true); spark.Session s = req.session(true);
s.attribute("user",found.getUserName()); s.attribute("user-id",Integer.toString(found.getId()));
String id = s.id(); String id = s.id();
res.cookie("session-id",id); res.cookie("session-id",id);
res.redirect("/welcome"); res.redirect("/welcome");
...@@ -203,10 +201,15 @@ public class StartServer { ...@@ -203,10 +201,15 @@ public class StartServer {
return null; return null;
} }
String raison = req.queryParams("raison"); String raison = req.queryParams("raison");
int idGommette = Integer.parseInt(req.queryParams("idGommette")); int idGommette = Integer.parseInt(req.queryParams("idGommette"));
int idEleve = Integer.parseInt(req.queryParams("idEleve")); int idEleve = Integer.parseInt(req.queryParams("idEleve"));
int id = Integer.parseInt(req.session().attribute("user-id").toString());
ProfEntity connected = Core.Prof.getById(id);
Core.GommetteAttrib.create(idEleve,connected.getId(),idGommette, new java.sql.Date(System.currentTimeMillis()), raison); Core.GommetteAttrib.create(idEleve,connected.getId(),idGommette, new java.sql.Date(System.currentTimeMillis()), raison);
res.redirect("/eleves/"+req.queryParams("idEleve")); res.redirect("/eleves/"+req.queryParams("idEleve"));
return null; return null;
......
...@@ -25,6 +25,8 @@ public class ProfCore extends _DefaultCore<ProfEntity> { ...@@ -25,6 +25,8 @@ public class ProfCore extends _DefaultCore<ProfEntity> {
return dao.create(entity); return dao.create(entity);
} }
public ProfEntity getByLoginPair(String username, String password) throws Exception public ProfEntity getByLoginPair(String username, String password) throws Exception
{ {
String hash_pwd = Hash.hashSHA256(StartServer.SEL + password); String hash_pwd = Hash.hashSHA256(StartServer.SEL + password);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<input name="userName" required> <input name="userName" required>
<label for="password">Mot de passe</label> <label for="password">Mot de passe</label>
<input name="password" type="password" required> <input name="password" type="password" required>
<button type="submit" placeholder="Supprimer...">Envoyer</button> <button type="submit" placeholder="Supprimer...">Envoyer</button>
</form> </form>
......
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