mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-11 20:15:03 -05:00
Added dialog to reenter credentials when wrong at the settings check step in the wizard. This prevents users from having to rerun the whole wizard as it is now.
This commit is contained in:
parent
e3b607e49e
commit
2152512529
75
res/layout/alert_dialog_text_entry.xml
Normal file
75
res/layout/alert_dialog_text_entry.xml
Normal file
@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/error_msg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/form_label_email"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="@string/account_setup_incoming_username_label" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/error_dialog_username_field"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textEmailAddress"
|
||||
android:singleLine="true" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/form_label_password"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="@string/account_setup_basics_password_hint" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/error_dialog_password_field"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPassword"
|
||||
android:nextFocusDown="@+id/next"
|
||||
android:password="true"
|
||||
android:singleLine="true" />
|
||||
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/error_dialog_quit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:drawableLeft="@drawable/button_indicator_prev"
|
||||
android:text="@string/previous_action"
|
||||
android:layout_marginRight="20dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/error_dialog_ok"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:drawableRight="@drawable/button_indicator_next"
|
||||
android:text="@string/next_action" />
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
@ -530,11 +530,14 @@ http://k9mail.googlecode.com/
|
||||
<string name="move_copy_cannot_copy_unsynced_message">Cannot copy or move a message that is not synchronized with the server</string>
|
||||
|
||||
<string name="account_setup_failed_dlg_title">Setup could not finish</string>
|
||||
<string name="account_setup_failed_dlg_auth_message_fmt_static">Username or password incorrect.\nPlease try reentering your credentials.</string>
|
||||
<string name="account_setup_failed_dlg_auth_message_fmt">Username or password incorrect.\n(<xliff:g id="error">%s</xliff:g>)</string> <!-- Username or password incorrect\n(ERR01 Account does not exist) -->
|
||||
<string name="account_setup_failed_dlg_certificate_message_fmt">Cannot safely connect to server.\n(<xliff:g id="error">%s</xliff:g>)</string> <!-- Cannot safely connect to server\n(Invalid certificate) -->
|
||||
<string name="account_setup_failed_dlg_server_message_fmt">Cannot connect to server.\n(<xliff:g id="error">%s</xliff:g>)</string> <!-- Cannot connect to server\n(Connection timed out) -->
|
||||
<string name="account_setup_failed_dlg_edit_details_action">Edit details</string>
|
||||
<string name="account_setup_failed_dlg_continue_action">Continue</string>
|
||||
<string name="wrong_credentials_incoming">Wrong username or password for the incoming server.</string>
|
||||
<string name="wrong_credentials_outgoing">Wrong username or password for the outgoing server.</string>
|
||||
|
||||
<string name="account_settings_push_advanced_title">Advanced</string>
|
||||
<string name="account_settings_title_fmt">Account settings</string>
|
||||
|
@ -3,6 +3,7 @@ package com.fsck.k9.activity.setup;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
@ -10,9 +11,12 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Process;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import com.fsck.k9.*;
|
||||
@ -26,6 +30,10 @@ import com.fsck.k9.mail.store.TrustManagerFactory;
|
||||
import com.fsck.k9.mail.store.WebDavStore;
|
||||
import com.fsck.k9.mail.filter.Hex;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateEncodingException;
|
||||
import java.security.cert.X509Certificate;
|
||||
@ -51,6 +59,10 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
|
||||
|
||||
private static final String EXTRA_CHECK_OUTGOING = "checkOutgoing";
|
||||
|
||||
protected static final int REENTER_CREDENTIALS_DIALOG = 1;
|
||||
|
||||
private static final String EXCEPTION_MSG = "AUTH_EXCEPTION";
|
||||
|
||||
private Handler mHandler = new Handler();
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
@ -67,6 +79,11 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
|
||||
|
||||
private boolean mDestroyed;
|
||||
|
||||
private Intent mStartIntent;
|
||||
|
||||
private boolean mIsIncoming = true;
|
||||
private boolean mRetry = true;
|
||||
|
||||
public static void actionCheckSettings(Activity context, Account account,
|
||||
boolean checkIncoming, boolean checkOutgoing) {
|
||||
Intent i = new Intent(context, AccountSetupCheckSettings.class);
|
||||
@ -87,6 +104,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
|
||||
setMessage(R.string.account_setup_check_settings_retr_info_msg);
|
||||
mProgressBar.setIndeterminate(true);
|
||||
|
||||
mStartIntent = getIntent();
|
||||
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
|
||||
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
|
||||
mCheckIncoming = getIntent().getBooleanExtra(EXTRA_CHECK_INCOMING, false);
|
||||
@ -97,79 +115,82 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
|
||||
public void run() {
|
||||
Store store = null;
|
||||
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||
try {
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
if (mCanceled) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
if (mCheckIncoming) {
|
||||
store = mAccount.getRemoteStore();
|
||||
while(mRetry)
|
||||
{
|
||||
try {
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
if (mCanceled) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
if (mCheckIncoming) {
|
||||
mIsIncoming = true;
|
||||
store = mAccount.getRemoteStore();
|
||||
|
||||
if (store instanceof WebDavStore) {
|
||||
setMessage(R.string.account_setup_check_settings_authenticate);
|
||||
} else {
|
||||
setMessage(R.string.account_setup_check_settings_check_incoming_msg);
|
||||
}
|
||||
store.checkSettings();
|
||||
if (store instanceof WebDavStore) {
|
||||
setMessage(R.string.account_setup_check_settings_authenticate);
|
||||
} else {
|
||||
setMessage(R.string.account_setup_check_settings_check_incoming_msg);
|
||||
}
|
||||
store.checkSettings();
|
||||
|
||||
if (store instanceof WebDavStore) {
|
||||
setMessage(R.string.account_setup_check_settings_fetch);
|
||||
}
|
||||
MessagingController.getInstance(getApplication()).listFoldersSynchronous(mAccount, true, null);
|
||||
MessagingController.getInstance(getApplication()).synchronizeMailbox(mAccount, mAccount.getInboxFolderName(), null, null);
|
||||
}
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
if (mCanceled) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
if (mCheckOutgoing) {
|
||||
if (!(mAccount.getRemoteStore() instanceof WebDavStore)) {
|
||||
setMessage(R.string.account_setup_check_settings_check_outgoing_msg);
|
||||
}
|
||||
Transport transport = Transport.getInstance(mAccount);
|
||||
transport.close();
|
||||
transport.open();
|
||||
transport.close();
|
||||
}
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
if (mCanceled) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
} catch (final AuthenticationFailedException afe) {
|
||||
Log.e(K9.LOG_TAG, "Error while testing settings", afe);
|
||||
showErrorDialog(
|
||||
R.string.account_setup_failed_dlg_auth_message_fmt,
|
||||
afe.getMessage() == null ? "" : afe.getMessage());
|
||||
} catch (final CertificateValidationException cve) {
|
||||
Log.e(K9.LOG_TAG, "Error while testing settings", cve);
|
||||
if (store instanceof WebDavStore) {
|
||||
setMessage(R.string.account_setup_check_settings_fetch);
|
||||
}
|
||||
MessagingController.getInstance(getApplication()).listFoldersSynchronous(mAccount, true, null);
|
||||
MessagingController.getInstance(getApplication()).synchronizeMailbox(mAccount, K9.INBOX , null, null);
|
||||
}
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
if (mCanceled) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
if (mCheckOutgoing) {
|
||||
mIsIncoming = false;
|
||||
if (!(mAccount.getRemoteStore() instanceof WebDavStore)) {
|
||||
setMessage(R.string.account_setup_check_settings_check_outgoing_msg);
|
||||
}
|
||||
Transport transport = Transport.getInstance(mAccount);
|
||||
transport.close();
|
||||
transport.open();
|
||||
transport.close();
|
||||
}
|
||||
if (mDestroyed) {
|
||||
return;
|
||||
}
|
||||
if (mCanceled) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
setResult(RESULT_OK);
|
||||
finish();
|
||||
} catch (final AuthenticationFailedException afe) {
|
||||
Log.e(K9.LOG_TAG, "Error while testing settings", afe);
|
||||
|
||||
// Avoid NullPointerException in acceptKeyDialog()
|
||||
if (TrustManagerFactory.getLastCertChain() != null) {
|
||||
acceptKeyDialog(
|
||||
R.string.account_setup_failed_dlg_certificate_message_fmt,
|
||||
cve);
|
||||
} else {
|
||||
showErrorDialog(
|
||||
R.string.account_setup_failed_dlg_server_message_fmt,
|
||||
(cve.getMessage() == null ? "" : cve.getMessage()));
|
||||
}
|
||||
} catch (final Throwable t) {
|
||||
Log.e(K9.LOG_TAG, "Error while testing settings", t);
|
||||
showErrorDialog(
|
||||
R.string.account_setup_failed_dlg_server_message_fmt,
|
||||
(t.getMessage() == null ? "" : t.getMessage()));
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Bundle tmpBundle = new Bundle();
|
||||
tmpBundle.putString(EXCEPTION_MSG, mIsIncoming ? getString(R.string.wrong_credentials_incoming) : getString(R.string.wrong_credentials_outgoing));
|
||||
showDialog(REENTER_CREDENTIALS_DIALOG, tmpBundle);
|
||||
}
|
||||
});
|
||||
} catch (final CertificateValidationException cve) {
|
||||
Log.e(K9.LOG_TAG, "Error while testing settings", cve);
|
||||
acceptKeyDialog(
|
||||
R.string.account_setup_failed_dlg_certificate_message_fmt,
|
||||
cve);
|
||||
} catch (final Throwable t) {
|
||||
Log.e(K9.LOG_TAG, "Error while testing settings", t);
|
||||
showErrorDialog(
|
||||
R.string.account_setup_failed_dlg_server_message_fmt,
|
||||
(t.getMessage() == null ? "" : t.getMessage()));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,7 +216,85 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
|
||||
});
|
||||
}
|
||||
|
||||
private void showErrorDialog(final int msgResId, final Object... args) {
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
Dialog dialog = new Dialog(this);
|
||||
|
||||
if (id == REENTER_CREDENTIALS_DIALOG) {
|
||||
dialog.setContentView(R.layout.alert_dialog_text_entry);
|
||||
dialog.setTitle(getString(R.string.account_setup_failed_dlg_title));
|
||||
|
||||
final EditText mAlertUsernameField = ((EditText) dialog
|
||||
.findViewById(R.id.error_dialog_username_field));
|
||||
final EditText mAlertPasswordField = ((EditText) dialog
|
||||
.findViewById(R.id.error_dialog_password_field));
|
||||
|
||||
|
||||
// Try new credentials
|
||||
((Button) dialog.findViewById(R.id.error_dialog_ok))
|
||||
.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
changeCredentials(mAlertUsernameField.getText().toString(),
|
||||
mAlertPasswordField.getText().toString());
|
||||
dismissDialog(REENTER_CREDENTIALS_DIALOG);
|
||||
}
|
||||
});
|
||||
|
||||
// Exit
|
||||
((Button) dialog.findViewById(R.id.error_dialog_quit))
|
||||
.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
dialog = null;
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialog(int id, Dialog dialog, final Bundle args){
|
||||
if (id == REENTER_CREDENTIALS_DIALOG) {
|
||||
TextView mErrorMsg = ((TextView) dialog.findViewById(R.id.error_msg));
|
||||
mErrorMsg.setText(args.getString(EXCEPTION_MSG));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// changes the credentials with the new ones
|
||||
protected void changeCredentials(String user, String pasw) {
|
||||
try {
|
||||
String userInfo = URLEncoder.encode(user, "UTF-8") + ":" + URLEncoder.encode(pasw, "UTF-8");
|
||||
|
||||
// incoming
|
||||
URI tmpStoreURI = new URI(mAccount.getStoreUri());
|
||||
URI storeUri = new URI(
|
||||
tmpStoreURI.getScheme(),
|
||||
userInfo,
|
||||
tmpStoreURI.getHost(),
|
||||
tmpStoreURI.getPort(),
|
||||
null,null,null);
|
||||
mAccount.setStoreUri(storeUri.toString());
|
||||
|
||||
// outgoing
|
||||
URI tmpTransportURI = new URI(mAccount.getTransportUri());
|
||||
URI transportUri = new URI(
|
||||
tmpTransportURI.getScheme(),
|
||||
(tmpTransportURI.getUserInfo() == null || tmpTransportURI.getUserInfo().isEmpty()) ? null : userInfo,
|
||||
tmpTransportURI.getHost(),
|
||||
tmpTransportURI.getPort(),
|
||||
null,null,null);
|
||||
mAccount.setTransportUri(transportUri.toString());
|
||||
|
||||
} catch (URISyntaxException e) {}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void showErrorDialog(final int msgResId, final Object... args) {
|
||||
mHandler.post(new Runnable() {
|
||||
public void run() {
|
||||
if (mDestroyed) {
|
||||
|
Loading…
Reference in New Issue
Block a user