\r
package com.owncloud.android.ui.activity;\r
\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
import com.owncloud.android.AccountUtils;\r
import com.owncloud.android.authenticator.AccountAuthenticator;\r
import com.owncloud.android.authenticator.oauth2.OAuth2Context;\r
import android.widget.Button;\r
import android.widget.ImageView;\r
import android.widget.TextView;\r
+import android.widget.Toast;\r
+\r
import com.owncloud.android.R;\r
\r
import eu.alefzero.webdav.WebdavClient;\r
private Uri mNewCapturedUriFromOAuth2Redirection;\r
\r
private AccountManager mAccountMgr;\r
+ private boolean mJustCreated;\r
\r
private ImageView mRefreshButton;\r
private ImageView mViewPasswordButton;\r
}\r
\r
mPasswordInput.setText(""); // clean password to avoid social hacking (disadvantage: password in removed if the device is turned aside)\r
+ mJustCreated = true;\r
}\r
\r
\r
@Override\r
protected void onResume() {\r
super.onResume();\r
+ // the state of mOAuth2Check is automatically recovered between configuration changes, but not before onCreate() finishes; so keep the next lines here\r
changeViewByOAuth2Check(mOAuth2Check.isChecked()); \r
- // the state of mOAuth2Check is automatically recovered between configuration changes, but not before onCreate() finishes\r
+ if (getIntent().getByteExtra(EXTRA_ACTION, ACTION_CREATE) == ACTION_UPDATE_TOKEN && mJustCreated) {\r
+ if (mOAuth2Check.isChecked())\r
+ Toast.makeText(this, R.string.auth_expired_oauth_token_toast, Toast.LENGTH_LONG).show();\r
+ else\r
+ Toast.makeText(this, R.string.auth_expired_basic_auth_toast, Toast.LENGTH_LONG).show();\r
+ }\r
+ \r
\r
/* LEAVE OLD OAUTH FLOW ; \r
// (old oauth code) Registering token receiver. We must listening to the service that is pooling to the oAuth server for a token.\r
if (mNewCapturedUriFromOAuth2Redirection != null) {\r
getOAuth2AccessTokenFromCapturedRedirection(); \r
}\r
+ \r
+ mJustCreated = false;\r
}\r
\r
\r
*/\r
private void getOAuth2AccessTokenFromCapturedRedirection() {\r
/// Parse data from OAuth redirection\r
- Map<String, String> responseValues = new HashMap<String, String>();\r
String queryParameters = mNewCapturedUriFromOAuth2Redirection.getQuery();\r
mNewCapturedUriFromOAuth2Redirection = null;\r
- String[] pairs = queryParameters.split("&");\r
- int i = 0;\r
- String key = "";\r
- String value = "";\r
- StringBuilder sb = new StringBuilder();\r
- while (pairs.length > i) {\r
- int j = 0;\r
- String[] part = pairs[i].split("=");\r
- while (part.length > j) {\r
- String p = part[j];\r
- if (j == 0) {\r
- key = p;\r
- sb.append(key + " = ");\r
- } else if (j == 1) {\r
- value = p;\r
- responseValues.put(key, value);\r
- sb.append(value + "\n");\r
- }\r
-\r
- Log.v(TAG, "[" + i + "," + j + "] = " + p);\r
- j++;\r
- }\r
- i++;\r
- }\r
- \r
- /// Updating status widget to OK. -- TODO REMOVE, UNNECESSARY\r
- /*\r
- mStatusIcon = R.drawable.ic_ok;\r
- mStatusText = R.string.auth_connection_established;\r
- updateAuthStatus();\r
- */\r
\r
/// Showing the dialog with instructions for the user.\r
showDialog(DIALOG_OAUTH2_LOGIN_PROGRESS);\r
\r
/// GET ACCESS TOKEN to the oAuth server \r
- RemoteOperation operation = new OAuth2GetAccessToken(responseValues);\r
+ RemoteOperation operation = new OAuth2GetAccessToken(queryParameters);\r
WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth_url_endpoint_access)), getApplicationContext());\r
operation.execute(client, this, mHandler);\r
}\r
break;\r
case OAUTH2_ERROR:\r
mStatusIcon = R.drawable.common_error;\r
- mStatusText = R.string.auth_bad_oauth_token;\r
+ mStatusText = R.string.auth_oauth_error;\r
+ break;\r
+ case OAUTH2_ERROR_ACCESS_DENIED:\r
+ mStatusIcon = R.drawable.common_error;\r
+ mStatusText = R.string.auth_oauth_error_access_denied;\r
break;\r
case UNHANDLED_HTTP_CODE:\r
case UNKNOWN_ERROR:\r
mAuthCheckOperation.execute(client, this, mHandler);\r
\r
} else {\r
- if (webdav_path != null) {\r
- mOAuthAuthEndpointText.setError("A valid authorization could not be obtained");\r
- } else {\r
- mOAuthAuthEndpointText.setError(getString(R.string.auth_bad_oc_version_title)); // should never happen \r
- }\r
+ updateStatusIconAndText(result);\r
+ updateAuthStatus();\r
+ Log.d(TAG, "Access failed: " + result.getLogMessage());\r
}\r
}\r
\r