Skip to content
Snippets Groups Projects
Commit 6b84a06b authored by Maxime Gosselin's avatar Maxime Gosselin
Browse files

On ne peut plus rejoindre un thread si on ne le follow pas

parent d553306a
No related branches found
No related tags found
No related merge requests found
......@@ -52,7 +52,11 @@ public class ThreadController extends HttpServlet {
vue = "WEB-INF/vue/accueil.jsp";
break;
case "open":
vue = "WEB-INF/vue/chat.jsp?id=" + idThread;
if(daoFollower.userIsInThread(username, idThread)){
vue = "WEB-INF/vue/chat.jsp?id=" + idThread;
break;
}
vue = "WEB-INF/vue/fils.jsp";
break;
case "create":
String name = req.getParameter("name");
......
......@@ -99,4 +99,18 @@ public class DaoFollower {
}
return res;
}
public boolean userIsInThread(String username, int idThread){
DS bdd = DS.getInstance();
try(Connection con = bdd.getConnection()) {
PreparedStatement ps = con.prepareStatement("SELECT * FROM followers WHERE id_thread = ? AND username = ?");
ps.setInt(1, idThread);
ps.setString(2, username);
ResultSet rs = ps.executeQuery();
return rs.next();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment