Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public enum ResultCode {
NOT_AVAILABLE,
MAINTENANCE_MODE,
LOCK_FAILED,
DELAYED_IN_POWER_SAVE_MODE
DELAYED_IN_POWER_SAVE_MODE,
ACCOUNT_USES_STANDARD_PASSWORD
}

private boolean mSuccess = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,15 +95,19 @@ protected RemoteOperationResult run(OwnCloudClient client) {
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);

// Parse the response
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) {
Expand All @@ -127,6 +133,14 @@ private PushResponse parseResult(String response) throws JSONException {
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);
}
Expand Down