简体   繁体   中英

authenticate users from android in Yii

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 :(

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);

Yii将信息保存在服务器上的$ _SESSION变量中(并且可能保存在cookie中,但我无法确定),但是您没有保存该信息。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM