|
|
|
@ -29,7 +29,6 @@ public class LoginActivity extends AppCompatActivity {
|
|
|
|
|
mLoginButton = findViewById(R.id.login);
|
|
|
|
|
// 设置登录按钮的点击事件
|
|
|
|
|
mLoginButton.setOnClickListener(v -> {
|
|
|
|
|
|
|
|
|
|
attemptLogin();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -37,19 +36,23 @@ public class LoginActivity extends AppCompatActivity {
|
|
|
|
|
String username = mUsername.getText().toString();
|
|
|
|
|
String password = mPassword.getText().toString();
|
|
|
|
|
boolean if_correct = verifyUser(username,password);
|
|
|
|
|
if (!isInputUsernameValid(username)){
|
|
|
|
|
Toast.makeText(this, "用户名非法", Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
if (!isInputPasswordValid(password)){
|
|
|
|
|
Toast.makeText(this, "密码非法", Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
if (if_correct) {
|
|
|
|
|
Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
|
|
|
|
|
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
finish(); // 关闭登录界面
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
|
|
|
|
|
if (!isInputUsernameValid(username) || !isInputPasswordValid(password)){
|
|
|
|
|
if (!isInputUsernameValid(username) && !isInputPasswordValid(password)) {
|
|
|
|
|
Toast.makeText(this, "用户名和密码非法", Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
else if (!isInputPasswordValid(password)){
|
|
|
|
|
Toast.makeText(this, "密码非法", Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
else {Toast.makeText(this, "用户名非法", Toast.LENGTH_SHORT).show();}
|
|
|
|
|
}else {
|
|
|
|
|
if (if_correct) {
|
|
|
|
|
Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
|
|
|
|
|
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|
finish(); // 关闭登录界面
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -93,4 +96,5 @@ public class LoginActivity extends AppCompatActivity {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|