parent
c36da7648b
commit
9855cd9e83
@ -0,0 +1,12 @@
|
||||
<component name="libraryTable">
|
||||
<library name="lib">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/flatlaf-3.4.1.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/activation-1.1.1.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/javax.mail-1.6.2.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/jakarta.activation-api-2.1.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,20 +0,0 @@
|
||||
import com.formdev.flatlaf.FlatLightLaf;
|
||||
import controller.AppController;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("awt.useSystemAAFontSettings", "on");
|
||||
System.setProperty("swing.aatext", "true");
|
||||
|
||||
try {
|
||||
UIManager.setLookAndFeel(new FlatLightLaf());
|
||||
} catch (UnsupportedLookAndFeelException e) {
|
||||
System.err.println("无法设置UI主题: " + e.getMessage());
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(AppController::new);
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
|
||||
smtp.host=smtp.qq.com
|
||||
smtp.port=465
|
||||
smtp.ssl.enable=true
|
||||
smtp.auth=true
|
||||
|
||||
|
||||
mail.sender.email=2631495488@qq.com
|
||||
|
||||
mail.sender.password=vdjvddhflexgdjfd
|
||||
@ -1,19 +0,0 @@
|
||||
package model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Question {
|
||||
private final String questionText;
|
||||
private final List<String> options;
|
||||
private final int correctOptionIndex;
|
||||
|
||||
public Question(String questionText, List<String> options, int correctOptionIndex) {
|
||||
this.questionText = questionText;
|
||||
this.options = options;
|
||||
this.correctOptionIndex = correctOptionIndex;
|
||||
}
|
||||
|
||||
public String getQuestionText() { return questionText; }
|
||||
public List<String> getOptions() { return options; }
|
||||
public int getCorrectOptionIndex() { return correctOptionIndex; }
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
package model;
|
||||
|
||||
public enum UserType {
|
||||
PRIMARY("小学"),
|
||||
JUNIOR("初中"),
|
||||
SENIOR("高中");
|
||||
|
||||
private final String displayName;
|
||||
|
||||
UserType(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
}
|
||||
@ -1,97 +0,0 @@
|
||||
package service;
|
||||
|
||||
import model.User;
|
||||
import model.UserType;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
||||
public class UserManager {
|
||||
private final Path usersFile = Paths.get("data", "users.txt");
|
||||
private final Map<String, User> usersByEmail = new HashMap<>(); // 使用邮箱作为主键
|
||||
|
||||
public UserManager() {
|
||||
try {
|
||||
Files.createDirectories(usersFile.getParent());
|
||||
if (!Files.exists(usersFile)) Files.createFile(usersFile);
|
||||
loadUsers();
|
||||
} catch (IOException e) {
|
||||
System.err.println("初始化用户管理器时出错: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void loadUsers() throws IOException {
|
||||
List<String> lines = Files.readAllLines(usersFile, StandardCharsets.UTF_8);
|
||||
for (String line : lines) {
|
||||
User user = User.fromString(line);
|
||||
if (user != null) usersByEmail.put(user.getEmail(), user);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveUsers() {
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(usersFile, StandardCharsets.UTF_8)) {
|
||||
for (User user : usersByEmail.values()) writer.write(user.toString() + "\n");
|
||||
} catch (IOException e) {
|
||||
System.err.println("保存用户时出错: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public User authenticate(String identifier, String password) {
|
||||
String hashedInput = hashPassword(password);
|
||||
|
||||
// 策略一:尝试将 identifier 作为邮箱进行快速查找
|
||||
User userByEmail = usersByEmail.get(identifier);
|
||||
if (userByEmail != null && userByEmail.getHashedPassword().equals(hashedInput)) {
|
||||
return userByEmail; // 邮箱匹配成功
|
||||
}
|
||||
|
||||
// 策略二:如果邮箱查找失败,则遍历所有用户,尝试匹配用户名
|
||||
for (User user : usersByEmail.values()) {
|
||||
if (user.getUsername() != null && user.getUsername().equals(identifier)) {
|
||||
if (user.getHashedPassword().equals(hashedInput)) {
|
||||
return user; // 用户名匹配成功
|
||||
}
|
||||
break; // 用户名是唯一的,找到后无需继续遍历
|
||||
}
|
||||
}
|
||||
|
||||
return null; // 认证失败
|
||||
}
|
||||
|
||||
public boolean emailExists(String email) {
|
||||
return usersByEmail.containsKey(email);
|
||||
}
|
||||
|
||||
public boolean usernameExists(String username) {
|
||||
if (username == null || username.trim().isEmpty()) return false;
|
||||
for (User user : usersByEmail.values()) {
|
||||
if (username.equals(user.getUsername())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void registerUser(String email, String username, String password, UserType type) {
|
||||
User newUser = new User(email, username, "", type);
|
||||
newUser.setHashedPassword(password);
|
||||
usersByEmail.put(email, newUser);
|
||||
saveUsers();
|
||||
}
|
||||
|
||||
public void updateUser(User user) {
|
||||
if (usersByEmail.containsKey(user.getEmail())) {
|
||||
usersByEmail.put(user.getEmail(), user);
|
||||
saveUsers();
|
||||
}
|
||||
}
|
||||
|
||||
private String hashPassword(String password) {
|
||||
return Integer.toString(password.hashCode());
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package service;
|
||||
|
||||
|
||||
public class ValidationService {
|
||||
public static boolean isValidEmail(String email) {
|
||||
if (email == null || email.trim().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
|
||||
return email.matches(emailRegex);
|
||||
}
|
||||
|
||||
public static boolean isPasswordStrong(String password) {
|
||||
if (password == null || password.length() < 6 || password.length() > 10) {
|
||||
return false;
|
||||
}
|
||||
boolean hasUpperCase = password.matches(".*[A-Z].*");
|
||||
boolean hasLowerCase = password.matches(".*[a-z].*");
|
||||
boolean hasDigit = password.matches(".*[0-9].*");
|
||||
|
||||
return hasUpperCase && hasLowerCase && hasDigit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
package service.generator;
|
||||
|
||||
public interface QuestionGenerator {
|
||||
String generateQuestion();
|
||||
}
|
||||
Loading…
Reference in new issue