Merge branch 'backend-bugfix-persistent-data' into 'master'
Bugfix backend data-initialization See merge request marcel.schwarz/2020ss-qbc-geofence-timetracking!49
This commit is contained in:
commit
8b2e26042c
@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
|
||||
@ -29,15 +31,31 @@ public class UserController {
|
||||
@GetMapping("/whoami")
|
||||
public UserAllEmbeddedProjection getUsername(Authentication authentication) {
|
||||
TimetrackUser user = userRepository.findFirstByUsername(authentication.getName());
|
||||
return projectionFactory.createProjection(UserAllEmbeddedProjection.class, user);
|
||||
if (user != null) {
|
||||
return projectionFactory.createProjection(UserAllEmbeddedProjection.class, user);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/sign-up")
|
||||
public ResponseEntity<String> signUp(@RequestBody TimetrackUser user) {
|
||||
user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
|
||||
TimetrackUser byUsername = userRepository.findFirstByUsername(user.getUsername());
|
||||
public ResponseEntity<String> signUp(@RequestBody HashMap<String, String> signUpData) {
|
||||
if (signUpData.get("username") == null
|
||||
|| signUpData.get("password") == null
|
||||
|| signUpData.get("firstname") == null
|
||||
|| signUpData.get("lastname") == null) {
|
||||
return new ResponseEntity<>("Missing information", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
TimetrackUser newUser = new TimetrackUser();
|
||||
newUser.setFirstname(signUpData.get("firstname"));
|
||||
newUser.setLastname(signUpData.get("lastname"));
|
||||
newUser.setPassword(bCryptPasswordEncoder.encode(signUpData.get("password")));
|
||||
newUser.setUsername(signUpData.get("username"));
|
||||
|
||||
TimetrackUser byUsername = userRepository.findFirstByUsername(newUser.getUsername());
|
||||
if (byUsername == null) {
|
||||
userRepository.save(user);
|
||||
userRepository.save(newUser);
|
||||
return new ResponseEntity<>("Created", HttpStatus.CREATED);
|
||||
} else {
|
||||
return new ResponseEntity<>("Username already exists!", HttpStatus.CONFLICT);
|
||||
|
@ -15,6 +15,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static com.auth0.jwt.algorithms.Algorithm.HMAC512;
|
||||
import static de.hft.geotime.security.SecurityConstants.*;
|
||||
@ -31,11 +32,11 @@ public class JWTAuthenticationFilter extends UsernamePasswordAuthenticationFilte
|
||||
HttpServletRequest req,
|
||||
HttpServletResponse res) throws AuthenticationException {
|
||||
try {
|
||||
LoginUser creds = new ObjectMapper().readValue(req.getInputStream(), LoginUser.class);
|
||||
HashMap creds = new ObjectMapper().readValue(req.getInputStream(), HashMap.class);
|
||||
return authenticationManager.authenticate(
|
||||
new UsernamePasswordAuthenticationToken(
|
||||
creds.getUsername(),
|
||||
creds.getPassword(),
|
||||
creds.get("username"),
|
||||
creds.get("password"),
|
||||
new ArrayList<>()
|
||||
)
|
||||
);
|
||||
|
@ -4,4 +4,5 @@ spring.datasource.username=sa
|
||||
spring.datasource.password=
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
spring.h2.console.enabled=true
|
||||
spring.datasource.initialization-mode=always
|
||||
spring.h2.console.path=/h2-console
|
@ -2,5 +2,4 @@ spring.jpa.hibernate.ddl-auto=update
|
||||
spring.datasource.url=jdbc:mariadb://db:3306/geotime
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=supersecure
|
||||
spring.datasource.initialization-mode=always
|
||||
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
|
@ -1,7 +1,9 @@
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
DELETE FROM timetrack_user;
|
||||
DELETE FROM role;
|
||||
DELETE FROM location;
|
||||
DELETE FROM timetrack_user;
|
||||
DELETE FROM timetrack_account;
|
||||
|
||||
INSERT INTO role (id, `name`) VALUES
|
||||
(1, 'Admin');
|
||||
|
@ -12,6 +12,7 @@ services:
|
||||
|
||||
backend:
|
||||
container_name: qbc_backend
|
||||
restart: always
|
||||
build:
|
||||
context: ./backend
|
||||
ports:
|
||||
@ -25,7 +26,10 @@ services:
|
||||
build:
|
||||
context: ./sql
|
||||
volumes:
|
||||
- "./sql/db-data:/var/lib/mysql"
|
||||
- "qbc-db-data:/var/lib/mysql"
|
||||
environment:
|
||||
MYSQL_DATABASE: geotime
|
||||
MYSQL_ROOT_PASSWORD: supersecure
|
||||
|
||||
volumes:
|
||||
qbc-db-data:
|
Loading…
Reference in New Issue
Block a user