|
|
|
@ -3,8 +3,13 @@ package auth;
|
|
|
|
|
import model.Level;
|
|
|
|
|
import model.User;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
public class AuthService {
|
|
|
|
|
private final List<User> users;
|
|
|
|
@ -22,4 +27,41 @@ public class AuthService {
|
|
|
|
|
users.add(new User("王五2", "123", Level.SENIOR_HIGH));
|
|
|
|
|
users.add(new User("王五3", "123", Level.SENIOR_HIGH));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Optional<User> login(String username, String password) {
|
|
|
|
|
return users.stream()
|
|
|
|
|
.filter(user -> user.getUsername().equals(username) && user.getPassword().equals(password))
|
|
|
|
|
.findFirst();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class TestPaperService {
|
|
|
|
|
|
|
|
|
|
public Set<String> loadExistingQuestions(String username) {
|
|
|
|
|
Set<String> questions = new HashSet<>();
|
|
|
|
|
File userDir = new File(username);
|
|
|
|
|
if (!userDir.exists() || !userDir.isDirectory()) {
|
|
|
|
|
return questions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try (Stream<Path> paths = Files.walk(Paths.get(username))) {
|
|
|
|
|
paths.filter(Files::isRegularFile)
|
|
|
|
|
.filter(path -> path.toString().endsWith(".txt"))
|
|
|
|
|
.forEach(path -> {
|
|
|
|
|
try {
|
|
|
|
|
Files.lines(path).forEach(line -> {
|
|
|
|
|
// 简单的题目提取逻辑,假设每行都是一个题目
|
|
|
|
|
if (line.matches("^\\d+\\.\\s.*")) {
|
|
|
|
|
questions.add(line.substring(line.indexOf(' ') + 1).trim());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
System.err.println("读取历史文件失败: " + path);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
System.err.println("加载历史题目时出错: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
return questions;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|