diff options
author | Andy Scherzinger <info@andy-scherzinger.de> | 2017-09-21 12:41:36 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-21 12:41:36 +0300 |
commit | 2f5ddc4566465a223cce4d195958473b0c890d8a (patch) | |
tree | 4e32c001b22ae7fe02a80eac98de3338f8130472 | |
parent | 5805bdbe1d7ebfe4951f400c83e08206018af6de (diff) | |
parent | a98a1cc6639cc554c77ffdd8dcf7e5b32147475e (diff) |
Merge pull request #90 from nextcloud/pushWarning1.0.31
Support for checking if old login is used
2 files changed, 18 insertions, 3 deletions
diff --git a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java index eb53ce11..b9cf0605 100644 --- a/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java +++ b/src/com/owncloud/android/lib/common/operations/RemoteOperationResult.java @@ -122,7 +122,8 @@ public class RemoteOperationResult implements Serializable { NOT_AVAILABLE, MAINTENANCE_MODE, LOCK_FAILED, - DELAYED_IN_POWER_SAVE_MODE + DELAYED_IN_POWER_SAVE_MODE, + ACCOUNT_USES_STANDARD_PASSWORD } private boolean mSuccess = false; diff --git a/src/com/owncloud/android/lib/resources/notifications/RegisterAccountDeviceForNotificationsOperation.java b/src/com/owncloud/android/lib/resources/notifications/RegisterAccountDeviceForNotificationsOperation.java index 9d1f7b18..fea39af4 100644 --- a/src/com/owncloud/android/lib/resources/notifications/RegisterAccountDeviceForNotificationsOperation.java +++ b/src/com/owncloud/android/lib/resources/notifications/RegisterAccountDeviceForNotificationsOperation.java @@ -55,10 +55,12 @@ public class RegisterAccountDeviceForNotificationsOperation extends RemoteOperat // JSON Node names private static final String NODE_OCS = "ocs"; private static final String NODE_DATA = "data"; + private static final String MESSAGE = "message"; private static final String PUSH_TOKEN_HASH = "pushTokenHash"; private static final String DEVICE_PUBLIC_KEY = "devicePublicKey"; private static final String PROXY_SERVER = "proxyServer"; + private static final String INVALID_SESSION_TOKEN = "INVALID_SESSION_TOKEN"; private String pushTokenHash; private String devicePublicKey; @@ -93,7 +95,7 @@ public class RegisterAccountDeviceForNotificationsOperation extends RemoteOperat status = client.executeMethod(post); String response = post.getResponseBodyAsString(); - if(isSuccess(status)) { + if (isSuccess(status)) { result = new RemoteOperationResult(true, status, post.getResponseHeaders()); Log_OC.d(TAG, "Successful response: " + response); @@ -101,7 +103,11 @@ public class RegisterAccountDeviceForNotificationsOperation extends RemoteOperat pushResponse = parseResult(response); result.setPushResponseData(pushResponse); } else { - result = new RemoteOperationResult(false, status, post.getResponseHeaders()); + if (isInvalidSessionToken(response)) { + result = new RemoteOperationResult(RemoteOperationResult.ResultCode.ACCOUNT_USES_STANDARD_PASSWORD); + } else { + result = new RemoteOperationResult(false, status, post.getResponseHeaders()); + } } } catch (Exception e) { @@ -127,6 +133,14 @@ public class RegisterAccountDeviceForNotificationsOperation extends RemoteOperat return gson.fromJson(jsonDataObject, pushResponseType); } + private boolean isInvalidSessionToken(String response) { + JsonParser jsonParser = new JsonParser(); + JsonObject jsonObject = (JsonObject)jsonParser.parse(response); + String message = jsonObject.getAsJsonObject(NODE_OCS).getAsJsonObject(NODE_DATA).get(MESSAGE).getAsString(); + + return INVALID_SESSION_TOKEN.equals(message); + } + private boolean isSuccess(int status) { return (status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED); } |