Login via settings working
This commit is contained in:
@@ -4,6 +4,7 @@ import android.accounts.AbstractAccountAuthenticator;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountAuthenticatorResponse;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AccountsException;
|
||||
import android.accounts.NetworkErrorException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -12,9 +13,13 @@ import android.text.TextUtils;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
public class FUAuthenticator extends AbstractAccountAuthenticator {
|
||||
|
||||
private final Context mContext;
|
||||
private Logger log = new Logger(this);
|
||||
|
||||
public FUAuthenticator(Context context) {
|
||||
super(context);
|
||||
@@ -28,6 +33,18 @@ public class FUAuthenticator extends AbstractAccountAuthenticator {
|
||||
|
||||
@Override
|
||||
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
|
||||
final AccountManager am = AccountManager.get(mContext);
|
||||
log.d((Object[]) am.getAccountsByType(accountType));
|
||||
log.d(am.getAccountsByType(accountType).length);
|
||||
if (am.getAccountsByType(accountType).length > 0) {
|
||||
final Intent intent = new Intent(mContext, FUAuthenticatorActivity.class);
|
||||
intent.putExtra(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION);
|
||||
intent.putExtra(AccountManager.KEY_ERROR_MESSAGE, "Already an account added!");
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
final Intent intent = new Intent(mContext, FUAuthenticatorActivity.class);
|
||||
intent.putExtra(FUAuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType);
|
||||
intent.putExtra(FUAuthenticatorActivity.ARG_AUTH_TYPE, authTokenType);
|
||||
|
||||
@@ -55,6 +55,7 @@ public class FUAuthenticatorActivity extends AccountAuthenticatorActivity {
|
||||
|
||||
mAccountType = getIntent().getStringExtra(ARG_ACCOUNT_TYPE);
|
||||
mAuthTokenType = getIntent().getStringExtra(ARG_AUTH_TYPE);
|
||||
mAuthTokenType = mAuthTokenType != null ? mAuthTokenType : AccountGeneral.AUTHTOKEN_TYPE_KVV;
|
||||
mIsAddingNewAccount = getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false);
|
||||
|
||||
setContentView(R.layout.activity_fu_authenticator);
|
||||
|
||||
@@ -18,6 +18,7 @@ import de.sebse.fuplanner.services.kvv.sync.BBLogin;
|
||||
import de.sebse.fuplanner.services.kvv.sync.FULogin;
|
||||
import de.sebse.fuplanner.services.kvv.sync.KVVLogin;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
|
||||
|
||||
@@ -46,7 +47,7 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
|
||||
@Nullable
|
||||
private FUAuthenticatorActivity mActivity;
|
||||
|
||||
UserLoginTask(String username, String password, String tokenType, @NotNull Context context) {
|
||||
UserLoginTask(String username, String password, @NotNull String tokenType, @NotNull Context context) {
|
||||
mUsername = username;
|
||||
mPassword = password;
|
||||
mTokenType = tokenType;
|
||||
@@ -95,6 +96,7 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
|
||||
}, errorFunc);
|
||||
break;
|
||||
default:
|
||||
errorFunc.onError(new NetworkError(104100, 400, "Invalid auth token type"));
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user