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

Plus d'authentified ni de connected

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