Commit 072e7fc2bad8cab7d490ca189da9f38cf86b4b2b

Authored by Unknown
1 parent 02a70d4c

Passage de pseudo à email pour les utilisateurs

PFE06/src/main/java/com/PFE/ServerManager/Customer.java
... ... @@ -16,8 +16,8 @@ public class Customer{
16 16 @Basic(optional = false)
17 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 22 @Column(name = "password")
23 23 private String password;
... ... @@ -40,10 +40,10 @@ public class Customer{
40 40 }
41 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 48 public void setPassword(String password) {
49 49 this.password = password;
... ...
PFE06/src/main/java/com/PFE/ServerManager/CustomerRepository.java
1 1 package com.PFE.ServerManager;
2 2  
3 3 import org.springframework.data.jpa.repository.JpaRepository;
4   -import org.springframework.data.repository.CrudRepository;
5 4 import org.springframework.stereotype.Repository;
6 5  
7 6 // This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository
... ... @@ -12,6 +11,6 @@ import org.springframework.stereotype.Repository;
12 11 @Repository
13 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 39 public ModelAndView home() {
40 40 ModelAndView modelAndView = new ModelAndView();
41 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 44 modelAndView.addObject("customerRole", customer.getRole());
45 45 modelAndView.setViewName("home");
46 46 return modelAndView;
... ... @@ -50,8 +50,8 @@ public class MainController {
50 50 public ModelAndView registration() {
51 51 ModelAndView modelAndView = new ModelAndView();
52 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 55 modelAndView.addObject("customerRole", customer.getRole());
56 56 modelAndView.setViewName("registration");
57 57 return modelAndView;
... ... @@ -63,24 +63,24 @@ public class MainController {
63 63 }
64 64  
65 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 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 68 ModelAndView modelAndView = new ModelAndView(); // il n'est peut être pas utile d'utiliser ModelAndView
69 69 Customer n = new Customer();
70   - n.setPseudo(pseudo);
  70 + n.setEmail(email);
71 71 n.setPassword(bCryptPasswordEncoder.encode(password));
72   - n.setId((int)(customerRepository.count()+1));
  72 + n.setId((int)(customerRepository.count() + 1));
73 73 n.setActive(1);
74   - Customer temp = customerRepository.findByPseudo(pseudo);
  74 + Customer temp = customerRepository.findByEmail(email);
75 75 Role userRole = roleRepository.findByRole(role);
76 76 n.setRoles(new HashSet<Role>(Arrays.asList(userRole)));
77 77 //utilisé uniquement pour continuer à afficher l'utilisateur connecté//
78 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 81 modelAndView.addObject("customerRole", customer.getRole());
82 82 modelAndView.setViewName("registration");
83   - ///////
  83 +
84 84 if(temp != null) {
85 85 modelAndView.addObject("message", "L'utilisateur existe déjà !");
86 86 modelAndView.addObject("fail", true);
... ... @@ -102,9 +102,9 @@ public class MainController {
102 102  
103 103  
104 104 Authentication auth = SecurityContextHolder.getContext().getAuthentication();
105   - Customer customer = customerRepository.findByPseudo(auth.getName());
  105 + Customer customer = customerRepository.findByEmail(auth.getName());
106 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 108 dirs.mkdirs();
109 109 OutputStream outputStream = null;
110 110 InputStream inputStream = null;
... ... @@ -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 156 modelAndView.setViewName("all");
158 157  
159 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 161 modelAndView.addObject("customerRole", customer.getRole());
163 162  
164 163 /*List<Customer> list = new ArrayList<Customer>();
... ... @@ -167,7 +166,7 @@ public class MainController {
167 166 list.add(listIterator.next());
168 167 }*/
169 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 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 8 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9 9 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
10 10 import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
11   -
12 11 import javax.sql.DataSource;
13 12  
14 13 @Configuration
... ... @@ -26,8 +25,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
26 25 auth.jdbcAuthentication()
27 26 .dataSource(dataSource)
28 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 32 @Override
... ... @@ -45,7 +44,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
45 44 .formLogin()
46 45 .loginPage("/login").failureUrl("/login?error=true")
47 46 .defaultSuccessUrl("/home")
48   - .usernameParameter("pseudo")
  47 + .usernameParameter("email")
49 48 .passwordParameter("password")
50 49 .and()
51 50 .logout()
... ...
PFE06/src/main/resources/data.sql
1 1 /* ce fichier doit être placé dans les ressources afin d'être utilisé */
2 2 INSERT INTO "role" VALUES (1,'ADMIN');
3 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 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 7 INSERT INTO "customer_role" VALUES (2,2);
8 8 \ No newline at end of file
... ...
PFE06/src/main/resources/templates/login.html
... ... @@ -29,11 +29,11 @@
29 29 <form id="Login" th:action="@{/login}" method="POST">
30 30  
31 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 33 </div>
34 34  
35 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 37 </div>
38 38  
39 39 <button @click.prevent="login" type="submit" class="btn btn-primary">Se connecter</button>
... ...