简体   繁体   English

在Yii中从android验证用户身份

[英]authenticate users from android in Yii

I've this android app from which users can signin and signup to Yii 我有这个android应用,用户可以从中登录和注册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. 登录和注册工作正常,但是当我发送其他请求(例如编辑帖子等)时,Yii不会记住该用户,就像该用户从未登录过一样。
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. 现在,我需要将哪些信息保存在应用程序中并随每个请求一起发送,以便Yii知道该用户之前已登录。
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. 看来您正在尝试通过http(例如80)端口在网络上进行通信。 Take a look at How to do HTTP authentication in android? 看看如何在Android中进行HTTP身份验证? 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. 如果您坚持使用键/值对将凭据附加到每个HTTP请求,则使用SharedPreferences可以更好地满足您的目的。 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中,但我无法确定),但是您没有保存该信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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