细节修改

pull/1/head
wrh 7 months ago
parent 1624db0d9c
commit 310e4265e5

@ -1,6 +1,6 @@
import controller.NavigationController;
import javax.swing.*;
import javax.swing.UIManager;
import javax.swing.SwingUtilities;
public class MathLearningApp {
public static void main(String[] args) {
// Set system look and feel

@ -1,7 +1,12 @@
package controller;
import model.User;
import view.*;
import view.LoginView;
import view.RegisterView;
import view.MainView;
import view.ExamView;
import view.ResultView;
public class NavigationController {
private static LoginView loginView;
@ -75,13 +80,4 @@ public class NavigationController {
}
}
// 新增:设置当前用户(在登录时调用)
public static void setCurrentUser(User user) {
currentUser = user;
}
// 新增:获取当前用户
public static User getCurrentUser() {
return currentUser;
}
}

@ -3,7 +3,8 @@ package controller;
import model.Question;
import model.QuestionGenerator;
import utils.FileUtil;
import java.util.*;
import java.util.List;
import java.util.Arrays;
public class QuestionController {
private QuestionGenerator generator = new QuestionGenerator();

@ -1,7 +1,9 @@
package controller;
import model.User;
import utils.*;
import utils.FileUtil;
import utils.ValidationUtil;
import utils.EmailUtil;
public class UserController {
@ -101,10 +103,6 @@ public class UserController {
return null; // 用户不存在
}
if (!user.isRegistered()) {
return null; // 用户未完成注册
}
if (user.getPassword() == null || !user.getPassword().equals(password)) {
return null; // 密码错误
}

@ -20,8 +20,7 @@ public class Question implements Serializable {
// Getters
public String getQuestion() { return question; }
public String[] getOptions() { return options; }
public int getCorrectAnswer() { return correctAnswer; }
public String getDifficulty() { return difficulty; }
public boolean isCorrect(int selectedAnswer) {
return selectedAnswer == correctAnswer;

@ -1,6 +1,11 @@
package model;
import java.util.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
import java.util.Random;
import java.text.DecimalFormat;
public class QuestionGenerator {

@ -19,13 +19,11 @@ public class User {
public void setUsername(String username) { this.username = username; }
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }
public String getPassword() { return password; }
public void setPassword(String password) { this.password = password; }
public String getRegistrationCode() { return registrationCode; }
public void setRegistrationCode(String registrationCode) { this.registrationCode = registrationCode; }
public boolean isRegistered() { return isRegistered; }
public void setRegistered(boolean registered) { isRegistered = registered; }

@ -1,7 +1,12 @@
package utils;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
import java.util.Random;
@ -29,11 +34,9 @@ public class EmailUtil {
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", SMTP_HOST);
props.put("mail.smtp.port", SMTP_PORT);
// 超时设置
props.put("mail.smtp.timeout", "10000");
props.put("mail.smtp.connectiontimeout", "10000");
// 创建认证器
Authenticator authenticator = new Authenticator() {
@Override
@ -41,25 +44,20 @@ public class EmailUtil {
return new PasswordAuthentication(FROM_EMAIL, EMAIL_PASSWORD);
}
};
Session session = Session.getInstance(props, authenticator);
try {
// 创建邮件
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(FROM_EMAIL, FROM_NAME, "UTF-8"));
message.setRecipient(Message.RecipientType.TO, new InternetAddress(userEmail));
message.setSubject("数学学习软件 - 注册验证码", "UTF-8");
// 邮件内容HTML格式
String htmlContent = buildEmailContent(username, code);
message.setContent(htmlContent, "text/html;charset=UTF-8");
// 发送邮件
Transport.send(message);
System.out.println("✅ 注册码已成功发送到: " + userEmail);
return true;
} catch (Exception e) {
System.err.println("❌ 邮件发送失败: " + e.getMessage());
e.printStackTrace();
@ -94,7 +92,7 @@ public class EmailUtil {
" <div class=\"code-box\">" +
" <div class=\"code\">" + code + "</div>" +
" </div>" +
" <p>验证码有效期30分钟,请尽快完成注册。</p>" +
" <p>注册码直到系统退出前都有效,请尽快完成注册。</p>" +
" <p>如果这不是您的操作,请忽略此邮件。</p>" +
" <div class=\"footer\">" +
" <p>此为系统邮件,请勿回复</p>" +

@ -5,9 +5,16 @@ import model.User;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.io.*;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.*;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class FileUtil {
private static final String USERS_FILE = "data/users.json";

@ -4,8 +4,18 @@ import controller.UserController;
import model.User;
import utils.ValidationUtil;
import javax.swing.*;
import java.awt.*;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

@ -4,8 +4,19 @@ import controller.NavigationController;
import controller.QuestionController;
import model.Question;
import javax.swing.*;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JButton;
import javax.swing.ButtonGroup;
import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;

@ -4,8 +4,18 @@ import controller.NavigationController;
import controller.UserController;
import model.User;
import javax.swing.*;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

@ -4,8 +4,18 @@ import controller.NavigationController;
import controller.UserController;
import model.User;
import javax.swing.*;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

@ -4,19 +4,26 @@ import controller.NavigationController;
import controller.UserController;
import model.User;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class RegisterView extends JFrame {
private JTextField usernameField; // 新增:用户名输入框
private JTextField usernameField;
private JTextField emailField;
private JTextField codeField;
private JPasswordField passwordField;
private JPasswordField confirmPasswordField;
private UserController userController;
private String currentUsername; // 保存当前注册的用户名
private String currentUsername;
public RegisterView() {
userController = new UserController();
@ -26,7 +33,7 @@ public class RegisterView extends JFrame {
private void initializeUI() {
setTitle("数学学习软件 - 注册");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(550, 500); // 增加高度以容纳用户名字段
setSize(550, 550); // 增加高度以容纳所有组件
setLocationRelativeTo(null);
setResizable(false);
@ -38,8 +45,8 @@ public class RegisterView extends JFrame {
titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
mainPanel.add(titleLabel, BorderLayout.NORTH);
// Form panel - 增加用户名字段
JPanel formPanel = new JPanel(new GridLayout(8, 2, 10, 10));
// Form panel
JPanel formPanel = new JPanel(new GridLayout(6, 2, 10, 10));
JLabel usernameLabel = new JLabel("用户名:");
usernameLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));
@ -73,7 +80,7 @@ public class RegisterView extends JFrame {
formPanel.add(emailLabel);
formPanel.add(emailField);
formPanel.add(sendCodeButton);
formPanel.add(new JLabel());
formPanel.add(new JLabel()); // 空标签占位
formPanel.add(codeLabel);
formPanel.add(codeField);
formPanel.add(passwordLabel);
@ -81,17 +88,31 @@ public class RegisterView extends JFrame {
formPanel.add(confirmPasswordLabel);
formPanel.add(confirmPasswordField);
formPanel.add(registerButton);
mainPanel.add(formPanel, BorderLayout.CENTER);
// 创建底部面板,包含密码提示和返回按钮
JPanel bottomPanel = new JPanel(new BorderLayout(10, 10));
// 密码要求提示
JLabel hintLabel = new JLabel(
"<html><body style='text-align: center'>" +
"密码要求6-10位必须包含大小写字母和数字<br>" +
"例如Abc123、Test456" +
"</body></html>", JLabel.CENTER);
hintLabel.setFont(new Font("微软雅黑", Font.PLAIN, 12));
hintLabel.setForeground(Color.GRAY);
bottomPanel.add(hintLabel, BorderLayout.CENTER);
// Back button
JButton backButton = new JButton("返回登录");
backButton.setFont(new Font("微软雅黑", Font.PLAIN, 14));
backButton.addActionListener(e -> NavigationController.showLoginView());
JPanel bottomPanel = new JPanel(new FlowLayout());
bottomPanel.add(backButton);
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(registerButton); // 将注册按钮移到这里
buttonPanel.add(backButton);
bottomPanel.add(buttonPanel, BorderLayout.SOUTH);
mainPanel.add(bottomPanel, BorderLayout.SOUTH);
// Add action listeners

@ -2,8 +2,15 @@ package view;
import controller.NavigationController;
import javax.swing.*;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

Loading…
Cancel
Save