可使用邮箱或用户名登录,修改提示信息显示

liwentao_branch
Teptao 7 months ago
parent 020f87a42f
commit 62fd382179

@ -4,7 +4,14 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="1201acd7-f240-4a23-9c12-26bf9afcb8cb" name="更改" comment="合并更改" />
<list default="true" id="1201acd7-f240-4a23-9c12-26bf9afcb8cb" name="更改" comment="合并更改">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/data/users.txt" beforeDir="false" afterPath="$PROJECT_DIR$/data/users.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/mathapp/panels/LoginPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/mathapp/panels/LoginPanel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/mathapp/services/DataPersistence.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/mathapp/services/DataPersistence.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/com/mathapp/panels/LoginPanel.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/mathapp/panels/LoginPanel.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/com/mathapp/services/DataPersistence.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/mathapp/services/DataPersistence.class" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -136,7 +143,15 @@
<option name="project" value="LOCAL" />
<updated>1760136750934</updated>
</task>
<option name="localTasksCounter" value="5" />
<task id="LOCAL-00005" summary="合并更改">
<option name="closed" value="true" />
<created>1760136867337</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1760136867337</updated>
</task>
<option name="localTasksCounter" value="6" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">

@ -1 +1,4 @@
test@example.com::jZae727K08KaOmKSgOaGzww/XVqLqBG7KAbpTTJzaI0=
test@example.com::jZae727K08KaOmKSgOaGzww/XVqLqBG7KAbpTTJzaI0=
Tester::1650163832@qq.com::7RcqFZEiXA1x7ggr5Sy2xvdMuJb6Xz/P8aMMmj+PZbI=
Tester2::1414246561@qq.com::7RcqFZEiXA1x7ggr5Sy2xvdMuJb6Xz/P8aMMmj+PZbI=

@ -6,6 +6,8 @@ import com.mathapp.services.DataPersistence;
import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
public class LoginPanel extends JPanel {
private final MathApp app;
@ -23,6 +25,52 @@ public class LoginPanel extends JPanel {
emailField = new JTextField(20);
passwordField = new JPasswordField(20);
emailField.setText("请输入账号(支持邮箱或用户名)");
emailField.setForeground(Color.GRAY);
passwordField.setText("........");
passwordField.setForeground(Color.GRAY);
emailField.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
// 获得焦点时,若当前文本是提示文字,则清空并改为黑色
if (emailField.getText().equals("请输入账号(支持邮箱或用户名)")) {
emailField.setText("");
emailField.setForeground(Color.black);
}
}
public void focusLost(FocusEvent e) {
// 失去焦点时,若文本框为空,则恢复灰色提示文字
if (emailField.getText().isEmpty()) {
emailField.setForeground(Color.gray);
emailField.setText("请输入账号(支持邮箱或用户名)");
}
}
});
passwordField.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
// 获得焦点时,若当前文本是提示文字,则清空并改为黑色
if (passwordField.getText().equals("........")) {
passwordField.setText("");
passwordField.setForeground(Color.black);
}
}
public void focusLost(FocusEvent e) {
// 失去焦点时,若文本框为空,则恢复灰色提示文字
if (passwordField.getText().isEmpty()) {
passwordField.setForeground(Color.gray);
passwordField.setText("........");
}
}
});
JButton loginButton = new JButton("登录");
loginButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));
loginButton.setPreferredSize(new Dimension(120, 40));
@ -45,7 +93,7 @@ public class LoginPanel extends JPanel {
gbc.gridwidth = 1;
gbc.gridy = 1;
gbc.anchor = GridBagConstraints.EAST;
add(new JLabel("邮箱:"), gbc);
//add(new JLabel("账号(用户名或邮箱):"), gbc);
gbc.gridx = 1;
gbc.anchor = GridBagConstraints.WEST;
@ -54,7 +102,7 @@ public class LoginPanel extends JPanel {
gbc.gridx = 0;
gbc.gridy = 2;
gbc.anchor = GridBagConstraints.EAST;
add(new JLabel("密码:"), gbc);
//add(new JLabel("密码:"), gbc);
gbc.gridx = 1;
gbc.anchor = GridBagConstraints.WEST;
@ -83,7 +131,7 @@ public class LoginPanel extends JPanel {
String password = new String(passwordField.getPassword());
if (email.isEmpty() || password.isEmpty()) {
JOptionPane.showMessageDialog(this, "邮箱和密码不能为空!", "错误", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(this, "账号和密码不能为空!", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
@ -92,7 +140,7 @@ public class LoginPanel extends JPanel {
app.setCurrentUserEmail(email);
app.showPanel(MathApp.MAIN_MENU_PANEL);
} else {
JOptionPane.showMessageDialog(this, "邮箱或密码错误!", "登录失败", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(this, "账号或密码错误!", "登录失败", JOptionPane.ERROR_MESSAGE);
}
}
}

@ -45,7 +45,7 @@ public class DataPersistence {
try (Stream<String> lines = Files.lines(USER_FILE_PATH, StandardCharsets.UTF_8)) {
return lines.filter(line -> {
String[] parts = line.split("::");
return parts.length >= 3 && parts[1].equals(email);
return parts.length >= 3 && (parts[1].equals(email)||parts[0].equals(email));
})
.map(line -> {
String[] parts = line.split("::");

Loading…
Cancel
Save