增加首次登录需要选择教育阶段

pull/2/head
陈映江 5 months ago
parent 3a306a6c35
commit ce8dd17ebc

@ -4,5 +4,6 @@
"passwordHash" : "$2a$12$fAWGM2CJSSiulyFbDWyRyefrBWr9emYrMdkD.Rw2LPKFaYQeYYW9K",
"registrationDate" : [ 2025, 10, 8, 21, 0, 37, 863490500 ],
"verificationCode" : "926911",
"verified" : true
"verified" : true,
"type" : "初中"
} ]

@ -1,5 +1,7 @@
package mathlearning.model;
import com.fasterxml.jackson.databind.BeanProperty;
import java.time.LocalDateTime;
public class User {
@ -9,6 +11,7 @@ public class User {
private LocalDateTime registrationDate;
private String verificationCode;
private boolean verified;
private String type;
public User() {}
@ -18,6 +21,7 @@ public class User {
this.verificationCode = verificationCode;
this.verified = false;
this.registrationDate = LocalDateTime.now();
this.type = null;
}
// Getters and setters
@ -38,4 +42,7 @@ public class User {
public String getUsername() { return username; }
public void setUsername(String username) {this.username = username; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
}

@ -189,6 +189,16 @@ public class UserService {
return true;
}
public boolean updateUserType(String email, String type) {
User user = users.get(email);
if (user == null) {
return false;
}
user.setType(type);
saveUsers();
return true;
}
public boolean validatePassword(String password) {
if (password.length() < 6 || password.length() > 10) {
return false;

@ -114,9 +114,50 @@ public class LoginFrame extends JFrame{
private void openMainFrame(String email) {
User user = userService.getUser(email);
// 这里先简单显示一个消息,后续可以扩展为主界面
JOptionPane.showMessageDialog(this,
"欢迎 " + user.getUsername() + "!\n登录成功主界面功能待实现。",
"登录成功", JOptionPane.INFORMATION_MESSAGE);
// 如果用户类型为空,让用户选择类型
if (user.getType() == null || user.getType().isEmpty()) {
String[] types = {"小学", "初中", "高中"};
String selectedType = (String) JOptionPane.showInputDialog(
this,
"欢迎 " + user.getUsername() + "!\n请选择您的教育阶段",
"选择教育阶段",
JOptionPane.QUESTION_MESSAGE,
null,
types,
types[0] // 默认选择第一个
);
// 如果用户选择了类型(没有点击取消)
if (selectedType != null) {
// 更新用户类型
boolean updated = userService.updateUserType(email, selectedType);
if (updated) {
// 更新本地user对象
user.setType(selectedType);
JOptionPane.showMessageDialog(this,
"登录成功!\n教育阶段" + selectedType,
"登录成功", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this,
"登录成功!\n但教育阶段设置失败",
"登录成功", JOptionPane.WARNING_MESSAGE);
}
} else {
// 如果用户取消选择,可以设置默认类型或者保持为空
userService.updateUserType(email, "小学");
user.setType("小学");
JOptionPane.showMessageDialog(this,
"登录成功!\n已为您选择默认教育阶段小学",
"登录成功", JOptionPane.INFORMATION_MESSAGE);
}
} else {
// 如果已经有类型,直接显示欢迎信息
JOptionPane.showMessageDialog(this,
"欢迎 " + user.getUsername() + "!\n登录成功。\n教育阶段" + user.getType(),
"登录成功", JOptionPane.INFORMATION_MESSAGE);
}
// 后续可以在这里打开主界面
// openMainApplicationWindow(user);
}
}

Loading…
Cancel
Save