mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-19 02:15:28 +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.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
@ -72,7 +71,6 @@ import javax.mail.Folder;
|
|||
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_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_PASSWORD;
|
||||
|
||||
|
@ -96,7 +94,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
private TextView tvCharacters;
|
||||
private Button btnCertificate;
|
||||
private TextView tvCertificate;
|
||||
private Button btnOAuth;
|
||||
private EditText etRealm;
|
||||
|
||||
private EditText etName;
|
||||
|
@ -201,7 +198,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
tvCharacters = view.findViewById(R.id.tvCharacters);
|
||||
btnCertificate = view.findViewById(R.id.btnCertificate);
|
||||
tvCertificate = view.findViewById(R.id.tvCertificate);
|
||||
btnOAuth = view.findViewById(R.id.btnOAuth);
|
||||
etRealm = view.findViewById(R.id.etRealm);
|
||||
|
||||
etName = view.findViewById(R.id.etName);
|
||||
|
@ -289,7 +285,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
tilPassword.getEditText().setText(null);
|
||||
certificate = null;
|
||||
tvCertificate.setText(R.string.title_optional);
|
||||
btnOAuth.setEnabled(false);
|
||||
etRealm.setText(null);
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -1309,49 +1297,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
}.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) {
|
||||
tvError.setText(Log.formatThrowable(ex, false));
|
||||
grpError.setVisibility(View.VISIBLE);
|
||||
|
@ -1550,9 +1495,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
btnCertificate.setEnabled(false);
|
||||
}
|
||||
|
||||
if (account == null || account.auth_type != AUTH_TYPE_GMAIL)
|
||||
Helper.hide((btnOAuth));
|
||||
|
||||
cbOnDemand.setEnabled(cbSynchronize.isChecked());
|
||||
cbPrimary.setEnabled(cbSynchronize.isChecked());
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ import android.widget.RadioGroup;
|
|||
import android.widget.ScrollView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
@ -66,7 +65,6 @@ import javax.mail.internet.InternetAddress;
|
|||
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_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_PASSWORD;
|
||||
|
||||
|
@ -98,7 +96,6 @@ public class FragmentIdentity extends FragmentBase {
|
|||
private TextView tvCharacters;
|
||||
private Button btnCertificate;
|
||||
private TextView tvCertificate;
|
||||
private Button btnOAuth;
|
||||
private EditText etRealm;
|
||||
private CheckBox cbUseIp;
|
||||
private EditText etEhlo;
|
||||
|
@ -191,7 +188,6 @@ public class FragmentIdentity extends FragmentBase {
|
|||
tvCharacters = view.findViewById(R.id.tvCharacters);
|
||||
btnCertificate = view.findViewById(R.id.btnCertificate);
|
||||
tvCertificate = view.findViewById(R.id.tvCertificate);
|
||||
btnOAuth = view.findViewById(R.id.btnOAuth);
|
||||
etRealm = view.findViewById(R.id.etRealm);
|
||||
cbUseIp = view.findViewById(R.id.cbUseIp);
|
||||
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() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
|
@ -962,49 +951,6 @@ public class FragmentIdentity extends FragmentBase {
|
|||
}.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) {
|
||||
tvError.setText(Log.formatThrowable(ex, false));
|
||||
grpError.setVisibility(View.VISIBLE);
|
||||
|
@ -1171,9 +1117,6 @@ public class FragmentIdentity extends FragmentBase {
|
|||
btnCertificate.setEnabled(false);
|
||||
}
|
||||
|
||||
if (identity == null || identity.auth_type != AUTH_TYPE_GMAIL)
|
||||
Helper.hide(btnOAuth);
|
||||
|
||||
cbPrimary.setEnabled(cbSynchronize.isChecked());
|
||||
|
||||
// Get providers
|
||||
|
|
|
@ -21,6 +21,8 @@ package eu.faircode.email;
|
|||
|
||||
import java.util.Objects;
|
||||
|
||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
|
||||
|
||||
public class TupleAccountState extends EntityAccount {
|
||||
// TODO: folder property changes (name, poll)
|
||||
public int folders;
|
||||
|
@ -35,7 +37,7 @@ public class TupleAccountState extends EntityAccount {
|
|||
this.insecure.equals(other.insecure) &&
|
||||
this.port.equals(other.port) &&
|
||||
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.realm, other.realm) &&
|
||||
Objects.equals(this.fingerprint, other.fingerprint) &&
|
||||
|
|
|
@ -315,17 +315,6 @@
|
|||
app:layout_constraintStart_toEndOf="@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
|
||||
android:id="@+id/tvRealm"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -334,7 +323,7 @@
|
|||
android:text="@string/title_realm"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnOAuth" />
|
||||
app:layout_constraintTop_toBottomOf="@id/btnCertificate" />
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etRealm"
|
||||
|
@ -989,7 +978,7 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
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,
|
||||
tvColor,btnColor,tvColorHint,tvColorPro" />
|
||||
|
||||
|
|
|
@ -465,17 +465,6 @@
|
|||
app:layout_constraintStart_toEndOf="@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
|
||||
android:id="@+id/tvRealm"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -484,7 +473,7 @@
|
|||
android:text="@string/title_realm"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnOAuth" />
|
||||
app:layout_constraintTop_toBottomOf="@id/btnCertificate" />
|
||||
|
||||
<eu.faircode.email.EditTextPlain
|
||||
android:id="@+id/etRealm"
|
||||
|
@ -850,7 +839,7 @@
|
|||
tvProvider,spProvider,
|
||||
tvDomain,tvDomainHint,etDomain,btnAutoConfig,
|
||||
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,
|
||||
cbUseIp,tvUseIpHint,tvEhlo,etEhlo,
|
||||
cbSynchronize,cbPrimary,cbSelf,
|
||||
|
|
Loading…
Add table
Reference in a new issue