mirror of https://github.com/M66B/FairEmail.git
Simplify/improve updating passwords
This commit is contained in:
parent
1e9a77e249
commit
2f771c6fa5
|
@ -346,13 +346,7 @@ public class ConnectionHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
static boolean isSameDomain(String host1, String host2) {
|
||||
String domain1 = getDomain(host1);
|
||||
String domain2 = getDomain(host2);
|
||||
return Objects.equals(domain1, domain2);
|
||||
}
|
||||
|
||||
private static String getDomain(String host) {
|
||||
static String getDomain(String host) {
|
||||
if (host != null) {
|
||||
String[] h = host.split("\\.");
|
||||
if (h.length >= 2)
|
||||
|
|
|
@ -82,6 +82,12 @@ public interface DaoIdentity {
|
|||
@Query("UPDATE identity SET password = :password WHERE id = :id")
|
||||
int setIdentityPassword(long id, String password);
|
||||
|
||||
@Query("UPDATE identity SET password = :password" +
|
||||
" WHERE account = :account" +
|
||||
" AND user = :user" +
|
||||
" AND host LIKE :domain")
|
||||
int setIdentityPassword(long account, String user, String password, String domain);
|
||||
|
||||
@Query("UPDATE identity SET last_connected = :last_connected WHERE id = :id")
|
||||
int setIdentityConnected(long id, long last_connected);
|
||||
|
||||
|
|
|
@ -918,14 +918,11 @@ public class FragmentAccount extends FragmentBase {
|
|||
db.beginTransaction();
|
||||
|
||||
if (account != null && !account.password.equals(password)) {
|
||||
List<EntityIdentity> identities = db.identity().getIdentities(account.id);
|
||||
for (EntityIdentity identity : identities)
|
||||
if (identity.password.equals(account.password) &&
|
||||
ConnectionHelper.isSameDomain(identity.host, account.host)) {
|
||||
Log.i("Changing identity password host=" + identity.host);
|
||||
identity.password = password;
|
||||
db.identity().updateIdentity(identity);
|
||||
}
|
||||
int count = db.identity().setIdentityPassword(
|
||||
account.id,
|
||||
account.user, password,
|
||||
"%." + ConnectionHelper.getDomain(account.host));
|
||||
Log.i("Updated passwords=" + count);
|
||||
}
|
||||
|
||||
boolean update = (account != null);
|
||||
|
|
|
@ -707,6 +707,14 @@ public class FragmentIdentity extends FragmentBase {
|
|||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
if (identity != null && !identity.password.equals(password)) {
|
||||
int count = db.identity().setIdentityPassword(
|
||||
identity.account,
|
||||
identity.user, password,
|
||||
identity.host);
|
||||
Log.i("Updated passwords=" + count);
|
||||
}
|
||||
|
||||
boolean update = (identity != null);
|
||||
if (identity == null)
|
||||
identity = new EntityIdentity();
|
||||
|
|
|
@ -49,7 +49,6 @@ import com.google.android.material.snackbar.Snackbar;
|
|||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static com.google.android.material.textfield.TextInputLayout.END_ICON_NONE;
|
||||
|
@ -281,14 +280,11 @@ public class FragmentPop extends FragmentBase {
|
|||
db.beginTransaction();
|
||||
|
||||
if (account != null && !account.password.equals(password)) {
|
||||
List<EntityIdentity> identities = db.identity().getIdentities(account.id);
|
||||
for (EntityIdentity identity : identities)
|
||||
if (identity.password.equals(account.password) &&
|
||||
ConnectionHelper.isSameDomain(identity.host, account.host)) {
|
||||
Log.i("Changing identity password host=" + identity.host);
|
||||
identity.password = password;
|
||||
db.identity().updateIdentity(identity);
|
||||
}
|
||||
int count = db.identity().setIdentityPassword(
|
||||
account.id,
|
||||
account.user, password,
|
||||
"%." + ConnectionHelper.getDomain(account.host));
|
||||
Log.i("Updated passwords=" + count);
|
||||
}
|
||||
|
||||
boolean update = (account != null);
|
||||
|
|
Loading…
Reference in New Issue