From ecb9173dd4eac3d12d135959324d542d11a0fab1 Mon Sep 17 00:00:00 2001 From: Anubhaw Arya Date: Fri, 11 Jan 2013 22:06:59 -0500 Subject: [PATCH] Account Data Management --- src/com/example/campusfeed/Accounts.java | 45 +++++++++++-- src/com/example/campusfeed/CreateAccount.java | 67 ++++++++++++------- src/com/example/campusfeed/SignIn.java | 4 ++ 3 files changed, 84 insertions(+), 32 deletions(-) diff --git a/src/com/example/campusfeed/Accounts.java b/src/com/example/campusfeed/Accounts.java index c98cc77..7712902 100644 --- a/src/com/example/campusfeed/Accounts.java +++ b/src/com/example/campusfeed/Accounts.java @@ -14,28 +14,59 @@ public class Accounts { // TODO Fix this - public Accounts(){ - + static String s; + static String username, password,email; + static String[] starredEvents, createdEvents; + + public static void setUsername(String user) + { + username = user; } - public static void starEvent(String uniqueId, String email) + public static void setPassword(String pass) { - new AccountOnline().execute(uniqueId, email); + password = pass; + } + public static void setEmail(String addy){ + email=addy; } - public static void ReadAccountInfo() + public static void setStarredEvents(String[] events) { + starredEvents = events; + } + public static void setCreatedEvents(String[] events) + { + createdEvents = events; } - public static void MyEvents() + public static String getUsername() { + return username; + } + public static String getEmail(){ + return email; + } + public static String getPassword() + { + return password; + } + + public static String[] getStarredEvents() + { + return starredEvents; } - public static void starredEvents() + public static String[] setCreatedEvents() { + return createdEvents; + } + public static void starEvent(String uniqueId, String email) + { + new AccountOnline().execute(uniqueId, email); } } diff --git a/src/com/example/campusfeed/CreateAccount.java b/src/com/example/campusfeed/CreateAccount.java index d8eac6e..8e6a81d 100644 --- a/src/com/example/campusfeed/CreateAccount.java +++ b/src/com/example/campusfeed/CreateAccount.java @@ -2,10 +2,13 @@ import java.io.IOException; import org.apache.http.HttpResponse; +import org.apache.http.ParseException; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.util.EntityUtils; + import android.os.AsyncTask; import android.os.Bundle; import android.app.Activity; @@ -19,7 +22,7 @@ public class CreateAccount extends Activity { EditText userName, passWord, email; - static TextView error; + TextView error; protected void onCreate(Bundle savedInstanceState) { @@ -52,34 +55,48 @@ public void onClick(View v) } }); } -} - -class createAcc extends AsyncTask -{ - protected String doInBackground(String... params) + class createAcc extends AsyncTask { - String url = "http://ezevents.6te.net/createaccount.php" + "?email=" - + params[0] + "&username=" + params[1] + "&password=" - + params[2]; - HttpGet httpGet = new HttpGet(url); - HttpClient h = new DefaultHttpClient(); - HttpResponse r = null; - try - { - // execute request - r = h.execute(httpGet); - } catch (ClientProtocolException e1) + + protected String doInBackground(String... params) { - Log.d("APP", e1.getMessage()); - } catch (IOException e1) + String url = "http://ezevents.6te.net/createaccount.php" + + "?email=" + params[0] + "&username=" + params[1] + + "&password=" + params[2]; + HttpGet httpGet = new HttpGet(url); + HttpClient h = new DefaultHttpClient(); + HttpResponse r = null; + try + { + // execute request + r = h.execute(httpGet); + } catch (ClientProtocolException e1) + { + Log.d("APP", e1.getMessage()); + } catch (IOException e1) + { + Log.d("APP", e1.getMessage()); + } + try + { + return EntityUtils.toString(r.getEntity()); + } catch (ParseException e) + { + Log.d("ERROR", e.getMessage()); + } catch (IOException e) + { + Log.d("ERROR", e.getMessage()); + } + return null; + } + + protected void onPostExecute(String response) { - Log.d("APP", e1.getMessage()); + if (response.equals("fail") || response == null) + error.setVisibility(View.VISIBLE); + else + CreateAccount.this.finish(); } - if (r.getEntity().equals("fail")) - CreateAccount.error.setVisibility(View.VISIBLE); - else - CreateAccount.error.setVisibility(View.GONE); - return null; } } diff --git a/src/com/example/campusfeed/SignIn.java b/src/com/example/campusfeed/SignIn.java index 62c9491..2ad20b7 100644 --- a/src/com/example/campusfeed/SignIn.java +++ b/src/com/example/campusfeed/SignIn.java @@ -109,6 +109,10 @@ protected void onPostExecute(String result) error.setVisibility(View.VISIBLE); } else { + Accounts.setUsername(userName.getText().toString()); + Accounts.setPassword(passWord.getText().toString()); + String[] array=result.split("|"); + Accounts.setEmail(array[0]); error.setVisibility(View.GONE); p.dismiss(); SignIn.this.finish();