CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
String url = "https://www.----.php";
StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if(response.equals("Login Success")){
startActivity(new Intent(login.this, fragment_steuerung.class));
finish();
}else if(response.equals("LS1")){
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(getResources().getString(R.string.prefLoginState), "loggendin");
editor.apply();
startActivity(new Intent(login.this, fragment_steuerung.class));
finish();
}else if(response.equals("Dein Account ist nicht Aktiviert wurden. Bitte Bestätige deine Email Adresse.")){
AlertDialog.Builder builder = new AlertDialog.Builder(login.this, R.style.AlertDialogTheme);
View view = LayoutInflater.from(login.this).inflate(R.layout.layout_email_dialog, (ConstraintLayout)findViewById(R.id.layoutDialogContainer));
builder.setView(view);
((TextView)view.findViewById(R.id.textTitle)).setText(getString(R.string.account_nicht_acktiviert_dialog_ueber));
((TextView)view.findViewById(R.id.textView_email)).setText(getString(R.string.account_nicht_aktiviert));
((Button)view.findViewById(R.id.buttonAction)).setText(getString(R.string.okay));
((ImageView)view.findViewById(R.id.image_email)).setImageResource(R.drawable.ic_email2);
final AlertDialog alertDialog = builder.create();
view.findViewById(R.id.buttonAction).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
if (alertDialog.getWindow() != null){
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.show();
}else{
AlertDialog.Builder builder = new AlertDialog.Builder(login.this, R.style.AlertDialogTheme);
View view = LayoutInflater.from(login.this).inflate(R.layout.layout_error_dialog, (ConstraintLayout)findViewById(R.id.layoutDialogContainer));
builder.setView(view);
((TextView)view.findViewById(R.id.textTitle)).setText(getString(R.string.login_fehlgeschlagen_uber));
((TextView)view.findViewById(R.id.textView_error)).setText(getString(R.string.login_fehlgeschlagen_grund) + " " + response);
((Button)view.findViewById(R.id.buttonAction)).setText(getString(R.string.okay));
((ImageView)view.findViewById(R.id.image_error)).setImageResource(R.drawable.ic_error);
final AlertDialog alertDialog = builder.create();
view.findViewById(R.id.buttonAction).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
if (alertDialog.getWindow() != null){
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
AlertDialog.Builder builder = new AlertDialog.Builder(login.this, R.style.AlertDialogTheme);
View view = LayoutInflater.from(login.this).inflate(R.layout.layout_error_dialog, (ConstraintLayout)findViewById(R.id.layoutDialogContainer));
builder.setView(view);
((TextView)view.findViewById(R.id.textTitle)).setText("VolleyError");
((TextView)view.findViewById(R.id.textView_error)).setText("ERROR: " + error.toString());
((Button)view.findViewById(R.id.buttonAction)).setText(getString(R.string.okay));
((ImageView)view.findViewById(R.id.image_error)).setImageResource(R.drawable.ic_error);
final AlertDialog alertDialog = builder.create();
view.findViewById(R.id.buttonAction).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
if (alertDialog.getWindow() != null){
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
}
alertDialog.show();
}
}){
@Nullable
@Override
protected Map<String, String> getParams() throws AuthFailureError {
HashMap<String, String> param = new HashMap<>();
param.put("email", emailadresse);
param.put("pass", passwort);
param.put("paname", packagename);
return param;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> header = new HashMap<>();
return header;
}
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
String header_response = String.valueOf(response.headers.values());
int index1 = header_response.indexOf("PHPSESSID=");
int index2 = header_response.indexOf(("; path"));
String session_id = header_response.substring(index1, index2);
SharedPreferences sharedPreferences = getSharedPreferences("Session", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("SessionID", session_id);
editor.apply();
Log.d("Cookie", session_id);
return Response.success(jsonString, HttpHeaderParser.parseCacheHeaders(response));
}catch (UnsupportedEncodingException e){
Log.d("Cookie Fehler", e.toString());
return Response.error(new ParseError(e));
}
}
};
request.setRetryPolicy(new DefaultRetryPolicy(30000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
MySingleRegister.getmInstance(login.this).addToRequestQueue(request);