Commit c1d2852e126d62873e8cc8e86fad1d47b0df5959
1 parent
716532ee
Ajout css
Showing
8 changed files
with
98 additions
and
43 deletions
Show diff stats
src/main/java/fr/plil/sio/web/mvc/ApplicationSecurityConfiguration.java
... | ... | @@ -29,6 +29,7 @@ public class ApplicationSecurityConfiguration extends WebSecurityConfigurerAdapt |
29 | 29 | .authorizeRequests() |
30 | 30 | .antMatchers("/webjars/**").permitAll() |
31 | 31 | .antMatchers("/js/**").permitAll() |
32 | + .antMatchers("/css/**").permitAll() | |
32 | 33 | .anyRequest().authenticated() |
33 | 34 | .and() |
34 | 35 | .formLogin() | ... | ... |
src/main/java/fr/plil/sio/web/mvc/Dette.java
1 | 1 | package fr.plil.sio.web.mvc; |
2 | 2 | |
3 | +import com.fasterxml.jackson.annotation.JsonManagedReference; | |
3 | 4 | import java.util.Objects; |
4 | 5 | import javax.persistence.*; |
5 | 6 | |
... | ... | @@ -16,9 +17,11 @@ public class Dette { |
16 | 17 | |
17 | 18 | |
18 | 19 | @ManyToOne(optional = false) |
20 | + @JsonManagedReference | |
19 | 21 | private User creditor; |
20 | 22 | |
21 | 23 | @ManyToOne(optional = false) |
24 | + @JsonManagedReference | |
22 | 25 | private User borrower; |
23 | 26 | |
24 | 27 | @Override | ... | ... |
src/main/java/fr/plil/sio/web/mvc/User.java
1 | 1 | package fr.plil.sio.web.mvc; |
2 | 2 | |
3 | 3 | |
4 | +import com.fasterxml.jackson.annotation.JsonBackReference; | |
4 | 5 | import com.fasterxml.jackson.annotation.JsonManagedReference; |
5 | 6 | import java.util.ArrayList; |
6 | 7 | import org.springframework.security.core.GrantedAuthority; |
... | ... | @@ -27,8 +28,9 @@ public class User implements UserDetails { |
27 | 28 | @Column(name = "PASSWORD_F") |
28 | 29 | private String password; |
29 | 30 | |
30 | - @OneToMany(mappedBy="holderOfDebt",cascade = CascadeType.REMOVE) | |
31 | - private List<Dette> dettes = new ArrayList<Dette>(); | |
31 | + @OneToMany(mappedBy="borrower",cascade = CascadeType.REMOVE) | |
32 | + @JsonBackReference | |
33 | + private List<Dette> dettes = new ArrayList<>(); | |
32 | 34 | |
33 | 35 | public List<Dette> getDettes() { |
34 | 36 | return dettes; | ... | ... |
src/main/java/fr/plil/sio/web/mvc/UserServiceImpl.java
... | ... | @@ -14,6 +14,9 @@ public class UserServiceImpl implements UserService { |
14 | 14 | |
15 | 15 | @Resource |
16 | 16 | private UserRepository userRepository; |
17 | + | |
18 | + @Resource | |
19 | + private DetteRepository detteRepository; | |
17 | 20 | |
18 | 21 | @Resource |
19 | 22 | private RoleRepository roleRepository; |
... | ... | @@ -47,8 +50,8 @@ public class UserServiceImpl implements UserService { |
47 | 50 | @Transactional(readOnly = true) |
48 | 51 | public List<Dette> findDettes() { |
49 | 52 | String username = securityService.findLoggedInUsername(); |
50 | - List<Dette> dettes = userRepository.findByUsername(username).getDettes(); | |
51 | - return dettes; | |
53 | + User user = userRepository.findByUsername(username); | |
54 | + return detteRepository.findByBorrower(user); | |
52 | 55 | } |
53 | 56 | |
54 | 57 | @Override |
... | ... | @@ -61,22 +64,19 @@ public class UserServiceImpl implements UserService { |
61 | 64 | @Transactional |
62 | 65 | public Dette addDette(String username, String sommeDette) { |
63 | 66 | //Get the holder of debt |
64 | -// User user = userRepository.findByUsername(username); | |
65 | -// | |
66 | -// //Get connected user | |
67 | -// // Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | |
68 | -// String connectedUsername = securityService.findLoggedInUsername(); | |
69 | -// User connectedUser = userRepository.findByUsername(connectedUsername); | |
70 | -// //Set dette | |
71 | -// List<Dette> newDettes = user.getDettes(); | |
72 | -// Dette d = new Dette(); | |
73 | -// Double dSomme = Double.parseDouble(sommeDette); | |
74 | -// d.setSommeDette(dSomme); | |
75 | -// d.setHolderOfDebt(connectedUser); | |
76 | -// d.setDueToUser(user); | |
77 | -// newDettes.add(d); | |
78 | - | |
79 | - return new Dette(); | |
67 | + User user = userRepository.findByUsername(username); | |
68 | + | |
69 | + String connectedUsername = securityService.findLoggedInUsername(); | |
70 | + User connectedUser = userRepository.findByUsername(connectedUsername); | |
71 | + | |
72 | + Dette d = new Dette(); | |
73 | + Double dSomme = Double.parseDouble(sommeDette); | |
74 | + d.setSommeDette(dSomme); | |
75 | + d.setBorrower(connectedUser); | |
76 | + d.setCreditor(user); | |
77 | + | |
78 | + detteRepository.save(d); | |
79 | + return d; | |
80 | 80 | } |
81 | 81 | |
82 | 82 | } | ... | ... |
src/main/webapp/WEB-INF/pages/header.jsp
... | ... | @@ -5,5 +5,7 @@ |
5 | 5 | <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
6 | 6 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
7 | 7 | <title><%= request.getAttribute("pageTitle") %></title> |
8 | + <link href="/webjars/bootstrap/css/bootstrap.min.css" rel="stylesheet"/> | |
9 | + <link href="/css/kawafile.css" rel="stylesheet"/> | |
8 | 10 | </head> |
9 | 11 | <a href="login.jsp"></a> |
10 | 12 | \ No newline at end of file | ... | ... |
src/main/webapp/WEB-INF/pages/login.jsp
... | ... | @@ -6,19 +6,36 @@ |
6 | 6 | </jsp:include> |
7 | 7 | |
8 | 8 | <c:url value="/login" var="loginUrl"/> |
9 | -<form action="${loginUrl}" method="post"> | |
10 | - <b><c:out value="${message}"></c:out></b> | |
11 | - <p> | |
12 | - <label for="username">Username</label> | |
13 | - <input type="text" id="username" name="username"/> | |
14 | - </p> | |
15 | - <p> | |
16 | - <label for="password">Password</label> | |
17 | - <input type="password" id="password" name="password"/> | |
18 | - </p> | |
19 | - <input type="hidden" | |
20 | - name="${_csrf.parameterName}" | |
21 | - value="${_csrf.token}"/> | |
22 | - <button type="submit" class="btn">Log in</button> | |
23 | -</form> | |
9 | + | |
10 | + | |
11 | +<div class="container-fluid"/> | |
12 | + | |
13 | + | |
14 | +<h1 class="name">CONNEXION</h1> | |
15 | + <div class="panel panel-info signInForm "> | |
16 | + <div class="panel-body"> | |
17 | + <form action="${loginUrl}" method="post" > | |
18 | + <b><c:out value="${message}"></c:out></b> | |
19 | + <div class="form-group"> | |
20 | + <label for="username">Username</label> | |
21 | + <input class="form-control" type="text" id="username" name="username"/> | |
22 | + </div> | |
23 | + <div class="form-group"> | |
24 | + <label for="password">Password</label> | |
25 | + <input class="form-control" type="password" id="password" name="password"/> | |
26 | + </div> | |
27 | + <input type="hidden" | |
28 | + name="${_csrf.parameterName}" | |
29 | + value="${_csrf.token}"/> | |
30 | + <div class="text-center"> | |
31 | + <button type="submit" class="btn btn-info">Log in</button> | |
32 | + </div> | |
33 | + </form> | |
34 | + </div> | |
35 | + </div> | |
36 | + | |
37 | + | |
38 | +</div> | |
39 | + | |
40 | + | |
24 | 41 | <jsp:include page="footer.jsp"/> |
25 | 42 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +body{ | |
2 | + background-color:#9cd2d2; | |
3 | +} | |
4 | +.signInForm { | |
5 | + width:500px; | |
6 | + height:250px; | |
7 | + position: absolute; | |
8 | + top:-150px; | |
9 | + bottom: 0; | |
10 | + left: 0; | |
11 | + right: 0; | |
12 | + | |
13 | + margin: auto; | |
14 | +} | |
15 | + | |
16 | +.name{ | |
17 | + display: block; | |
18 | + font-family: Montserrat,"Helvetica Neue",Helvetica,Arial,sans-serif; | |
19 | + text-transform: uppercase; | |
20 | + font-weight: 700; | |
21 | + font-size: 3.5em; | |
22 | + | |
23 | + text-align:center; | |
24 | + color:white; | |
25 | + margin-top:200px; | |
26 | +} | |
0 | 27 | \ No newline at end of file | ... | ... |
src/main/webapp/js/kawafile.js
... | ... | @@ -6,11 +6,13 @@ function getDebtsOfUser(){ |
6 | 6 | $.getJSON(url,function(d){ |
7 | 7 | html+="<ul>"; |
8 | 8 | $.each(d,function(index,item){ |
9 | - html+="<li>"+item.holderOfDebt.username+"</li>"; | |
9 | + html+="<li>"+item.creditor.username+"</li>"; | |
10 | 10 | html+="<li>"+item.sommeDette+"</li>"; |
11 | 11 | }); |
12 | - }); | |
12 | + html+="</ul>"; | |
13 | 13 | $("#dettes").html(html); |
14 | + }); | |
15 | + | |
14 | 16 | } |
15 | 17 | |
16 | 18 | function updateDebtOfUser(){ |
... | ... | @@ -42,16 +44,18 @@ function updateDebtOfUser(){ |
42 | 44 | url:url, |
43 | 45 | method:"POST", |
44 | 46 | data:requestData, |
45 | - async:false, | |
46 | - }).done(function(d){ | |
47 | - alert("Ok"); | |
48 | - getDebtsOfUser(); | |
47 | + async:false | |
48 | + }).done(function(d){ | |
49 | + console.log(d); | |
49 | 50 | }).success(function(d){ |
50 | - getDebtsOfUser(); | |
51 | + console.log("Succes"); | |
52 | + console.log(d); | |
51 | 53 | }).fail(function(d){ |
52 | 54 | alert("Erreur"); |
55 | + console.log("Fail"); | |
56 | + console.log(d); | |
53 | 57 | }); |
54 | - getDebtsOfUser(); | |
58 | + //getDebtsOfUser(); | |
55 | 59 | } |
56 | 60 | |
57 | 61 | ... | ... |