moved UserWithouPaswword to authenticatorService
This commit is contained in:
		@ -35,7 +35,7 @@ public class UserController {
 | 
				
			|||||||
        User user = authServ.getUserFromToken(token);
 | 
					        User user = authServ.getUserFromToken(token);
 | 
				
			||||||
            if (user == null) return new UnauthorizedResponse<>(null);
 | 
					            if (user == null) return new UnauthorizedResponse<>(null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return new ResponseEntity<>(userWithoutPassword(user), HttpStatus.OK);
 | 
					        return new ResponseEntity<>(authServ.userWithoutPassword(user), HttpStatus.OK);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @PostMapping("/user")
 | 
					    @PostMapping("/user")
 | 
				
			||||||
@ -44,7 +44,7 @@ public class UserController {
 | 
				
			|||||||
        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService,Role.Secretary},token))
 | 
					        if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService,Role.Secretary},token))
 | 
				
			||||||
            return new UnauthorizedResponse<>(null);
 | 
					            return new UnauthorizedResponse<>(null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return new ResponseEntity<>(userWithoutPassword(userService.save(user)),HttpStatus.CREATED);
 | 
					        return new ResponseEntity<>(authServ.userWithoutPassword(userService.save(user)),HttpStatus.CREATED);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @GetMapping("/users")
 | 
					    @GetMapping("/users")
 | 
				
			||||||
@ -57,7 +57,7 @@ public class UserController {
 | 
				
			|||||||
        ArrayList<HashMap<String, Object>> withoutPassword = new ArrayList<>();
 | 
					        ArrayList<HashMap<String, Object>> withoutPassword = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (User u :users){
 | 
					        for (User u :users){
 | 
				
			||||||
            withoutPassword.add(userWithoutPassword(u));
 | 
					            withoutPassword.add(authServ.userWithoutPassword(u));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return new ResponseEntity<>(withoutPassword, HttpStatus.OK);
 | 
					        return new ResponseEntity<>(withoutPassword, HttpStatus.OK);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -95,30 +95,10 @@ public class UserController {
 | 
				
			|||||||
        ArrayList<HashMap<String, Object>> withoutPassword = new ArrayList<>();
 | 
					        ArrayList<HashMap<String, Object>> withoutPassword = new ArrayList<>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (User t: teachers){
 | 
					        for (User t: teachers){
 | 
				
			||||||
            withoutPassword.add(userWithoutPassword(t));
 | 
					            withoutPassword.add(authServ.userWithoutPassword(t));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return new ResponseEntity<>(withoutPassword, HttpStatus.OK);
 | 
					        return new ResponseEntity<>(withoutPassword, HttpStatus.OK);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        /** return user's data except password
 | 
					 | 
				
			||||||
         * @param user the user to return
 | 
					 | 
				
			||||||
         * @return all the user data without the password
 | 
					 | 
				
			||||||
         */
 | 
					 | 
				
			||||||
    private HashMap<String,Object> userWithoutPassword(User user){
 | 
					 | 
				
			||||||
        HashMap<String,Object> toReturn = new HashMap<>();
 | 
					 | 
				
			||||||
        toReturn.put("regNo",user.getRegNo());
 | 
					 | 
				
			||||||
        toReturn.put("lastName",user.getLastName());
 | 
					 | 
				
			||||||
        toReturn.put("firstName",user.getFirstName());
 | 
					 | 
				
			||||||
        toReturn.put("email", user.getEmail());
 | 
					 | 
				
			||||||
        toReturn.put("address",user.getAddress());
 | 
					 | 
				
			||||||
        toReturn.put("birthDate",user.getBirthDate());
 | 
					 | 
				
			||||||
        toReturn.put("country",user.getCountry());
 | 
					 | 
				
			||||||
        toReturn.put("profilePictureUrl",user.getProfilePictureUrl());
 | 
					 | 
				
			||||||
        toReturn.put("role",user.getRole());
 | 
					 | 
				
			||||||
        return toReturn;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@ import ovh.herisson.Clyde.Tables.Token;
 | 
				
			|||||||
import ovh.herisson.Clyde.Tables.User;
 | 
					import ovh.herisson.Clyde.Tables.User;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Date;
 | 
					import java.util.Date;
 | 
				
			||||||
 | 
					import java.util.HashMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Service
 | 
					@Service
 | 
				
			||||||
public class AuthenticatorService {
 | 
					public class AuthenticatorService {
 | 
				
			||||||
@ -52,5 +53,25 @@ public class AuthenticatorService {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** return user's data except password
 | 
				
			||||||
 | 
					     * @param user the user to return
 | 
				
			||||||
 | 
					     * @return all the user data without the password
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public HashMap<String,Object> userWithoutPassword(User user){
 | 
				
			||||||
 | 
					        HashMap<String,Object> toReturn = new HashMap<>();
 | 
				
			||||||
 | 
					        toReturn.put("regNo",user.getRegNo());
 | 
				
			||||||
 | 
					        toReturn.put("lastName",user.getLastName());
 | 
				
			||||||
 | 
					        toReturn.put("firstName",user.getFirstName());
 | 
				
			||||||
 | 
					        toReturn.put("email", user.getEmail());
 | 
				
			||||||
 | 
					        toReturn.put("address",user.getAddress());
 | 
				
			||||||
 | 
					        toReturn.put("birthDate",user.getBirthDate());
 | 
				
			||||||
 | 
					        toReturn.put("country",user.getCountry());
 | 
				
			||||||
 | 
					        toReturn.put("profilePictureUrl",user.getProfilePictureUrl());
 | 
				
			||||||
 | 
					        toReturn.put("role",user.getRole());
 | 
				
			||||||
 | 
					        return toReturn;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user