|
|
|
|
@ -7,7 +7,6 @@ package id.amigogroup.posterminal.keamanan;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
|
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
|
|
import id.amigogroup.posterminal.SystemValue;
|
|
|
|
|
import id.amigogroup.posterminal.api.AmigoPosRx;
|
|
|
|
|
@ -18,7 +17,6 @@ import io.reactivex.Observable;
|
|
|
|
|
import io.reactivex.Observer;
|
|
|
|
|
import io.reactivex.disposables.Disposable;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.ResourceBundle;
|
|
|
|
|
@ -84,7 +82,7 @@ public class FormLoginController implements Initializable {
|
|
|
|
|
posRx.getKaryawanByNik(fldNamaPengguna.getText()),
|
|
|
|
|
posRx.loginKaryawanByNikPin(nik, fldKataSandi.getText()),
|
|
|
|
|
(Karyawan k, ResponseBody response) -> {
|
|
|
|
|
return new KaryawanLogin(k, response);
|
|
|
|
|
return new KaryawanLogin(k,response);
|
|
|
|
|
}).subscribe(karyawanLoginObserver);
|
|
|
|
|
} else {
|
|
|
|
|
Alert alert = AlertUtil.getAlertWarning(
|
|
|
|
|
@ -108,14 +106,15 @@ public class FormLoginController implements Initializable {
|
|
|
|
|
try {
|
|
|
|
|
JsonNode jsonNode = mapper.readTree(k.result.string());
|
|
|
|
|
ObjectNode objectNode = jsonNode.deepCopy();
|
|
|
|
|
if (objectNode.get("status").asBoolean()) {
|
|
|
|
|
|
|
|
|
|
if(objectNode.get("status").asBoolean()){
|
|
|
|
|
SystemValue.karyawanLogin = k.karyawan;
|
|
|
|
|
generateNewWindow("/fxml/FormUtama.fxml").show();
|
|
|
|
|
|
|
|
|
|
Stage thisStage = (Stage) apMain.getScene().getWindow();
|
|
|
|
|
thisStage.hide();
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("Gagal ");
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
Alert alert = AlertUtil.getAlertError(
|
|
|
|
|
AlertUtil.ERROR_KARYAWAN_TIDAK_BOLEH_AKSES_TITLE,
|
|
|
|
|
objectNode.get("message").asText());
|
|
|
|
|
@ -143,46 +142,13 @@ public class FormLoginController implements Initializable {
|
|
|
|
|
@Override
|
|
|
|
|
public void onError(Throwable error) {
|
|
|
|
|
if (error instanceof HttpException) {
|
|
|
|
|
HttpException httpError = (HttpException) error;
|
|
|
|
|
Alert alert;
|
|
|
|
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
try {
|
|
|
|
|
JsonNode jsonNode = null;
|
|
|
|
|
ObjectNode objectNode = new ObjectNode(JsonNodeFactory.instance);
|
|
|
|
|
objectNode.put("message", "Login invalid. Username/password salah");
|
|
|
|
|
if (httpError.response() != null && httpError.response().errorBody() != null) {
|
|
|
|
|
jsonNode = mapper.readTree(httpError.response().errorBody().string());
|
|
|
|
|
|
|
|
|
|
objectNode = jsonNode.deepCopy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (((HttpException) error).code()) {
|
|
|
|
|
case HttpURLConnection.HTTP_NOT_FOUND:
|
|
|
|
|
alert = AlertUtil.getAlertError(
|
|
|
|
|
Alert alert = AlertUtil.getAlertError(
|
|
|
|
|
AlertUtil.ERROR_TIDAK_DITEMUKAN_TITLE,
|
|
|
|
|
"Karyawan dengan nomor tersebut tidak ditemukan.");
|
|
|
|
|
alert.initOwner(apMain.getScene().getWindow());
|
|
|
|
|
alert.show();
|
|
|
|
|
break;
|
|
|
|
|
case HttpURLConnection.HTTP_BAD_REQUEST:
|
|
|
|
|
alert = AlertUtil.getAlertError(
|
|
|
|
|
AlertUtil.ERROR_KARYAWAN_TIDAK_BOLEH_AKSES_TITLE,
|
|
|
|
|
objectNode.get("message").asText());
|
|
|
|
|
alert.initOwner(apMain.getScene().getWindow());
|
|
|
|
|
alert.show();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Logger.getLogger(FormLoginController.class.getName()).log(Level.SEVERE, null, error);
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
alert = AlertUtil.getAlertError(
|
|
|
|
|
AlertUtil.ERROR_KARYAWAN_TIDAK_BOLEH_AKSES_TITLE,
|
|
|
|
|
"Terjadi error yang tidak diduga sehingga karyawan tidak boleh mengakses.");
|
|
|
|
|
alert.initOwner((Stage) apMain.getScene().getWindow());
|
|
|
|
|
alert.show();
|
|
|
|
|
|
|
|
|
|
Logger.getLogger(FormLoginController.class.getName()).log(Level.SEVERE, null, ex);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
AmigoPosRx.handleGenericError(error, apMain.getScene().getWindow());
|
|
|
|
|
@ -194,8 +160,7 @@ public class FormLoginController implements Initializable {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private class KaryawanLogin {
|
|
|
|
|
|
|
|
|
|
private class KaryawanLogin{
|
|
|
|
|
private Karyawan karyawan;
|
|
|
|
|
private ResponseBody result;
|
|
|
|
|
|
|
|
|
|
|