|
|
@@ -22,6 +22,21 @@ import android.widget.Button;
|
|
|
import android.widget.EditText;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.apache.http.NameValuePair;
|
|
|
+import org.apache.http.client.HttpClient;
|
|
|
+import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
+import org.apache.http.message.BasicNameValuePair;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
+import org.json.JSONObject;
|
|
|
+
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* A login screen that offers login via email/password.
|
|
|
@@ -39,6 +54,7 @@ public class LoginActivity extends Activity implements LoaderCallbacks<Cursor> {
|
|
|
private EditText mPasswordView;
|
|
|
private View mProgressView;
|
|
|
private View mLoginFormView;
|
|
|
+ private Usuario user = new Usuario();
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@@ -205,12 +221,38 @@ public class LoginActivity extends Activity implements LoaderCallbacks<Cursor> {
|
|
|
@Override
|
|
|
protected Boolean doInBackground(Void... params) {
|
|
|
// TODO: attempt authentication against a network service.
|
|
|
-
|
|
|
+ HttpClient httpclient = new DefaultHttpClient();
|
|
|
+ HttpPost httppost = new HttpPost("https://plataforma.especificosba.com.ar/back/loginLive.php");
|
|
|
try {
|
|
|
// Simulate network access.
|
|
|
- Thread.sleep(200);
|
|
|
|
|
|
- } catch (InterruptedException e) {
|
|
|
+ MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
|
|
|
+ messageDigest.update(mPassword.getBytes("UTF-8"));
|
|
|
+ String hashedPass=String.format("%064x", new java.math.BigInteger(1, messageDigest.digest()));
|
|
|
+ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
|
|
|
+ nameValuePairs.add(new BasicNameValuePair("email", mEmail));
|
|
|
+ nameValuePairs.add(new BasicNameValuePair("pass", hashedPass));
|
|
|
+ httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
|
|
|
+ //execute http post
|
|
|
+ HttpResponse response = httpclient.execute(httppost);
|
|
|
+ int code = response.getStatusLine().getStatusCode();
|
|
|
+ if(code==400){
|
|
|
+ return false; //User/pass invalidos
|
|
|
+ }
|
|
|
+ if(code==401){
|
|
|
+ return false; //No hay ahora
|
|
|
+ }
|
|
|
+ HttpEntity entity = response.getEntity();
|
|
|
+ String responseString = EntityUtils.toString(entity, "UTF-8");
|
|
|
+ JSONObject obj = new JSONObject(responseString);
|
|
|
+ user.apellido=obj.getString("apellido");
|
|
|
+ user.nombre=obj.getString("nombre");
|
|
|
+ user.pais=obj.getString("pais");
|
|
|
+ user.ciudad=obj.getString("ciudad");
|
|
|
+ //{"apellido":"Ventura","ciudad":"Trelew","nombre":"David","pais":"Argentina","provincia":"Chubut"}
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -225,6 +267,7 @@ public class LoginActivity extends Activity implements LoaderCallbacks<Cursor> {
|
|
|
|
|
|
if (success) {
|
|
|
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
|
|
|
+ intent.putExtra("usuario", user);
|
|
|
startActivity(intent);
|
|
|
finish();
|
|
|
} else {
|