You need to sign in or sign up before continuing.
Commit ce8799a5 authored by Ahmad Abi Mulya's avatar Ahmad Abi Mulya

fix login validation message to API Response

parent fa060dba
......@@ -25,7 +25,6 @@ import retrofit2.Response;
public class LoginActivity extends AppCompatActivity {
ActivityLoginBinding binding;
private PrefManager prefManager;
UserViewModel viewModel;
@Override
......@@ -43,10 +42,6 @@ public class LoginActivity extends AppCompatActivity {
binding.btnLogin.setOnClickListener(view -> {
if(binding.etUsername.getText().toString().length() == 0 || binding.etPassword.getText().toString().length() == 0){
Toast.makeText(getApplicationContext(), "Please input Username and Password", Toast.LENGTH_SHORT).show();
}else if(!binding.etPassword.getText().toString().matches("[A-Za-z0-9]+")){
binding.etPassword.setError("Passwords can only contain Alphanumeric");
}else if(binding.etPassword.getText().toString().length() < 8) {
binding.etPassword.setError("Password length cannot be less than 8 characters");
}else{
binding.setLoading(true);
viewModel.setListUser();
......@@ -72,16 +67,17 @@ public class LoginActivity extends AppCompatActivity {
ApiClient.client(UserService.class, UserViewModel.BASE_URL).loginUser(login).enqueue(new Callback<ResponseLogin>() {
@Override
public void onResponse(Call<ResponseLogin> call, Response<ResponseLogin> response) {
if (response.code() >= 200 & response.code() <= 299){
if (response.body()!= null){
Log.d("body", String.valueOf(response.body().getData().getFullName()));
prefManager.setFirstLogin(false);
binding.setLoading(false);
Toast.makeText(getApplicationContext(), response.body().getMessages(), Toast.LENGTH_LONG).show();
startActivity(new Intent(LoginActivity.this, MainActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
prefManager.setDataUser(response.body().getData().getFullName());
finish();
}else{
Toast.makeText(getApplicationContext(), "Email or password wrong", Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), response.body().getMessages(), Toast.LENGTH_LONG).show();
binding.setLoading(false);
}
}
......
......@@ -50,6 +50,7 @@ public class RegisterActivity extends AppCompatActivity {
viewModel.registrasi(user);
Toast.makeText(getApplicationContext(), "Register Was Successful", Toast.LENGTH_LONG).show();
startActivity(new Intent(getApplicationContext(), LoginActivity.class));
finish();
}
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment