Add sample user controller with sign-up and name of current user
This commit is contained in:
parent
c7ff49bc64
commit
ec702d93c5
@ -5,5 +5,5 @@ public class SecurityConstants {
|
|||||||
public static final long EXPIRATION_TIME = 864_000_000; // 10 days
|
public static final long EXPIRATION_TIME = 864_000_000; // 10 days
|
||||||
public static final String TOKEN_PREFIX = "Bearer ";
|
public static final String TOKEN_PREFIX = "Bearer ";
|
||||||
public static final String HEADER_STRING = "Authorization";
|
public static final String HEADER_STRING = "Authorization";
|
||||||
public static final String SIGN_UP_URL = "/users/sign-up";
|
public static final String SIGN_UP_URL = "/user/sign-up";
|
||||||
}
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package de.hft.geotime.user;
|
||||||
|
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user")
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
private TimetrackUserRepository userRepository;
|
||||||
|
private BCryptPasswordEncoder bCryptPasswordEncoder;
|
||||||
|
|
||||||
|
public UserController(TimetrackUserRepository userRepository, BCryptPasswordEncoder bCryptPasswordEncoder) {
|
||||||
|
this.userRepository = userRepository;
|
||||||
|
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public String getUsername(Authentication authentication) {
|
||||||
|
TimetrackUser timetrackUser = userRepository.findFirstByUsername(authentication.getName());
|
||||||
|
return "Welcome back " + timetrackUser.getFirstname() + " " + timetrackUser.getLastname();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: implement register, maybe move to another class
|
||||||
|
@PostMapping("/sign-up")
|
||||||
|
public HashMap<String, Object> signUp(@RequestBody HashMap<String, Object> payload) {
|
||||||
|
return payload;
|
||||||
|
// user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
|
||||||
|
// userRepository.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user