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