Login via settings working

This commit is contained in:
Caesar2011
2019-02-05 21:07:35 +01:00
parent 1bbb09499d
commit d78948d349
3 changed files with 21 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import android.accounts.AbstractAccountAuthenticator;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountAuthenticatorResponse; import android.accounts.AccountAuthenticatorResponse;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.accounts.AccountsException;
import android.accounts.NetworkErrorException; import android.accounts.NetworkErrorException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -12,9 +13,13 @@ import android.text.TextUtils;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import de.sebse.fuplanner.tools.CustomAccountManager;
import de.sebse.fuplanner.tools.logging.Logger;
public class FUAuthenticator extends AbstractAccountAuthenticator { public class FUAuthenticator extends AbstractAccountAuthenticator {
private final Context mContext; private final Context mContext;
private Logger log = new Logger(this);
public FUAuthenticator(Context context) { public FUAuthenticator(Context context) {
super(context); super(context);
@@ -28,6 +33,18 @@ public class FUAuthenticator extends AbstractAccountAuthenticator {
@Override @Override
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException { 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); final Intent intent = new Intent(mContext, FUAuthenticatorActivity.class);
intent.putExtra(FUAuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType); intent.putExtra(FUAuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType);
intent.putExtra(FUAuthenticatorActivity.ARG_AUTH_TYPE, authTokenType); intent.putExtra(FUAuthenticatorActivity.ARG_AUTH_TYPE, authTokenType);

View File

@@ -55,6 +55,7 @@ public class FUAuthenticatorActivity extends AccountAuthenticatorActivity {
mAccountType = getIntent().getStringExtra(ARG_ACCOUNT_TYPE); mAccountType = getIntent().getStringExtra(ARG_ACCOUNT_TYPE);
mAuthTokenType = getIntent().getStringExtra(ARG_AUTH_TYPE); mAuthTokenType = getIntent().getStringExtra(ARG_AUTH_TYPE);
mAuthTokenType = mAuthTokenType != null ? mAuthTokenType : AccountGeneral.AUTHTOKEN_TYPE_KVV;
mIsAddingNewAccount = getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false); mIsAddingNewAccount = getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false);
setContentView(R.layout.activity_fu_authenticator); setContentView(R.layout.activity_fu_authenticator);

View File

@@ -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.FULogin;
import de.sebse.fuplanner.services.kvv.sync.KVVLogin; import de.sebse.fuplanner.services.kvv.sync.KVVLogin;
import de.sebse.fuplanner.tools.logging.Logger; import de.sebse.fuplanner.tools.logging.Logger;
import de.sebse.fuplanner.tools.network.NetworkError;
import de.sebse.fuplanner.tools.network.NetworkErrorCallback; import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
@@ -46,7 +47,7 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
@Nullable @Nullable
private FUAuthenticatorActivity mActivity; 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; mUsername = username;
mPassword = password; mPassword = password;
mTokenType = tokenType; mTokenType = tokenType;
@@ -95,6 +96,7 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
}, errorFunc); }, errorFunc);
break; break;
default: default:
errorFunc.onError(new NetworkError(104100, 400, "Invalid auth token type"));
return null; return null;
} }
try { try {