Skip to content
Snippets Groups Projects
Commit 70e18422 authored by Antoine Hazebrouck's avatar Antoine Hazebrouck
Browse files

on voit les notess en passant par les liens

parent 9b54ca4b
No related branches found
No related tags found
No related merge requests found
...@@ -22,7 +22,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { ...@@ -22,7 +22,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
http.authorizeHttpRequests() http.authorizeHttpRequests()
.antMatchers("/admin").hasRole("ADMIN") .antMatchers("/admin").hasRole("ADMIN")
.antMatchers("/user").hasRole("USER") .antMatchers("/user").hasRole("USER")
.antMatchers("/notes").hasRole("USER") .antMatchers("/notes/{id}").hasRole("USER")
.antMatchers("/register_notes").hasRole("USER") .antMatchers("/register_notes").hasRole("USER")
.antMatchers("/").permitAll() .antMatchers("/").permitAll()
.and().formLogin(); .and().formLogin();
......
package jez.authentication2.controllers; package jez.authentication2.controllers;
import java.sql.SQLException; import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import jez.authentication2.services.NotesService; import jez.authentication2.services.NotesService;
...@@ -27,17 +27,20 @@ public class MainController { ...@@ -27,17 +27,20 @@ public class MainController {
return "home.html"; return "home.html";
} }
@GetMapping(value = "/notes") @GetMapping(value = "/notes/{note_id}")
public String displayNotes(Model model) throws SQLException { public String displayNotes(@PathVariable Integer note_id, Model model) throws SQLException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String notes = notesService.getNotes(authentication.getName(), 1); String username = authentication.getName();
String notes = notesService.getNotes(username, note_id);
System.out.println(notes); System.out.println(notes);
System.out.println(userService.getUser(authentication.getName())); System.out.println(note_id);
System.out.println(userService.getUser(username));
model.addAttribute("username", username);
model.addAttribute("notes", notes); model.addAttribute("notes", notes);
model.addAttribute("ids", notesService.getAllIds(authentication.getName())); model.addAttribute("ids", notesService.getAllIds(username));
return "main_page.html"; return "main_page.html";
} }
......
...@@ -3,43 +3,46 @@ ...@@ -3,43 +3,46 @@
<html xmlns:th="http://www.thymeleaf.org"> <html xmlns:th="http://www.thymeleaf.org">
<head> <head>
<meta charset='utf-8'> <meta charset="ISO-8859-1">
<meta http-equiv='X-UA-Compatible' content='IE=edge'> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"
integrity="sha384-eMNCOe7tC1doHpGoWe/6oMVemdAVTMs2xqW4mwXrXsW0L84Iytr2wi5v2QjrP/xp"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.min.js"
integrity="sha384-cn7l7gDp0eyniUwwAZgrzD06kc/tftFf19TOAs2zVinnD/C7E91j9yyk5//jjpt/"
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<title>NotePad</title> <title>NotePad</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src='main.js'></script>
</head> </head>
<body> <body>
<div class="container"> <div class="container-fluid m-4">
<div class="row mt-4"> <div class="row">
<div class="col-2"> <div class="col-10">
<h1 class="h1">NotePad</h1> <h1 class="h1">NotePad</h1>
</div> </div>
<div class="col-9">
</div> <div class="col-2">
<div class="col-1">
<form action="/logout"> <form action="/logout">
<input type="submit" value="Logout"> <input type="submit" value="Logout">
</form> </form>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<!-- A GAUCHE AFFICHER TOUS LES IDS --> <div class="col-2">
<div class="card"> <table class="table table-bordered">
<tr th:each="id: ${ids}"> <tr th:each="id: ${ids}">
<td th:text="${id}"> <td><a href="" th:text="${id}"></a></td>
</tr> </tr>
</table>
</div> </div>
<div class="col-10 m-4"> <div class="col-10">
<!-- afficher le login en haut a gauche -->
<!-- afficher le logout en haut a droite -->
<form action="/register_notes" method="post"> <form action="/register_notes" method="post">
<textarea id="notes" name="notes" rows="..." cols="150" th:text="${notes}"> ... </textarea> <textarea id="notes" name="notes" rows="..." cols="150" th:text="${notes}"> ... </textarea>
<br> <br>
...@@ -47,8 +50,28 @@ ...@@ -47,8 +50,28 @@
<input type="submit" value="Submit"> <input type="submit" value="Submit">
</form> </form>
</div> </div>
</div>
<!-- header -->
<!-- <div class="row">
<div class="col mx-auto">
<div class="col-1">
</div>
<div class="col-8">
</div> </div>
<div class="col-1">
</div>
</div>
</div> -->
</div> </div>
</body> </body>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment