0

I've this android app from which users can signin and signup to Yii
the signin and signup works fine but when I'm sending other requests like editing Posts and other things, Yii doesn't remember the user, like the user never signed in.
now what information I need to save in the app and send with each request so that Yii know this user has signed in before.
this is the information that I send with my signin request:

ArrayList<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
nameValuePair.add(new BasicNameValuePair("email", signinEmail.getText().toString()));
nameValuePair.add(new BasicNameValuePair("password", signinPassword.getText().toString()));
HttpRequest siginRequest = new HttpRequest();
JSONObject signinResult = siginRequest.post("users/signin", nameValuePair);

please help me cause it's driving me crazy :(

Amirhossein Mehrvarzi
  • 18,024
  • 7
  • 45
  • 70
Mohsen Shakiba
  • 1,762
  • 3
  • 22
  • 41

2 Answers2

1

It seems you're trying to communicate through http, say, port number 80 over the web. Take a look at How to do HTTP authentication in android? that covers one that you wanna do.

If you insist on using key/value pairs for appending credentials to each http request using SharedPreferences is more organized to meet your purpose. So Once you get these values from the response, store them with:

SharedPreferences apiVals = getSharedPreferences("credentials", MODE_PRIVATE);
apivals.edit()
   .putString("authToken", authToken)
   .putString("Session", SessionId)
   .commit();

For retrieving:

SharedPreferences apiVals = getSharedPreferences("apiVals", MODE_PRIVATE);
String authToken = apiVals.getString("authToken", null);
Community
  • 1
  • 1
Amirhossein Mehrvarzi
  • 18,024
  • 7
  • 45
  • 70
0

Yii saves information in the $_SESSION variable on the server (and possibly in cookies but I can't recall for sure) but you aren't saving that.

Larry Borsato
  • 394
  • 3
  • 5