mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-19 18:35:34 +00:00
Tokens are auto managed
This commit is contained in:
parent
177609ae25
commit
874b8c245e
5 changed files with 7 additions and 142 deletions
|
@ -47,7 +47,6 @@ import android.widget.RadioGroup;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
@ -72,7 +71,6 @@ import javax.mail.Folder;
|
||||||
import static android.app.Activity.RESULT_OK;
|
import static android.app.Activity.RESULT_OK;
|
||||||
import static com.google.android.material.textfield.TextInputLayout.END_ICON_NONE;
|
import static com.google.android.material.textfield.TextInputLayout.END_ICON_NONE;
|
||||||
import static com.google.android.material.textfield.TextInputLayout.END_ICON_PASSWORD_TOGGLE;
|
import static com.google.android.material.textfield.TextInputLayout.END_ICON_PASSWORD_TOGGLE;
|
||||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_GMAIL;
|
|
||||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH;
|
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH;
|
||||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
|
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
|
||||||
|
|
||||||
|
@ -96,7 +94,6 @@ public class FragmentAccount extends FragmentBase {
|
||||||
private TextView tvCharacters;
|
private TextView tvCharacters;
|
||||||
private Button btnCertificate;
|
private Button btnCertificate;
|
||||||
private TextView tvCertificate;
|
private TextView tvCertificate;
|
||||||
private Button btnOAuth;
|
|
||||||
private EditText etRealm;
|
private EditText etRealm;
|
||||||
|
|
||||||
private EditText etName;
|
private EditText etName;
|
||||||
|
@ -201,7 +198,6 @@ public class FragmentAccount extends FragmentBase {
|
||||||
tvCharacters = view.findViewById(R.id.tvCharacters);
|
tvCharacters = view.findViewById(R.id.tvCharacters);
|
||||||
btnCertificate = view.findViewById(R.id.btnCertificate);
|
btnCertificate = view.findViewById(R.id.btnCertificate);
|
||||||
tvCertificate = view.findViewById(R.id.tvCertificate);
|
tvCertificate = view.findViewById(R.id.tvCertificate);
|
||||||
btnOAuth = view.findViewById(R.id.btnOAuth);
|
|
||||||
etRealm = view.findViewById(R.id.etRealm);
|
etRealm = view.findViewById(R.id.etRealm);
|
||||||
|
|
||||||
etName = view.findViewById(R.id.etName);
|
etName = view.findViewById(R.id.etName);
|
||||||
|
@ -289,7 +285,6 @@ public class FragmentAccount extends FragmentBase {
|
||||||
tilPassword.getEditText().setText(null);
|
tilPassword.getEditText().setText(null);
|
||||||
certificate = null;
|
certificate = null;
|
||||||
tvCertificate.setText(R.string.title_optional);
|
tvCertificate.setText(R.string.title_optional);
|
||||||
btnOAuth.setEnabled(false);
|
|
||||||
etRealm.setText(null);
|
etRealm.setText(null);
|
||||||
cbTrust.setChecked(false);
|
cbTrust.setChecked(false);
|
||||||
|
|
||||||
|
@ -363,13 +358,6 @@ public class FragmentAccount extends FragmentBase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
btnOAuth.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
onAuth();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
btnColor.setOnClickListener(new View.OnClickListener() {
|
btnColor.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
@ -1309,49 +1297,6 @@ public class FragmentAccount extends FragmentBase {
|
||||||
}.execute(this, args, "account:save");
|
}.execute(this, args, "account:save");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onAuth() {
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putLong("id", id);
|
|
||||||
|
|
||||||
new SimpleTask<String>() {
|
|
||||||
@Override
|
|
||||||
protected void onPreExecute(Bundle args) {
|
|
||||||
btnOAuth.setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Bundle args) {
|
|
||||||
btnOAuth.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String onExecute(Context context, Bundle args) throws Throwable {
|
|
||||||
long id = args.getLong("id");
|
|
||||||
|
|
||||||
DB db = DB.getInstance(context);
|
|
||||||
|
|
||||||
EntityAccount account = db.account().getAccount(id);
|
|
||||||
if (account == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
GmailState state = GmailState.jsonDeserialize(account.password);
|
|
||||||
state.refresh(context, account.user, true);
|
|
||||||
return state.jsonSerializeString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onExecuted(Bundle args, String token) {
|
|
||||||
ToastEx.makeText(getContext(), R.string.title_completed, Toast.LENGTH_LONG).show();
|
|
||||||
tilPassword.getEditText().setText(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onException(Bundle args, Throwable ex) {
|
|
||||||
Log.unexpectedError(getParentFragmentManager(), ex, false);
|
|
||||||
}
|
|
||||||
}.execute(this, args, "account:oauth");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showError(Throwable ex) {
|
private void showError(Throwable ex) {
|
||||||
tvError.setText(Log.formatThrowable(ex, false));
|
tvError.setText(Log.formatThrowable(ex, false));
|
||||||
grpError.setVisibility(View.VISIBLE);
|
grpError.setVisibility(View.VISIBLE);
|
||||||
|
@ -1550,9 +1495,6 @@ public class FragmentAccount extends FragmentBase {
|
||||||
btnCertificate.setEnabled(false);
|
btnCertificate.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (account == null || account.auth_type != AUTH_TYPE_GMAIL)
|
|
||||||
Helper.hide((btnOAuth));
|
|
||||||
|
|
||||||
cbOnDemand.setEnabled(cbSynchronize.isChecked());
|
cbOnDemand.setEnabled(cbSynchronize.isChecked());
|
||||||
cbPrimary.setEnabled(cbSynchronize.isChecked());
|
cbPrimary.setEnabled(cbSynchronize.isChecked());
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@ import android.widget.RadioGroup;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
@ -66,7 +65,6 @@ import javax.mail.internet.InternetAddress;
|
||||||
import static android.app.Activity.RESULT_OK;
|
import static android.app.Activity.RESULT_OK;
|
||||||
import static com.google.android.material.textfield.TextInputLayout.END_ICON_NONE;
|
import static com.google.android.material.textfield.TextInputLayout.END_ICON_NONE;
|
||||||
import static com.google.android.material.textfield.TextInputLayout.END_ICON_PASSWORD_TOGGLE;
|
import static com.google.android.material.textfield.TextInputLayout.END_ICON_PASSWORD_TOGGLE;
|
||||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_GMAIL;
|
|
||||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH;
|
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH;
|
||||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
|
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
|
||||||
|
|
||||||
|
@ -98,7 +96,6 @@ public class FragmentIdentity extends FragmentBase {
|
||||||
private TextView tvCharacters;
|
private TextView tvCharacters;
|
||||||
private Button btnCertificate;
|
private Button btnCertificate;
|
||||||
private TextView tvCertificate;
|
private TextView tvCertificate;
|
||||||
private Button btnOAuth;
|
|
||||||
private EditText etRealm;
|
private EditText etRealm;
|
||||||
private CheckBox cbUseIp;
|
private CheckBox cbUseIp;
|
||||||
private EditText etEhlo;
|
private EditText etEhlo;
|
||||||
|
@ -191,7 +188,6 @@ public class FragmentIdentity extends FragmentBase {
|
||||||
tvCharacters = view.findViewById(R.id.tvCharacters);
|
tvCharacters = view.findViewById(R.id.tvCharacters);
|
||||||
btnCertificate = view.findViewById(R.id.btnCertificate);
|
btnCertificate = view.findViewById(R.id.btnCertificate);
|
||||||
tvCertificate = view.findViewById(R.id.tvCertificate);
|
tvCertificate = view.findViewById(R.id.tvCertificate);
|
||||||
btnOAuth = view.findViewById(R.id.btnOAuth);
|
|
||||||
etRealm = view.findViewById(R.id.etRealm);
|
etRealm = view.findViewById(R.id.etRealm);
|
||||||
cbUseIp = view.findViewById(R.id.cbUseIp);
|
cbUseIp = view.findViewById(R.id.cbUseIp);
|
||||||
etEhlo = view.findViewById(R.id.etEhlo);
|
etEhlo = view.findViewById(R.id.etEhlo);
|
||||||
|
@ -410,13 +406,6 @@ public class FragmentIdentity extends FragmentBase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
btnOAuth.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
onAuth();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||||
|
@ -962,49 +951,6 @@ public class FragmentIdentity extends FragmentBase {
|
||||||
}.execute(this, args, "identity:save");
|
}.execute(this, args, "identity:save");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onAuth() {
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putLong("id", id);
|
|
||||||
|
|
||||||
new SimpleTask<String>() {
|
|
||||||
@Override
|
|
||||||
protected void onPreExecute(Bundle args) {
|
|
||||||
btnOAuth.setEnabled(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Bundle args) {
|
|
||||||
btnOAuth.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String onExecute(Context context, Bundle args) throws Throwable {
|
|
||||||
long id = args.getLong("id");
|
|
||||||
|
|
||||||
DB db = DB.getInstance(context);
|
|
||||||
|
|
||||||
EntityIdentity identity = db.identity().getIdentity(id);
|
|
||||||
if (identity == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
GmailState state = GmailState.jsonDeserialize(identity.password);
|
|
||||||
state.refresh(context, identity.user, true);
|
|
||||||
return state.jsonSerializeString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onExecuted(Bundle args, String token) {
|
|
||||||
ToastEx.makeText(getContext(), R.string.title_completed, Toast.LENGTH_LONG).show();
|
|
||||||
tilPassword.getEditText().setText(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onException(Bundle args, Throwable ex) {
|
|
||||||
Log.unexpectedError(getParentFragmentManager(), ex, false);
|
|
||||||
}
|
|
||||||
}.execute(this, args, "identity:oauth");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showError(Throwable ex) {
|
private void showError(Throwable ex) {
|
||||||
tvError.setText(Log.formatThrowable(ex, false));
|
tvError.setText(Log.formatThrowable(ex, false));
|
||||||
grpError.setVisibility(View.VISIBLE);
|
grpError.setVisibility(View.VISIBLE);
|
||||||
|
@ -1171,9 +1117,6 @@ public class FragmentIdentity extends FragmentBase {
|
||||||
btnCertificate.setEnabled(false);
|
btnCertificate.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (identity == null || identity.auth_type != AUTH_TYPE_GMAIL)
|
|
||||||
Helper.hide(btnOAuth);
|
|
||||||
|
|
||||||
cbPrimary.setEnabled(cbSynchronize.isChecked());
|
cbPrimary.setEnabled(cbSynchronize.isChecked());
|
||||||
|
|
||||||
// Get providers
|
// Get providers
|
||||||
|
|
|
@ -21,6 +21,8 @@ package eu.faircode.email;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
|
||||||
|
|
||||||
public class TupleAccountState extends EntityAccount {
|
public class TupleAccountState extends EntityAccount {
|
||||||
// TODO: folder property changes (name, poll)
|
// TODO: folder property changes (name, poll)
|
||||||
public int folders;
|
public int folders;
|
||||||
|
@ -35,7 +37,7 @@ public class TupleAccountState extends EntityAccount {
|
||||||
this.insecure.equals(other.insecure) &&
|
this.insecure.equals(other.insecure) &&
|
||||||
this.port.equals(other.port) &&
|
this.port.equals(other.port) &&
|
||||||
this.user.equals(other.user) &&
|
this.user.equals(other.user) &&
|
||||||
this.password.equals(other.password) &&
|
(auth_type != AUTH_TYPE_PASSWORD || this.password.equals(other.password)) &&
|
||||||
Objects.equals(this.certificate_alias, other.certificate_alias) &&
|
Objects.equals(this.certificate_alias, other.certificate_alias) &&
|
||||||
Objects.equals(this.realm, other.realm) &&
|
Objects.equals(this.realm, other.realm) &&
|
||||||
Objects.equals(this.fingerprint, other.fingerprint) &&
|
Objects.equals(this.fingerprint, other.fingerprint) &&
|
||||||
|
|
|
@ -315,17 +315,6 @@
|
||||||
app:layout_constraintStart_toEndOf="@id/btnCertificate"
|
app:layout_constraintStart_toEndOf="@id/btnCertificate"
|
||||||
app:layout_constraintTop_toTopOf="@id/btnCertificate" />
|
app:layout_constraintTop_toTopOf="@id/btnCertificate" />
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnOAuth"
|
|
||||||
style="?android:attr/buttonStyleSmall"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="12dp"
|
|
||||||
android:tag="disable"
|
|
||||||
android:text="@string/title_setup_authentication"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/btnCertificate" />
|
|
||||||
|
|
||||||
<eu.faircode.email.FixedTextView
|
<eu.faircode.email.FixedTextView
|
||||||
android:id="@+id/tvRealm"
|
android:id="@+id/tvRealm"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -334,7 +323,7 @@
|
||||||
android:text="@string/title_realm"
|
android:text="@string/title_realm"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/btnOAuth" />
|
app:layout_constraintTop_toBottomOf="@id/btnCertificate" />
|
||||||
|
|
||||||
<eu.faircode.email.EditTextPlain
|
<eu.faircode.email.EditTextPlain
|
||||||
android:id="@+id/etRealm"
|
android:id="@+id/etRealm"
|
||||||
|
@ -989,7 +978,7 @@
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
app:constraint_referenced_ids="
|
app:constraint_referenced_ids="
|
||||||
tvUser,etUser,tvPassword,tilPassword,tvCaseSensitive,btnCertificate,tvCertificate,btnOAuth,tvRealm,etRealm,
|
tvUser,etUser,tvPassword,tilPassword,tvCaseSensitive,btnCertificate,tvCertificate,tvRealm,etRealm,
|
||||||
tvName,tvNameRemark,etName,
|
tvName,tvNameRemark,etName,
|
||||||
tvColor,btnColor,tvColorHint,tvColorPro" />
|
tvColor,btnColor,tvColorHint,tvColorPro" />
|
||||||
|
|
||||||
|
|
|
@ -465,17 +465,6 @@
|
||||||
app:layout_constraintStart_toEndOf="@id/btnCertificate"
|
app:layout_constraintStart_toEndOf="@id/btnCertificate"
|
||||||
app:layout_constraintTop_toTopOf="@id/btnCertificate" />
|
app:layout_constraintTop_toTopOf="@id/btnCertificate" />
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnOAuth"
|
|
||||||
style="?android:attr/buttonStyleSmall"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="12dp"
|
|
||||||
android:tag="disable"
|
|
||||||
android:text="@string/title_setup_authentication"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/btnCertificate" />
|
|
||||||
|
|
||||||
<eu.faircode.email.FixedTextView
|
<eu.faircode.email.FixedTextView
|
||||||
android:id="@+id/tvRealm"
|
android:id="@+id/tvRealm"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -484,7 +473,7 @@
|
||||||
android:text="@string/title_realm"
|
android:text="@string/title_realm"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/btnOAuth" />
|
app:layout_constraintTop_toBottomOf="@id/btnCertificate" />
|
||||||
|
|
||||||
<eu.faircode.email.EditTextPlain
|
<eu.faircode.email.EditTextPlain
|
||||||
android:id="@+id/etRealm"
|
android:id="@+id/etRealm"
|
||||||
|
@ -850,7 +839,7 @@
|
||||||
tvProvider,spProvider,
|
tvProvider,spProvider,
|
||||||
tvDomain,tvDomainHint,etDomain,btnAutoConfig,
|
tvDomain,tvDomainHint,etDomain,btnAutoConfig,
|
||||||
tvSmtp,tvHost,etHost,tvEncryption,rgEncryption,cbInsecure,tvInsecureRemark,tvPort,etPort,
|
tvSmtp,tvHost,etHost,tvEncryption,rgEncryption,cbInsecure,tvInsecureRemark,tvPort,etPort,
|
||||||
tvUser,etUser,tvPassword,tilPassword,tvCaseSensitiveHint,btnCertificate,tvCertificate,btnOAuth,
|
tvUser,etUser,tvPassword,tilPassword,tvCaseSensitiveHint,btnCertificate,tvCertificate,
|
||||||
tvRealm,etRealm,
|
tvRealm,etRealm,
|
||||||
cbUseIp,tvUseIpHint,tvEhlo,etEhlo,
|
cbUseIp,tvUseIpHint,tvEhlo,etEhlo,
|
||||||
cbSynchronize,cbPrimary,cbSelf,
|
cbSynchronize,cbPrimary,cbSelf,
|
||||||
|
|
Loading…
Add table
Reference in a new issue