1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
| package com.ta3alam.activity;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
ProgressDialog pDialog;
JSONParser jsonParser;
String login ="par Defaut";
String password ="par defaut";
String loginSaisi;
String passwordSaisi;
EditText inputLogin = null;
EditText inputPassword = null;
Button btnConnexion = null;
Button btnInscription = null;
// url to create new product
private static String url_get_user_details = "http://192.168.1.8/ta3alam_conectitivty/get_user_details.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_USER = "utilisateur";
private static final String TAG_LOGIN="login";
private static final String TAG_PASSWORD="password";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.authentification);
inputLogin =(EditText)findViewById(R.id.editTextLogin);
inputPassword =(EditText)findViewById(R.id.editTextPassword);
btnConnexion = (Button)findViewById(R.id.buttonConnection);
btnConnexion.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new GetUser().execute();
}
});
btnInscription =(Button)findViewById(R.id.btnInscription);
btnInscription.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),NewUserActivity.class);
startActivity(i);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
class GetUser extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Loading product details. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Getting product details in background thread
* */
protected String doInBackground(String... params) {
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
// Check for success tag
int success;
try {
loginSaisi = inputLogin.getText().toString();
passwordSaisi = inputPassword.getText().toString();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("login", loginSaisi));
// getting product details by making HTTP request
// Note that product details url will use GET request
//
JSONObject json = jsonParser.makeHttpRequest(
url_get_user_details, "GET", params);//le debogage bloque ici
// check your log for json response
Log.d("Single Product Details", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully received product details
JSONArray productObj = json
.getJSONArray(TAG_USER); // JSON Array
// get first product object from JSON Array
JSONObject user = productObj.getJSONObject(0);
login = user.getString(TAG_LOGIN);
password = user.getString(TAG_PASSWORD);
if(testAuthentification(login, password, loginSaisi, passwordSaisi))
{
Intent i = new Intent(getApplicationContext(),Bienvenu.class);
startActivity(i);
}
}else{
// product with pid not found
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once got all details
pDialog.dismiss();
}
}
private boolean testAuthentification(final String login1 ,final String password1,final String login2,final String password2)
{
if(login1.equals(login2) && password1.equals(password2))
{
return true;
}else
{
return false;
}
}
} |
Partager