diff --git a/bazaDanych.mv.db b/bazaDanych.mv.db deleted file mode 100644 index c6afb15..0000000 Binary files a/bazaDanych.mv.db and /dev/null differ diff --git a/pom.xml b/pom.xml index 81ab720..a718de3 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,12 @@ + + org.springframework.boot + spring-boot-devtools + + + diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/MyUserDetailService.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/MyUserDetailService.java index 9aa13b8..4a135e0 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/MyUserDetailService.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/MyUserDetailService.java @@ -21,4 +21,8 @@ public UserDetails loadUserByUsername(String username) { } return new MyUserPrincipal(user); } + + + + } diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/SecurityConfiguration.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/SecurityConfiguration.java index 0df3a12..66e1c22 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/SecurityConfiguration.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/SecurityConfiguration.java @@ -34,7 +34,7 @@ protected void configure(HttpSecurity httpSecurity) throws Exception { httpSecurity.csrf().disable(); httpSecurity.authorizeRequests() - .antMatchers("/trucks/all","/session/player/**","/order/all").permitAll() + .antMatchers("/trucks/all","/session/player/**","/order/all","/register","/login").permitAll() .anyRequest().authenticated() .and() .formLogin().permitAll() diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/TruckforwarderBackendApplication.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/TruckforwarderBackendApplication.java index 803718b..884936a 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/TruckforwarderBackendApplication.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/TruckforwarderBackendApplication.java @@ -21,7 +21,6 @@ public class TruckforwarderBackendApplication { - public static void main(String[] args) { SpringApplication.run(TruckforwarderBackendApplication.class, args); } @@ -42,4 +41,5 @@ public FilterRegistrationBean simpleCorsFilter() { return bean; } + } diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/PlayerController.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/PlayerController.java index 5db4606..8c801bc 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/PlayerController.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/PlayerController.java @@ -63,11 +63,9 @@ public void postPurchaseTruck(@RequestBody String SelectedTruck){ String selectedTruckByUser; stringBuilder.append(SelectedTruck); stringBuilder.delete(0,18); - stringBuilder.delete(stringBuilder.length()-2,stringBuilder.length()); // Format String from Post to correctly form + stringBuilder.delete(stringBuilder.length()-2,stringBuilder.length()); selectedTruckByUser = stringBuilder.toString(); - BoughtTrucks boughtTrucks = new BoughtTrucks(); - boughtTrucks.setIdbought_trucks(Math.toIntExact(boughtTrucksRepository.count() + 1)); boughtTrucks.setIdtrucks(truckRepository.findByName(selectedTruckByUser).getID()); boughtTrucks.setIdplayers(playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()).getIdplayers()); @@ -77,12 +75,11 @@ public void postPurchaseTruck(@RequestBody String SelectedTruck){ boughtTrucksRepository.save(boughtTrucks); // Add Bought Truck - playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()). setCash(playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()).getCash() - - truckRepository.findByName(selectedTruckByUser).getPrice()); // Set Cash Status + truckRepository.findByName(selectedTruckByUser).getPrice()); - playerRepository.save(playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName())); // Update Cash Status + playerRepository.save(playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName())); diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/UserController.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/UserController.java index 749e9d4..06b9d0c 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/UserController.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/UserController.java @@ -2,17 +2,15 @@ import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContext; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.web.bind.annotation.*; import pl.staszczykpiotr.truckforwarder_backend.dto.Player; import pl.staszczykpiotr.truckforwarder_backend.dto.User; -import pl.staszczykpiotr.truckforwarder_backend.repository.BoughtTrucksRepository; import pl.staszczykpiotr.truckforwarder_backend.repository.PlayerRepository; - -import java.security.Principal; +import pl.staszczykpiotr.truckforwarder_backend.repository.UserRepository; @CrossOrigin @RestController @@ -20,42 +18,57 @@ @RequestMapping("/principal") public class UserController { private PlayerRepository playerRepository; + private UserRepository userRepository; @Autowired - public UserController(PlayerRepository playerRepository) { + public UserController(PlayerRepository playerRepository, UserRepository userRepository) { this.playerRepository = playerRepository; + this.userRepository = userRepository; } - @GetMapping - public User transferPrincipal(@RequestParam String username, @RequestParam String password){ - User httpEntryUser = new User(); + @PostMapping("/login") + public String loginUser(@RequestBody String username, String password) { - httpEntryUser.setUsername(username); - httpEntryUser.setPassword(password); + return "login_success"; - return httpEntryUser; } - @GetMapping("info") - public Principal retrievePrincipal(Principal principal) { - - return principal; + @PostMapping("/register") + @ResponseStatus(code = HttpStatus.OK) + public String processRegister(String username, String password) { + User user = new User(); + user.setUsername(username); + user.setPassword(password); + user.setEnabled(true); + user.setId((long) Math.toIntExact(playerRepository.count() + 1)); + BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + String encodedPassword = passwordEncoder.encode(user.getPassword()); + user.setPassword(encodedPassword); + + userRepository.save(user); + + Player player = new Player(); + player.setIdplayers(Math.toIntExact(playerRepository.count() + 1)); + player.setName(username); + player.setSpeed(100F); + player.setResponsibility(100F); + player.setRespect(100F); + player.setCash(15000F); + player.setFinished_courses(0); + player.setFailed_courses(0); + player.setOwner(username); + + playerRepository.save(player); + + + return "login success"; } - - - @PostMapping() - public Boolean loginUser(@RequestBody String username, String password){ - - //return playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()); - return SecurityContextHolder.getContext().getAuthentication().isAuthenticated(); - - } +} -} diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Truck.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Truck.java index bec4a33..e3c0612 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Truck.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Truck.java @@ -1,14 +1,12 @@ package pl.staszczykpiotr.truckforwarder_backend.dto; -import pl.staszczykpiotr.truckforwarder_backend.interfaces.ITruck; - import javax.persistence.*; @Entity @Table(name = "trucks") -public class Truck implements ITruck{ +public class Truck { @Id @Column(name = "id") @@ -31,50 +29,46 @@ public class Truck implements ITruck{ protected Float capacity; @Column(name = "price") protected Float price; - @Column(name = "status") - protected Byte status; + public Truck(){ }; - @Override + public Integer getID() { return idtrucks; } - @Override + public String getName() { return name; } - @Override + public String getLoading() { return loadingtype; } - @Override + public Float getLength() { return length; } - @Override + public Float getWidth() { return width; } - @Override + public Float getHeight() { return height; } - @Override + public Float getWeight() { return weight; } - @Override + public Float getCapacity() { return capacity; } - @Override + public Float getPrice() { return price; } - @Override - public Byte getStatus() { - return status; - } + } diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/User.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/User.java index ddb5fed..dba62bc 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/User.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/User.java @@ -17,6 +17,16 @@ public class User { private String password; + public Boolean getEnabled() { + return enabled; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + private Boolean enabled; + public Long getId() { return id; } @@ -40,4 +50,15 @@ public String getPassword() { public void setPassword(String password) { this.password = password; } + +// public void register(String username, String password){ +// this.username = username; +// this.password = password; +// } + + + + public User(){ + + } } diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/interfaces/ITruck.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/interfaces/ITruck.java deleted file mode 100644 index 6abb5b5..0000000 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/interfaces/ITruck.java +++ /dev/null @@ -1,16 +0,0 @@ -package pl.staszczykpiotr.truckforwarder_backend.interfaces; - -public interface ITruck { - - public Integer getID(); - public String getName(); - public String getLoading(); - public Float getLength(); - public Float getWidth(); - public Float getHeight(); - public Float getWeight(); - public Float getCapacity(); - public Float getPrice(); - public Byte getStatus(); - } - diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/UserRepository.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/UserRepository.java index c034c4e..28900af 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/UserRepository.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/UserRepository.java @@ -8,4 +8,6 @@ public interface UserRepository extends JpaRepository { User findByUsername(String username); + User readAllByUsernameAndPassword(String username, String password); + } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e4e41bb..6b3c1ee 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,4 +5,6 @@ spring.datasource.username=root spring.datasource.password=Zaq12wsx spring.datasource.initialization-mode=always logging.level.org.springframework.security=DEBUG +debug=true + diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml deleted file mode 100644 index 91f9926..0000000 --- a/src/main/resources/hibernate.cfg.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - jdbc:mysql://127.0.0.1:3306/sys?serverTimezone=Europe/Warsaw - root - Zaq12wsx - true - com.mysql.jdbc.Driver - - org.hibernate.dialect.MySQL5Dialect - update - true - true - - - - - - \ No newline at end of file