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

Ajout du mot de passe pour les profs / formulaire de login (temporaire) / ...

Ajout du mot de passe pour les profs / formulaire de login (temporaire) /  authentification (temporaire) / accès au ressources(profs) que si authentifié(e)
parent 662f8470
No related branches found
No related tags found
No related merge requests found
Showing
with 96 additions and 9 deletions
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
File added
<#ftl encoding="utf-8">
<body xmlns="http://www.w3.org/1999/html">
<form method="post" action="/login">
<label for="userName">Nom d'utilisateur</label>
<input name="userName">
<label for="password">Mot de passe</label>
<input name="password">
<button type="submit" placeholder="Supprimer...">Envoyer</button>
</form>
</body>
</html>
......@@ -11,8 +11,10 @@
</ul>
<form method="post" action="prof/delete">
<form method="post" action="profs/delete">
<label for="id">id</label>
<input name="id">
<button type="submit" placeholder="Supprimer...">Envoyer</button>
</form>
</body>
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
File added
<#ftl encoding="utf-8">
<body xmlns="http://www.w3.org/1999/html">
<form method="post" action="/login">
<label for="userName">Nom d'utilisateur</label>
<input name="userName">
<label for="password">Mot de passe</label>
<input name="password">
<button type="submit" placeholder="Supprimer...">Envoyer</button>
</form>
</body>
</html>
No preview for this file type
......@@ -5,18 +5,22 @@ import com.uca.gui.*;
import com.uca.core.*;
import com.uca.entity.*;
import java.sql.*;
import java.util.*;
import static spark.Spark.*;
public class StartServer {
//.\gradlew run
public static boolean authentified = false;
public static void displayLocalHost(int portNb, String suffix)
{
System.out.println("http://localhost:"+portNb+"/"+suffix);
}
public static void main(String[] args) {
int portNb = 8081;
//Configure Spark
staticFiles.location("/static/");
......@@ -33,7 +37,16 @@ public class StartServer {
displayLocalHost(portNb, "profs");
get("/profs", (req, res) -> {
return ProfGUI.getAllProfs();
if (authentified)
{
return ProfGUI.getAllProfs();
}
else
{
res.redirect("/login");
return null;
}
});
post("/profs/delete",(req,res) -> {
......@@ -42,6 +55,34 @@ public class StartServer {
return null;
});
displayLocalHost(portNb, "login");
get("/login",(req,res)->{
return LoginGUI.getConnectionPage();
});
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;
}
}
if (found != null) {
if (found.getPassword().compareTo(password) == 0) {
authentified = true;
res.redirect("/profs");
System.out.println(found);
return null;
}
}
return "<!DOCTYPE html><html>Incorrect</html>";
});
}
}
\ No newline at end of file
......@@ -13,11 +13,12 @@ public class ProfCore extends _DefaultCore<ProfEntity> {
super(new ProfDAO());
}
public ProfEntity create(String firstName, String lastName, String userName) {
public ProfEntity create(String firstName, String lastName, String userName, String password) {
ProfEntity entity = new ProfEntity();
entity.setFirstName(firstName);
entity.setLastName (lastName);
entity.setUserName (userName);
entity.setPassword(password);
return dao.create(entity);
}
}
......@@ -13,11 +13,12 @@ public class ProfDAO extends _DefaultDAO<ProfEntity> {
@Override
public void pushUnsafe(ProfEntity obj) throws Exception
{
PreparedStatement stmt = this.connect.prepareStatement("update profs set firstName=?, lastName=?, userName=? where id=?;");
PreparedStatement stmt = this.connect.prepareStatement("update profs set firstName=?, lastName=?, userName=? , password=? where id=?;");
int idx = 1;
stmt.setString(idx++, obj.getFirstName());
stmt.setString(idx++, obj.getLastName());
stmt.setString(idx++, obj.getUserName());
stmt.setString(idx++, obj.getPassword());
stmt.setInt (idx++, obj.getId());
stmt.executeUpdate();
}
......@@ -30,6 +31,8 @@ public class ProfDAO extends _DefaultDAO<ProfEntity> {
entity.setFirstName(resultSet.getString("firstName"));
entity.setLastName(resultSet.getString("lastName"));
entity.setUserName(resultSet.getString("userName"));
entity.setPassword(resultSet.getString("password"));
return entity;
}
}
\ No newline at end of file
......@@ -31,10 +31,10 @@ public class _Initializer {
}
public static void Init(){
//DropTable("users");
//DropTable("profs");
DropTable("users");
DropTable("profs");
CreateTable("CREATE TABLE IF NOT EXISTS users (id int primary key auto_increment, firstname varchar(100), lastname varchar(100));");
CreateTable("CREATE TABLE IF NOT EXISTS profs (id int primary key auto_increment, firstname varchar(100), lastname varchar(100), username varchar(100));");
CreateTable("CREATE TABLE IF NOT EXISTS profs (id int primary key auto_increment, firstname varchar(100), lastname varchar(100), username varchar(100), password varchar(100));");
//CreateTable("CREATE TABLE IF NOT EXISTS eleves(id int primary key auto_increment, firstname varchar(100), lastname varchar(100), nomClasse varchar(100), dateNaissance varchar(10));");
//CreateTable("CREATE TABLE IF NOT EXISTS gommettes(id int primary key auto_increment, nom varchar(100), description varchar(100));");
//CreateTable("CREATE TABLE IF NOT EXISTS gommetteAttribs(id int primary key auto_increment, id idEleve, id idProf, raison varchar(500));");
......@@ -51,7 +51,7 @@ public class _Initializer {
Core.User.create("Terry", "Golo");
Core.User.create("Judas", "Nanas");
Core.Prof.create("Boris", "OUYA", "DaWarudo");
Core.Prof.create("Thomas", "TAMAGNAUD", "CéMoiLul");
Core.Prof.create("Boris", "OUYA", "DaWarudo","");
Core.Prof.create("Thomas", "TAMAGNAUD", "CéMoiLul","FaisMoiMal");
}
}
......@@ -4,8 +4,12 @@ import com.uca.entity.UserEntity;
public class ProfEntity extends UserEntity {
private String UserName;
private String password;
public String getUserName() { return UserName; }
public void setUserName(String value) { UserName = value; }
public void setPassword(String value) { password = value; }
public String getPassword() { return password; }
public ProfEntity() { }
}
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