Permalink
Browse files

Working logout and log back in

  • Loading branch information...
1 parent 6eb12e2 commit bcec0eac6b0e836ac1630a405efe5fe107c95623 Sam Karp committed Apr 13, 2011
@@ -57,9 +57,9 @@ private void setDefaultSettings() {
Editor editor = prefs.edit();
if(null == prefs.getString("webapp_username", null))
- editor.putString("webapp_username", getString(R.string.default_username));
+ editor.putString("webapp_username", "");
if(null == prefs.getString("webapp_password", null))
- editor.putString("webapp_password", getString(R.string.default_password));
+ editor.putString("webapp_password", "");
editor.commit();
}
}
@@ -1,20 +1,54 @@
package gov.nasa.arc.geocam.talk.activity;
import gov.nasa.arc.geocam.talk.R;
+import gov.nasa.arc.geocam.talk.bean.ServerResponse;
+import gov.nasa.arc.geocam.talk.exception.AuthenticationFailedException;
import gov.nasa.arc.geocam.talk.service.ISiteAuth;
import roboguice.activity.RoboPreferenceActivity;
+import roboguice.inject.InjectResource;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.Toast;
import com.google.inject.Inject;
public class GeoCamTalkSettings extends RoboPreferenceActivity {
@Inject
ISiteAuth siteAuth;
+
+ @Inject
+ SharedPreferences prefs;
+
+ @InjectResource(R.string.url_message_list)
+ String urlMessageList;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.change_preferences);
addPreferencesFromResource(R.xml.prefs);
}
+
+ public void onLoginClick(View v) {
+
+ try {
+ Editor editor = prefs.edit();
+ editor.commit();
+ siteAuth.login(prefs.getString("webapp_username", null),prefs.getString("webapp_password", null));
+ Intent intent = new Intent(this, GeoCamTalkActivity.class);
+ this.startActivity(intent);
+ } catch (AuthenticationFailedException f) {
+ Toast.makeText(this.getApplicationContext(), "Bad Username/Password combination",
+ Toast.LENGTH_SHORT).show();
+ } catch (Exception e) {
+ Log.i("Talk", "Error:" + e.getMessage());
+ }
+
+
+ }
}
@@ -31,6 +31,9 @@ public void reAuthenticate()
public void logout()
throws ClientProtocolException, AuthenticationFailedException, IOException;
+
+ public void login(String username, String password)
+ throws ClientProtocolException, AuthenticationFailedException, IOException;
}
class AuthorizationFailedException extends Exception {
@@ -186,7 +186,7 @@ private void ensureAuthenticated() throws AuthenticationFailedException,
}
}
- private void login(String username, String password) throws ClientProtocolException,
+ public void login(String username, String password) throws ClientProtocolException,
IOException, AuthenticationFailedException {
httpClient = new DefaultHttpClient();
HttpParams params = httpClient.getParams();
@@ -211,6 +211,8 @@ private void login(String username, String password) throws ClientProtocolExcept
}
throw new AuthenticationFailedException(
"Session cookie was missing from server login response.");
+ } else if (200 == r.getStatusLine().getStatusCode()){
+ return;
} else {
throw new AuthenticationFailedException("Got unexpected response code from server: "
+ r.getStatusLine().getStatusCode());

0 comments on commit bcec0ea

Please sign in to comment.