Merge branch 'ybw_branch' of https://bdgit.educoder.net/ppy4sjqvf/pairedProject
# Conflicts: # src/main/java/module-info.javapull/2/head
commit
997acd73ec
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
||||
@ -0,0 +1,31 @@
|
||||
package com.ybw.mathapp.service;
|
||||
|
||||
// File: mathpuzzle/entity/QuestionWithAnswer.java
|
||||
/**
|
||||
* 用于封装一道题目及其正确答案。
|
||||
*/
|
||||
public class QuestionWithAnswer {
|
||||
private final String question; // 题目字符串,例如 "2 + 3 ="
|
||||
private final double correctAnswer; // 计算得出的正确答案
|
||||
|
||||
public QuestionWithAnswer(String question, double correctAnswer) {
|
||||
this.question = question;
|
||||
this.correctAnswer = correctAnswer;
|
||||
}
|
||||
|
||||
public String getQuestion() {
|
||||
return question;
|
||||
}
|
||||
|
||||
public double getCorrectAnswer() {
|
||||
return correctAnswer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "QuestionWithAnswer{" +
|
||||
"question='" + question + '\'' +
|
||||
", correctAnswer=" + correctAnswer +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.ybw.mathapp.system;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Scanner;
|
||||
import com.ybw.mathapp.entity.User;
|
||||
|
||||
public class LogSystem {
|
||||
private final HashMap<String, User> userHashMap = new HashMap<>();
|
||||
public void userHashMapInit() {
|
||||
// 小学
|
||||
userHashMap.put("1798231811@qq.com", new User("1798231811@qq.com", "1234567"));
|
||||
|
||||
}
|
||||
|
||||
public User login() {
|
||||
System.out.println("请输入用户名和密码,两者之间用空格隔开,用户名为邮箱账号");
|
||||
while(true) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String[] info = scanner.nextLine().split(" ");
|
||||
if(info.length != 2) {
|
||||
System.out.println("请输入正确格式");
|
||||
} else {
|
||||
String name = info[0];
|
||||
String password = info[1];
|
||||
User user = userHashMap.get(name);
|
||||
if (user == null) {
|
||||
System.out.println("邮箱未注册");
|
||||
}
|
||||
else if (!user.getPassword().equals(password)) {
|
||||
System.out.println("请输入正确的用户名、密码");
|
||||
}
|
||||
else {
|
||||
System.out.println("当前选择为" + user.getLevel() + "出题");
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,158 @@
|
||||
package com.ybw.mathapp.util;
|
||||
|
||||
import com.ybw.mathapp.config.EmailConfig;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import jakarta.mail.Authenticator;
|
||||
import jakarta.mail.Message;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.PasswordAuthentication;
|
||||
import jakarta.mail.Session;
|
||||
import jakarta.mail.Transport;
|
||||
import jakarta.mail.internet.InternetAddress;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
|
||||
public class EmailService {
|
||||
private static Map<String, VerificationCodeInfo> verificationCodes = new HashMap<>();
|
||||
|
||||
// 验证码信息内部类
|
||||
private static class VerificationCodeInfo {
|
||||
String code;
|
||||
long timestamp;
|
||||
|
||||
VerificationCodeInfo(String code, long timestamp) {
|
||||
this.code = code;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
// 生成6位随机验证码
|
||||
public static String generateVerificationCode() {
|
||||
Random random = new Random();
|
||||
int code = 100000 + random.nextInt(900000);
|
||||
return String.valueOf(code);
|
||||
}
|
||||
|
||||
// 发送真实邮件验证码
|
||||
public static boolean sendVerificationCode(String recipientEmail, String code) {
|
||||
try {
|
||||
// 创建邮件会话
|
||||
Properties props = new Properties();
|
||||
props.put("mail.smtp.host", EmailConfig.SMTP_HOST);
|
||||
props.put("mail.smtp.port", EmailConfig.SMTP_PORT);
|
||||
props.put("mail.smtp.auth", "true");
|
||||
props.put("mail.smtp.starttls.enable", "true");
|
||||
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
|
||||
|
||||
// 创建认证器
|
||||
Authenticator auth = new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(
|
||||
EmailConfig.SENDER_EMAIL,
|
||||
EmailConfig.SENDER_PASSWORD
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Session session = Session.getInstance(props, auth);
|
||||
|
||||
// 创建邮件消息
|
||||
Message message = new MimeMessage(session);
|
||||
message.setFrom(new InternetAddress(EmailConfig.SENDER_EMAIL));
|
||||
message.setRecipients(Message.RecipientType.TO,
|
||||
InternetAddress.parse(recipientEmail));
|
||||
message.setSubject(EmailConfig.EMAIL_SUBJECT);
|
||||
|
||||
// 创建邮件内容
|
||||
String emailContent = createEmailContent(code);
|
||||
message.setContent(emailContent, "text/html; charset=utf-8");
|
||||
|
||||
// 发送邮件
|
||||
Transport.send(message);
|
||||
|
||||
// 存储验证码信息
|
||||
verificationCodes.put(recipientEmail,
|
||||
new VerificationCodeInfo(code, System.currentTimeMillis()));
|
||||
|
||||
System.out.println("验证码已发送到邮箱: " + recipientEmail);
|
||||
return true;
|
||||
|
||||
} catch (MessagingException e) {
|
||||
System.err.println("发送邮件失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 创建HTML格式的邮件内容
|
||||
private static String createEmailContent(String code) {
|
||||
return "<!DOCTYPE html>" +
|
||||
"<html>" +
|
||||
"<head>" +
|
||||
"<meta charset='UTF-8'>" +
|
||||
"<style>" +
|
||||
"body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }" +
|
||||
".container { max-width: 600px; margin: 0 auto; padding: 20px; }" +
|
||||
".header { background-color: #4CAF50; color: white; padding: 20px; text-align: center; }" +
|
||||
".content { padding: 20px; background-color: #f9f9f9; margin: 20px 0; }" +
|
||||
".code { font-size: 24px; font-weight: bold; color: #4CAF50; text-align: center; padding: 15px; background-color: white; border: 2px dashed #4CAF50; margin: 20px 0; }" +
|
||||
".footer { text-align: center; color: #666; font-size: 12px; }" +
|
||||
"</style>" +
|
||||
"</head>" +
|
||||
"<body>" +
|
||||
"<div class='container'>" +
|
||||
"<div class='header'>" +
|
||||
"<h2>用户注册验证码</h2>" +
|
||||
"</div>" +
|
||||
"<div class='content'>" +
|
||||
"<p>您好!</p>" +
|
||||
"<p>您正在注册账户,验证码如下:</p>" +
|
||||
"<div class='code'>" + code + "</div>" +
|
||||
"<p>验证码有效期为 " + EmailConfig.CODE_EXPIRY_MINUTES + " 分钟,请勿泄露给他人。</p>" +
|
||||
"<p>如果这不是您本人的操作,请忽略此邮件。</p>" +
|
||||
"</div>" +
|
||||
"<div class='footer'>" +
|
||||
"<p>此邮件为系统自动发送,请勿回复。</p>" +
|
||||
"</div>" +
|
||||
"</div>" +
|
||||
"</body>" +
|
||||
"</html>";
|
||||
}
|
||||
|
||||
// 验证验证码
|
||||
public static boolean verifyCode(String email, String inputCode) {
|
||||
VerificationCodeInfo codeInfo = verificationCodes.get(email);
|
||||
if (codeInfo == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查验证码是否过期
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (currentTime - codeInfo.timestamp > EmailConfig.CODE_EXPIRY_MINUTES * 60 * 1000) {
|
||||
verificationCodes.remove(email);
|
||||
return false;
|
||||
}
|
||||
|
||||
return codeInfo.code.equals(inputCode);
|
||||
}
|
||||
|
||||
// 清理过期的验证码(可选)
|
||||
public static void cleanupExpiredCodes() {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
Iterator<Entry<String, VerificationCodeInfo>> iterator =
|
||||
verificationCodes.entrySet().iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, VerificationCodeInfo> entry = iterator.next();
|
||||
if (currentTime - entry.getValue().timestamp >
|
||||
EmailConfig.CODE_EXPIRY_MINUTES * 60 * 1000) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package com.ybw.mathapp.util;
|
||||
|
||||
import com.ybw.mathapp.entity.User;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LoginFileUtils {
|
||||
private static final String USER_FILE = "users.txt";
|
||||
|
||||
// 读取所有用户
|
||||
// FileUtils.java 中的 readUsers 方法(简化版)
|
||||
public static List<User> readUsers() {
|
||||
List<User> users = new ArrayList<>();
|
||||
File file = new File(USER_FILE);
|
||||
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
System.err.println("创建用户文件失败: " + e.getMessage());
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (line.isEmpty()) continue;
|
||||
|
||||
User user = User.fromString(line);
|
||||
if (user != null) {
|
||||
users.add(user);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("读取用户文件失败: " + e.getMessage());
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
// 保存用户到文件
|
||||
public static void saveUser(User user) {
|
||||
try (PrintWriter writer = new PrintWriter(new FileWriter(USER_FILE, true))) {
|
||||
writer.println(user.toString());
|
||||
} catch (IOException e) {
|
||||
System.err.println("保存用户信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 检查邮箱是否已注册
|
||||
public static boolean isEmailRegistered(String email) {
|
||||
List<User> users = readUsers();
|
||||
for (User user : users) {
|
||||
if (user.getEmail().equalsIgnoreCase(email)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 验证用户登录
|
||||
public static boolean validateUser(String email, String password) {
|
||||
List<User> users = readUsers();
|
||||
for (User user : users) {
|
||||
if (user.getEmail().equalsIgnoreCase(email) &&
|
||||
user.getPassword().equals(password)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
rfc822=smtp
|
||||
smtp=smtp
|
||||
Loading…
Reference in new issue