Commit 072e7fc2bad8cab7d490ca189da9f38cf86b4b2b
1 parent
02a70d4c
Passage de pseudo à email pour les utilisateurs
Showing
6 changed files
with
29 additions
and
32 deletions
Show diff stats
PFE06/src/main/java/com/PFE/ServerManager/Customer.java
@@ -16,8 +16,8 @@ public class Customer{ | @@ -16,8 +16,8 @@ public class Customer{ | ||
16 | @Basic(optional = false) | 16 | @Basic(optional = false) |
17 | private Integer customer_id; | 17 | private Integer customer_id; |
18 | 18 | ||
19 | - @Column(name = "pseudo") | ||
20 | - private String pseudo; | 19 | + @Column(name = "email") |
20 | + private String email; | ||
21 | 21 | ||
22 | @Column(name = "password") | 22 | @Column(name = "password") |
23 | private String password; | 23 | private String password; |
@@ -40,10 +40,10 @@ public class Customer{ | @@ -40,10 +40,10 @@ public class Customer{ | ||
40 | } | 40 | } |
41 | public Integer getCustomer_id() { return customer_id; } | 41 | public Integer getCustomer_id() { return customer_id; } |
42 | 42 | ||
43 | - public void setPseudo(String pseudo) { | ||
44 | - this.pseudo = pseudo; | 43 | + public void setEmail(String email) { |
44 | + this.email = email; | ||
45 | } | 45 | } |
46 | - public String getPseudo() { return pseudo; } | 46 | + public String getEmail() { return email; } |
47 | 47 | ||
48 | public void setPassword(String password) { | 48 | public void setPassword(String password) { |
49 | this.password = password; | 49 | this.password = password; |
PFE06/src/main/java/com/PFE/ServerManager/CustomerRepository.java
1 | package com.PFE.ServerManager; | 1 | package com.PFE.ServerManager; |
2 | 2 | ||
3 | import org.springframework.data.jpa.repository.JpaRepository; | 3 | import org.springframework.data.jpa.repository.JpaRepository; |
4 | -import org.springframework.data.repository.CrudRepository; | ||
5 | import org.springframework.stereotype.Repository; | 4 | import org.springframework.stereotype.Repository; |
6 | 5 | ||
7 | // This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository | 6 | // This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository |
@@ -12,6 +11,6 @@ import org.springframework.stereotype.Repository; | @@ -12,6 +11,6 @@ import org.springframework.stereotype.Repository; | ||
12 | @Repository | 11 | @Repository |
13 | public interface CustomerRepository extends JpaRepository<Customer, Integer> { | 12 | public interface CustomerRepository extends JpaRepository<Customer, Integer> { |
14 | 13 | ||
15 | - Customer findByPseudo(String pseudo); | 14 | + Customer findByEmail(String email); |
16 | 15 | ||
17 | } | 16 | } |
PFE06/src/main/java/com/PFE/ServerManager/MainController.java
@@ -39,8 +39,8 @@ public class MainController { | @@ -39,8 +39,8 @@ public class MainController { | ||
39 | public ModelAndView home() { | 39 | public ModelAndView home() { |
40 | ModelAndView modelAndView = new ModelAndView(); | 40 | ModelAndView modelAndView = new ModelAndView(); |
41 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | 41 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
42 | - Customer customer = customerRepository.findByPseudo(auth.getName()); | ||
43 | - modelAndView.addObject("customerName", customer.getPseudo()); | 42 | + Customer customer = customerRepository.findByEmail(auth.getName()); |
43 | + modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); | ||
44 | modelAndView.addObject("customerRole", customer.getRole()); | 44 | modelAndView.addObject("customerRole", customer.getRole()); |
45 | modelAndView.setViewName("home"); | 45 | modelAndView.setViewName("home"); |
46 | return modelAndView; | 46 | return modelAndView; |
@@ -50,8 +50,8 @@ public class MainController { | @@ -50,8 +50,8 @@ public class MainController { | ||
50 | public ModelAndView registration() { | 50 | public ModelAndView registration() { |
51 | ModelAndView modelAndView = new ModelAndView(); | 51 | ModelAndView modelAndView = new ModelAndView(); |
52 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | 52 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
53 | - Customer customer = customerRepository.findByPseudo(auth.getName()); | ||
54 | - modelAndView.addObject("customerName", customer.getPseudo()); | 53 | + Customer customer = customerRepository.findByEmail(auth.getName()); |
54 | + modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); | ||
55 | modelAndView.addObject("customerRole", customer.getRole()); | 55 | modelAndView.addObject("customerRole", customer.getRole()); |
56 | modelAndView.setViewName("registration"); | 56 | modelAndView.setViewName("registration"); |
57 | return modelAndView; | 57 | return modelAndView; |
@@ -63,24 +63,24 @@ public class MainController { | @@ -63,24 +63,24 @@ public class MainController { | ||
63 | } | 63 | } |
64 | 64 | ||
65 | @PostMapping(path="/registration") | 65 | @PostMapping(path="/registration") |
66 | - public ModelAndView addNewUser(@RequestParam String pseudo, @RequestParam String password, @RequestParam String role) { | 66 | + public ModelAndView addNewUser(@RequestParam String email, @RequestParam String password, @RequestParam String role) { |
67 | //Model map, ModelAndView ou l'utilisation direct comme dans la méthode précédente sont 3 méthodes qui permettent d'envoyer des informations et donc de changer l'apparence d'une page | 67 | //Model map, ModelAndView ou l'utilisation direct comme dans la méthode précédente sont 3 méthodes qui permettent d'envoyer des informations et donc de changer l'apparence d'une page |
68 | ModelAndView modelAndView = new ModelAndView(); // il n'est peut être pas utile d'utiliser ModelAndView | 68 | ModelAndView modelAndView = new ModelAndView(); // il n'est peut être pas utile d'utiliser ModelAndView |
69 | Customer n = new Customer(); | 69 | Customer n = new Customer(); |
70 | - n.setPseudo(pseudo); | 70 | + n.setEmail(email); |
71 | n.setPassword(bCryptPasswordEncoder.encode(password)); | 71 | n.setPassword(bCryptPasswordEncoder.encode(password)); |
72 | - n.setId((int)(customerRepository.count()+1)); | 72 | + n.setId((int)(customerRepository.count() + 1)); |
73 | n.setActive(1); | 73 | n.setActive(1); |
74 | - Customer temp = customerRepository.findByPseudo(pseudo); | 74 | + Customer temp = customerRepository.findByEmail(email); |
75 | Role userRole = roleRepository.findByRole(role); | 75 | Role userRole = roleRepository.findByRole(role); |
76 | n.setRoles(new HashSet<Role>(Arrays.asList(userRole))); | 76 | n.setRoles(new HashSet<Role>(Arrays.asList(userRole))); |
77 | //utilisé uniquement pour continuer à afficher l'utilisateur connecté// | 77 | //utilisé uniquement pour continuer à afficher l'utilisateur connecté// |
78 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | 78 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
79 | - Customer customer = customerRepository.findByPseudo(auth.getName()); | ||
80 | - modelAndView.addObject("customerName", customer.getPseudo()); | 79 | + Customer customer = customerRepository.findByEmail(auth.getName()); |
80 | + modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); | ||
81 | modelAndView.addObject("customerRole", customer.getRole()); | 81 | modelAndView.addObject("customerRole", customer.getRole()); |
82 | modelAndView.setViewName("registration"); | 82 | modelAndView.setViewName("registration"); |
83 | - /////// | 83 | + |
84 | if(temp != null) { | 84 | if(temp != null) { |
85 | modelAndView.addObject("message", "L'utilisateur existe déjà !"); | 85 | modelAndView.addObject("message", "L'utilisateur existe déjà !"); |
86 | modelAndView.addObject("fail", true); | 86 | modelAndView.addObject("fail", true); |
@@ -102,9 +102,9 @@ public class MainController { | @@ -102,9 +102,9 @@ public class MainController { | ||
102 | 102 | ||
103 | 103 | ||
104 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | 104 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
105 | - Customer customer = customerRepository.findByPseudo(auth.getName()); | 105 | + Customer customer = customerRepository.findByEmail(auth.getName()); |
106 | Timestamp timestamp = new Timestamp(System.currentTimeMillis()); | 106 | Timestamp timestamp = new Timestamp(System.currentTimeMillis()); |
107 | - File dirs = new File("files/" + customer.getPseudo() + "_" + timestamp.getTime()); | 107 | + File dirs = new File("files/" + customer.getEmail().split("@")[0] + "_" + timestamp.getTime()); |
108 | dirs.mkdirs(); | 108 | dirs.mkdirs(); |
109 | OutputStream outputStream = null; | 109 | OutputStream outputStream = null; |
110 | InputStream inputStream = null; | 110 | InputStream inputStream = null; |
@@ -136,7 +136,6 @@ public class MainController { | @@ -136,7 +136,6 @@ public class MainController { | ||
136 | 136 | ||
137 | } | 137 | } |
138 | } | 138 | } |
139 | - | ||
140 | } | 139 | } |
141 | 140 | ||
142 | 141 | ||
@@ -157,8 +156,8 @@ public class MainController { | @@ -157,8 +156,8 @@ public class MainController { | ||
157 | modelAndView.setViewName("all"); | 156 | modelAndView.setViewName("all"); |
158 | 157 | ||
159 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | 158 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); |
160 | - Customer customer = customerRepository.findByPseudo(auth.getName()); | ||
161 | - modelAndView.addObject("customerName", customer.getPseudo()); | 159 | + Customer customer = customerRepository.findByEmail(auth.getName()); |
160 | + modelAndView.addObject("customerName", customer.getEmail().split("@")[0]); | ||
162 | modelAndView.addObject("customerRole", customer.getRole()); | 161 | modelAndView.addObject("customerRole", customer.getRole()); |
163 | 162 | ||
164 | /*List<Customer> list = new ArrayList<Customer>(); | 163 | /*List<Customer> list = new ArrayList<Customer>(); |
@@ -167,7 +166,7 @@ public class MainController { | @@ -167,7 +166,7 @@ public class MainController { | ||
167 | list.add(listIterator.next()); | 166 | list.add(listIterator.next()); |
168 | }*/ | 167 | }*/ |
169 | List<Customer> list = customerRepository.findAll(); // attention : la méthode findAll() de JpaRepository retourne une liste alors que celle de CrudRepository retourne un itérable | 168 | List<Customer> list = customerRepository.findAll(); // attention : la méthode findAll() de JpaRepository retourne une liste alors que celle de CrudRepository retourne un itérable |
170 | - modelAndView.addObject("list",list); | 169 | + modelAndView.addObject("list", list); |
171 | return modelAndView; | 170 | return modelAndView; |
172 | } | 171 | } |
173 | 172 |
PFE06/src/main/java/com/PFE/ServerManager/SecurityConfig.java
@@ -8,7 +8,6 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; | @@ -8,7 +8,6 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | 8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
9 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | 9 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
10 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher; | 10 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher; |
11 | - | ||
12 | import javax.sql.DataSource; | 11 | import javax.sql.DataSource; |
13 | 12 | ||
14 | @Configuration | 13 | @Configuration |
@@ -26,8 +25,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { | @@ -26,8 +25,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { | ||
26 | auth.jdbcAuthentication() | 25 | auth.jdbcAuthentication() |
27 | .dataSource(dataSource) | 26 | .dataSource(dataSource) |
28 | .passwordEncoder(passwordEncoder) | 27 | .passwordEncoder(passwordEncoder) |
29 | - .usersByUsernameQuery("select pseudo, password , active from customer where pseudo=?") | ||
30 | - .authoritiesByUsernameQuery("select c.pseudo, r.role from customer c inner join customer_role cr on(c.customer_id=cr.customer_id) inner join role r on(cr.role_id=r.role_id) where c.pseudo=?"); | 28 | + .usersByUsernameQuery("select email, password , active from customer where email=?") |
29 | + .authoritiesByUsernameQuery("select c.email, r.role from customer c inner join customer_role cr on(c.customer_id=cr.customer_id) inner join role r on(cr.role_id=r.role_id) where c.email=?"); | ||
31 | } | 30 | } |
32 | 31 | ||
33 | @Override | 32 | @Override |
@@ -45,7 +44,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { | @@ -45,7 +44,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { | ||
45 | .formLogin() | 44 | .formLogin() |
46 | .loginPage("/login").failureUrl("/login?error=true") | 45 | .loginPage("/login").failureUrl("/login?error=true") |
47 | .defaultSuccessUrl("/home") | 46 | .defaultSuccessUrl("/home") |
48 | - .usernameParameter("pseudo") | 47 | + .usernameParameter("email") |
49 | .passwordParameter("password") | 48 | .passwordParameter("password") |
50 | .and() | 49 | .and() |
51 | .logout() | 50 | .logout() |
PFE06/src/main/resources/data.sql
1 | /* ce fichier doit être placé dans les ressources afin d'être utilisé */ | 1 | /* ce fichier doit être placé dans les ressources afin d'être utilisé */ |
2 | INSERT INTO "role" VALUES (1,'ADMIN'); | 2 | INSERT INTO "role" VALUES (1,'ADMIN'); |
3 | INSERT INTO "role" VALUES (2,'USER'); | 3 | INSERT INTO "role" VALUES (2,'USER'); |
4 | -INSERT INTO "customer" VALUES (1,1,'$2a$10$GflhaD2IYuErynuOlxS2W.Gp1kXksVdiSviYN/lDYCsuH.lVm6Ph2','admin'); /*pseudo : admin // password : admin // role : ADMIN*/ | 4 | +INSERT INTO "customer" VALUES (1,1,'admin@admin.fr','$2a$10$GflhaD2IYuErynuOlxS2W.Gp1kXksVdiSviYN/lDYCsuH.lVm6Ph2'); /*pseudo : admin // password : admin // role : ADMIN*/ |
5 | INSERT INTO "customer_role" VALUES (1,1); | 5 | INSERT INTO "customer_role" VALUES (1,1); |
6 | -INSERT INTO "customer" VALUES (2,1,'$2a$10$0Fnls/gTQS1zA6rj1ZlxfuyyKNpCBDA1tcCqQMroPDIj1fRyhgv/O','user'); /*pseudo : user // password : user // role : USER*/ | 6 | +INSERT INTO "customer" VALUES (2,1,'user@user.fr','$2a$10$0Fnls/gTQS1zA6rj1ZlxfuyyKNpCBDA1tcCqQMroPDIj1fRyhgv/O'); /*pseudo : user // password : user // role : USER*/ |
7 | INSERT INTO "customer_role" VALUES (2,2); | 7 | INSERT INTO "customer_role" VALUES (2,2); |
8 | \ No newline at end of file | 8 | \ No newline at end of file |
PFE06/src/main/resources/templates/login.html
@@ -29,11 +29,11 @@ | @@ -29,11 +29,11 @@ | ||
29 | <form id="Login" th:action="@{/login}" method="POST"> | 29 | <form id="Login" th:action="@{/login}" method="POST"> |
30 | 30 | ||
31 | <div class="form-group"> | 31 | <div class="form-group"> |
32 | - <input type="text" v-model="user.login" class="form-control" id="inputEmail" placeholder="Pseudo" name="pseudo"> | 32 | + <input type="email" class="form-control" id="inputEmail" placeholder="Email" name="email"> |
33 | </div> | 33 | </div> |
34 | 34 | ||
35 | <div class="form-group"> | 35 | <div class="form-group"> |
36 | - <input type="password" v-model="user.password" class="form-control" id="inputPassword" placeholder="Mot de passe" name="password"> | 36 | + <input type="password" class="form-control" id="inputPassword" placeholder="Mot de passe" name="password"> |
37 | </div> | 37 | </div> |
38 | 38 | ||
39 | <button @click.prevent="login" type="submit" class="btn btn-primary">Se connecter</button> | 39 | <button @click.prevent="login" type="submit" class="btn btn-primary">Se connecter</button> |