我目前正在构建一个后端有 Parse 的应用程序。我意识到用户可以在多个设备上登录他的帐户。有没有办法可以一次将其限制在一台设备上?如果是这样,您能否解释一下该方法。提前致谢。
1238 次
2 回答
0
您需要监视应用程序将您的 Web 环境(例如 web 服务)一旦有人登录,您必须断开连接到同一用户的其他设备。
您可以通过最后一次登录请求的 IMEI 对其进行分析,并向同一用户的其他设备发送命令以删除访问权限。
于 2015-08-17T02:21:21.970 回答
0
我来这里寻找解决方案,但没有找到。通过反复试验,我已经解决了。我是一名新手开发人员,不知道这是否是最佳做法,但它确实有效。当用户尝试登录时,执行以下操作。
public void login(View v) {
// Create string variables for data.
String username = et_username.getText().toString().toLowerCase().trim();
String password = et_password.getText().toString();
// If a user is already on this device, log them out.
// this will happen when the force log out happens, the device will
// simply catch the invalid session, but still have that user data, just unavailable
user = ParseUser.getCurrentUser();
if (user != null)
user.logOutInBackground();
ParseUser.logInInBackground(username, password, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException e) {
final ParseQuery<ParseObject> query = new ParseQuery<>("_Session");
query.include("user");
query.whereEqualTo("user", ParseUser.getCurrentUser()); // Only get sessions for the specific user.
query.addAscendingOrder("createdAt"); // Place them in chronological order, with the oldest at the top.
query.countInBackground(new CountCallback() {
@Override
public void done(int count, ParseException e) {
if (count > 1) {
try {
query.getFirst().deleteInBackground();
} catch (ParseException e1) {
Toast.makeText(LoginActivity.this, e1.toString(), Toast.LENGTH_LONG).show();
}
}
}
});
if (user != null) {
emailVerified = user.getBoolean("emailVerified");
if (emailVerified) {
// Update the database to track their log in.
user.put("loggedIn", true);
user.saveInBackground();
if (!deliquent) {
// Launch the MainActivity.
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
}
else {
Intent intent = new Intent(LoginActivity.this, CardActivity.class);
startActivity(intent);
}
}
else {
Toast.makeText(LoginActivity.this, getResources().getString(R.string.verify), Toast.LENGTH_SHORT).show();
}
}
else {
Toast.makeText(LoginActivity.this, "From LoginActivity line:213\n" + e.toString(), Toast.LENGTH_SHORT).show();
}
}
});
}
于 2018-08-15T04:02:50.960 回答