Compare commits
6 Commits
3137c22313
...
af4a0f9684
| Author | SHA1 | Date | |
|---|---|---|---|
| af4a0f9684 | |||
| ae0417c77f | |||
| b7ede5652c | |||
| fcd9534e65 | |||
| fd0cb2d345 | |||
| 67c90b8f03 |
@ -6,20 +6,21 @@ import org.cmh.backend.Utils.JwtVerify;
|
||||
import org.cmh.backend.authentication.dto.*;
|
||||
import org.cmh.backend.authentication.model.UserHS;
|
||||
import org.cmh.backend.authentication.service.UserService;
|
||||
import org.cmh.backend.authentication.service.VerificationCodeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
class AuthenticationController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private VerificationCodeService verificationCodeService;
|
||||
|
||||
@GetMapping("/hello")
|
||||
public String hello() {
|
||||
return "Hello SpringBoot!";
|
||||
@ -59,8 +60,7 @@ class AuthenticationController {
|
||||
if (JwtUtil.isTokenValid(token)) {
|
||||
UserHS user = userService.getUserByUsername(JwtUtil.extractUsername(token));
|
||||
if (user != null) {
|
||||
|
||||
return new ResponseEntity<>(new UserProfileResponse(
|
||||
UserProfileResponse response = new UserProfileResponse(
|
||||
user.getUsername(),
|
||||
user.getNickname(),
|
||||
user.getGender(),
|
||||
@ -69,7 +69,12 @@ class AuthenticationController {
|
||||
user.getDepartment(),
|
||||
user.getRole(),
|
||||
user.getCreatedAt()
|
||||
), HttpStatus.OK);
|
||||
);
|
||||
if (user.getSuperAdmin()) {
|
||||
response.setDepartment("超级管理员");
|
||||
response.setRole("超级管理员");
|
||||
}
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
@ -95,18 +100,9 @@ class AuthenticationController {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@PostMapping("/sendVerificationCode")
|
||||
public ResponseEntity<Map<String, Integer>> sendVerificationCode(@RequestBody Map<String, String> request) {
|
||||
String contactInfo = request.get("contactInfo");
|
||||
// TODO:发送验证码功能有待添加。 boolean isSent = userService.sendVerificationCode(contactInfo);
|
||||
boolean isSent = true;
|
||||
if (isSent) {
|
||||
HashMap<String, Integer> response = new HashMap<>();
|
||||
response.put("code", 1234);
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
@GetMapping("/getVerificationCode")
|
||||
public ResponseEntity<VerificationCodeResponse> getVerificationCode() {
|
||||
return new ResponseEntity<>(verificationCodeService.provideVerificationCode(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
package org.cmh.backend.authentication.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class VerificationCodeResponse {
|
||||
private String code;
|
||||
private String path;
|
||||
}
|
||||
@ -25,4 +25,5 @@ public class UserHS {
|
||||
private String department;
|
||||
private String role;
|
||||
private LocalDateTime createdAt;
|
||||
private Boolean superAdmin = false;
|
||||
}
|
||||
|
||||
@ -0,0 +1,51 @@
|
||||
package org.cmh.backend.authentication.service;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.Getter;
|
||||
import org.cmh.backend.authentication.dto.VerificationCodeResponse;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Service
|
||||
public class VerificationCodeService {
|
||||
|
||||
@Value("${verification.code.images.path}")
|
||||
private String verificationCodeImagesPath;
|
||||
|
||||
@Getter
|
||||
private List<String> verificationCodeList = new ArrayList<>();
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
loadVerificationCodeImages();
|
||||
}
|
||||
|
||||
private void loadVerificationCodeImages() {
|
||||
try (Stream<Path> paths = Files.list(Paths.get(verificationCodeImagesPath))) {
|
||||
paths.filter(path -> path.toString().endsWith(".png"))
|
||||
.forEach(path -> verificationCodeList.add(path.getFileName().toString()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public VerificationCodeResponse provideVerificationCode() {
|
||||
if (verificationCodeList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Random random = new Random();
|
||||
int code = random.nextInt(random.nextInt(verificationCodeList.size()));
|
||||
String selectedCode = verificationCodeList.get(code);
|
||||
return new VerificationCodeResponse(selectedCode.split("\\.")[0], "/verificationCodeImages/" + selectedCode);
|
||||
}
|
||||
|
||||
}
|
||||
@ -20,5 +20,7 @@ spring.datasource.hikari.connection-timeout=30000
|
||||
server.servlet.encoding.enabled=true
|
||||
server.servlet.encoding.force=true
|
||||
server.servlet.encoding.charset=utf-8
|
||||
# verificationCode
|
||||
verification.code.images.path=src/main/resources/static/verificationCodeImages
|
||||
|
||||
|
||||
|
||||
BIN
src/main/resources/static/verificationCodeImages/011092.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/main/resources/static/verificationCodeImages/021719.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/022035.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/029455.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/main/resources/static/verificationCodeImages/031573.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/046770.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/047990.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/main/resources/static/verificationCodeImages/056052.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/058684.png
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
src/main/resources/static/verificationCodeImages/060657.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/082948.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
src/main/resources/static/verificationCodeImages/085535.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/main/resources/static/verificationCodeImages/095376.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
src/main/resources/static/verificationCodeImages/096237.png
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
src/main/resources/static/verificationCodeImages/121504.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/main/resources/static/verificationCodeImages/129257.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/main/resources/static/verificationCodeImages/143814.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
src/main/resources/static/verificationCodeImages/159296.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
src/main/resources/static/verificationCodeImages/162856.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/167606.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
src/main/resources/static/verificationCodeImages/187677.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/main/resources/static/verificationCodeImages/193643.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/194588.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/main/resources/static/verificationCodeImages/194642.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/196496.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/main/resources/static/verificationCodeImages/196553.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/main/resources/static/verificationCodeImages/198679.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/206102.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/216242.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
src/main/resources/static/verificationCodeImages/216341.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/main/resources/static/verificationCodeImages/219509.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/main/resources/static/verificationCodeImages/239910.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
src/main/resources/static/verificationCodeImages/245156.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/246115.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/main/resources/static/verificationCodeImages/254558.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/main/resources/static/verificationCodeImages/263518.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
src/main/resources/static/verificationCodeImages/265527.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/main/resources/static/verificationCodeImages/268074.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
src/main/resources/static/verificationCodeImages/293288.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/304263.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/main/resources/static/verificationCodeImages/311480.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/324873.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/342986.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
src/main/resources/static/verificationCodeImages/361726.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/372672.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/main/resources/static/verificationCodeImages/392726.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/main/resources/static/verificationCodeImages/398993.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/main/resources/static/verificationCodeImages/402610.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/409320.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
src/main/resources/static/verificationCodeImages/411406.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/main/resources/static/verificationCodeImages/439170.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/main/resources/static/verificationCodeImages/469004.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/480443.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/481488.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src/main/resources/static/verificationCodeImages/484022.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/main/resources/static/verificationCodeImages/492409.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/497995.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/main/resources/static/verificationCodeImages/501513.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/main/resources/static/verificationCodeImages/502886.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
src/main/resources/static/verificationCodeImages/503160.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
src/main/resources/static/verificationCodeImages/512497.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/526749.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
src/main/resources/static/verificationCodeImages/531660.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
src/main/resources/static/verificationCodeImages/545022.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
src/main/resources/static/verificationCodeImages/548598.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/main/resources/static/verificationCodeImages/562119.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
src/main/resources/static/verificationCodeImages/582599.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/main/resources/static/verificationCodeImages/591206.png
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
src/main/resources/static/verificationCodeImages/607760.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/main/resources/static/verificationCodeImages/633245.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
src/main/resources/static/verificationCodeImages/642202.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/main/resources/static/verificationCodeImages/647711.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
src/main/resources/static/verificationCodeImages/653574.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/main/resources/static/verificationCodeImages/690774.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/709672.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/726268.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/main/resources/static/verificationCodeImages/735646.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/749210.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/762755.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/main/resources/static/verificationCodeImages/766473.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/main/resources/static/verificationCodeImages/774503.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/795000.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/795308.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
src/main/resources/static/verificationCodeImages/798554.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/807222.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/main/resources/static/verificationCodeImages/810523.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
src/main/resources/static/verificationCodeImages/823694.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
src/main/resources/static/verificationCodeImages/843596.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
src/main/resources/static/verificationCodeImages/857226.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/883530.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src/main/resources/static/verificationCodeImages/906145.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
src/main/resources/static/verificationCodeImages/917528.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/main/resources/static/verificationCodeImages/947670.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src/main/resources/static/verificationCodeImages/949368.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
src/main/resources/static/verificationCodeImages/954806.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |