Login Error Handeling

This commit is contained in:
Caesar2011
2019-01-31 20:57:54 +01:00
parent c544adbd4b
commit ce322bd3ca
5 changed files with 29 additions and 15 deletions

View File

@@ -15,7 +15,9 @@ import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.google.android.material.textfield.TextInputEditText;
import de.sebse.fuplanner.R;
@@ -25,20 +27,15 @@ import static de.sebse.fuplanner.services.fulogin.UserLoginTask.PARAM_USER_PASS;
* A login screen that offers login via email/password.
*/
public class FUAuthenticatorActivity extends AccountAuthenticatorActivity {
/**
* Id to identity READ_CONTACTS permission request.
*/
private static final int REQUEST_READ_CONTACTS = 0;
/**
* Keep track of the login task to ensure we can cancel it if requested.
*/
UserLoginTask mAuthTask = null;
// UI references.
private EditText mEmailView;
EditText mPasswordView;
private TextInputEditText mEmailView;
TextInputEditText mPasswordView;
TextView mErrorView;
private View mProgressView;
private View mLoginFormView;
@@ -61,6 +58,7 @@ public class FUAuthenticatorActivity extends AccountAuthenticatorActivity {
mIsAddingNewAccount = getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false);
setContentView(R.layout.activity_fu_authenticator);
mErrorView = findViewById(R.id.error_textview);
// Set up the login form.
mEmailView = findViewById(R.id.input_username);

View File

@@ -62,8 +62,8 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<String> login = new AtomicReference<>();
NetworkErrorCallback errorFunc = error -> {
login.set("Error: "+String.valueOf(error.getCode()));
log.e(error);
login.set("Error: "+String.valueOf(error.getCode()));
latch.countDown();
};
switch (mTokenType) {
@@ -113,16 +113,20 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
mActivity.mAuthTask = null;
mActivity.showProgress(false);
if (success != null) {
if (success != null && !success.startsWith("Error: ")) {
final Intent res = new Intent();
res.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername);
res.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountGeneral.ACCOUNT_TYPE);
res.putExtra(AccountManager.KEY_AUTHTOKEN, success);
res.putExtra(PARAM_USER_PASS, mPassword);
mActivity.finishLogin(res);
} else {
} else if (success != null && (success.contains("100143") || success.contains("100243"))) {
mActivity.mPasswordView.setError(mActivity.getString(R.string.error_incorrect_password));
mActivity.mPasswordView.requestFocus();
} else if (success != null) {
mActivity.mErrorView.setText(mActivity.getString(R.string.network_error_parameter, success.substring(7)));
} else {
mActivity.mErrorView.setText(R.string.network_error);
}
}

View File

@@ -41,16 +41,24 @@
android:layout_gravity="center_horizontal"
android:contentDescription="@string/cd_ic_launcher"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/error_textview"
android:textAppearance="@style/TextAppearance.Design.Error"
android:textColor="@color/colorFURed"
tools:text="@string/hello_blank_fragment" />
<!-- Email Label -->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<EditText android:id="@+id/input_username"
<com.google.android.material.textfield.TextInputEditText android:id="@+id/input_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:inputType="textNoSuggestions"
android:hint="@string/username"
android:autofillHints="username"
tools:targetApi="o" />
@@ -62,7 +70,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<EditText android:id="@+id/input_password"
<com.google.android.material.textfield.TextInputEditText android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"

View File

@@ -112,4 +112,6 @@
<string name="event_removed">Event entfernt: %1$s</string>
<string name="gradebook_removed">Noteneintrag entfernt: %1$s</string>
<string name="resource_removed">Ressource entfernt: %1$s</string>
<string name="network_error">Ein Netzwerkfehler ist aufgetreten!</string>
<string name="network_error_parameter">Ein Netzwerkfehler ist aufgetreten: %s!</string>
</resources>

View File

@@ -120,4 +120,6 @@
<string name="resource_updated">Resource updated: %1$s</string>
<string name="resource_added">New resource: %1$s</string>
<string name="resource_removed">Resource removed: %1$s</string>
<string name="network_error">A network error occured!</string>
<string name="network_error_parameter">A network error occured: %s!</string>
</resources>