mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2024-12-16 15:48:13 +08:00
Fix email login loop (can login with email again) (#629)
Merge branch 'master' into fix-email-logins # Conflicts: # app/src/main/java/org/mian/gitnex/activities/LoginActivity.java cleanup Fix emails logins loop Co-authored-by: M M Arif <mmarif@swatian.com> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/629
This commit is contained in:
parent
b4b7981722
commit
7c40c049d4
@ -20,6 +20,7 @@ import com.tooltip.Tooltip;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.database.api.UserAccountsApi;
|
||||
import org.mian.gitnex.database.models.UserAccount;
|
||||
import org.mian.gitnex.helpers.AppUtil;
|
||||
import org.mian.gitnex.helpers.NetworkObserver;
|
||||
import org.mian.gitnex.helpers.PathsHelper;
|
||||
@ -210,14 +211,6 @@ public class LoginActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
if(loginUid.contains("@")) {
|
||||
|
||||
Toasty.warning(ctx, getResources().getString(R.string.userInvalidUserName));
|
||||
enableProcessButton();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(loginPass.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.emptyFieldPassword));
|
||||
@ -383,12 +376,18 @@ public class LoginActivity extends BaseActivity {
|
||||
String accountName = userDetails.getUsername() + "@" + instanceUrl;
|
||||
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
|
||||
int checkAccount = userAccountsApi.getCount(accountName);
|
||||
long accountId;
|
||||
|
||||
if(checkAccount == 0) {
|
||||
userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), loginToken, "");
|
||||
|
||||
accountId = userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), loginToken, "");
|
||||
tinyDB.putInt("currentActiveAccountId", (int) accountId);
|
||||
}
|
||||
else {
|
||||
|
||||
userAccountsApi.updateTokenByAccountName(accountName, loginToken);
|
||||
UserAccount data = userAccountsApi.getAccountData(accountName);
|
||||
tinyDB.putInt("currentActiveAccountId", data.getAccountId());
|
||||
}
|
||||
|
||||
enableProcessButton();
|
||||
@ -567,13 +566,18 @@ public class LoginActivity extends BaseActivity {
|
||||
String accountName = userDetails.getUsername() + "@" + instanceUrl;
|
||||
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
|
||||
int checkAccount = userAccountsApi.getCount(accountName);
|
||||
long accountId;
|
||||
|
||||
if(checkAccount == 0) {
|
||||
userAccountsApi
|
||||
.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), newToken.getSha1(), "");
|
||||
|
||||
accountId = userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), newToken.getSha1(), "");
|
||||
tinyDB.putInt("currentActiveAccountId", (int) accountId);
|
||||
}
|
||||
else {
|
||||
|
||||
userAccountsApi.updateTokenByAccountName(accountName, newToken.getSha1());
|
||||
UserAccount data = userAccountsApi.getAccountData(accountName);
|
||||
tinyDB.putInt("currentActiveAccountId", data.getAccountId());
|
||||
}
|
||||
|
||||
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
||||
|
@ -27,8 +27,6 @@ import com.google.android.material.navigation.NavigationView;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.clients.PicassoService;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.database.api.UserAccountsApi;
|
||||
import org.mian.gitnex.database.models.UserAccount;
|
||||
import org.mian.gitnex.fragments.AboutFragment;
|
||||
import org.mian.gitnex.fragments.AdministrationFragment;
|
||||
import org.mian.gitnex.fragments.BottomSheetDraftsFragment;
|
||||
@ -123,8 +121,9 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
return;
|
||||
}
|
||||
|
||||
String accountName = loginUid + "@" + instanceUrl;
|
||||
getAccountData(accountName);
|
||||
if(tinyDb.getInt("currentActiveAccountId") <= 0) {
|
||||
AlertDialogs.forceLogoutDialog(ctx, getResources().getString(R.string.forceLogoutDialogHeader), getResources().getString(R.string.forceLogoutDialogDescription), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
}
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
toolbarTitle = toolbar.findViewById(R.id.toolbar_title);
|
||||
@ -448,20 +447,6 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
|
||||
}
|
||||
|
||||
public void getAccountData(String accountName) {
|
||||
|
||||
UserAccountsApi accountData = new UserAccountsApi(ctx);
|
||||
UserAccount data = accountData.getAccountData(accountName);
|
||||
|
||||
if(data != null) {
|
||||
TinyDB tinyDb = new TinyDB(ctx.getApplicationContext());
|
||||
tinyDb.putInt("currentActiveAccountId", data.getAccountId());
|
||||
}
|
||||
else {
|
||||
AlertDialogs.forceLogoutDialog(ctx, getResources().getString(R.string.forceLogoutDialogHeader), getResources().getString(R.string.forceLogoutDialogDescription), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
|
||||
|
@ -3,7 +3,6 @@ package org.mian.gitnex.adapters;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -76,8 +75,6 @@ public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapte
|
||||
UserAccountsApi userAccountsApi = new UserAccountsApi(mCtx);
|
||||
UserAccount userAccount = userAccountsApi.getAccountData(accountNameSwitch);
|
||||
|
||||
Log.e("userAccount", userAccount.getInstanceUrl());
|
||||
|
||||
if(tinyDB.getInt("currentActiveAccountId") != userAccount.getAccountId()) {
|
||||
|
||||
String url = UrlBuilder.fromString(userAccount.getInstanceUrl())
|
||||
|
@ -18,6 +18,7 @@ public class UserAccountsApi {
|
||||
private static UserAccountsDao userAccountsDao;
|
||||
private static UserAccount userAccount;
|
||||
private static Integer checkAccount;
|
||||
private static long accountId;
|
||||
|
||||
public UserAccountsApi(Context context) {
|
||||
|
||||
@ -26,7 +27,7 @@ public class UserAccountsApi {
|
||||
userAccountsDao = db.userAccountsDao();
|
||||
}
|
||||
|
||||
public void insertNewAccount(String accountName, String instanceUrl, String userName, String token, String serverVersion) {
|
||||
public long insertNewAccount(String accountName, String instanceUrl, String userName, String token, String serverVersion) {
|
||||
|
||||
UserAccount userAccount = new UserAccount();
|
||||
userAccount.setAccountName(accountName);
|
||||
@ -35,12 +36,23 @@ public class UserAccountsApi {
|
||||
userAccount.setToken(token);
|
||||
userAccount.setServerVersion(serverVersion);
|
||||
|
||||
insertNewAccountAsync(userAccount);
|
||||
return insertNewAccountAsync(userAccount);
|
||||
}
|
||||
|
||||
private static void insertNewAccountAsync(final UserAccount userAccount) {
|
||||
private static long insertNewAccountAsync(final UserAccount userAccount) {
|
||||
|
||||
new Thread(() -> userAccountsDao.newAccount(userAccount)).start();
|
||||
try {
|
||||
|
||||
Thread thread = new Thread(() -> accountId = userAccountsDao.newAccount(userAccount));
|
||||
thread.start();
|
||||
thread.join();
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
|
||||
Log.e(StaticGlobalVariables.userAccountsRepository, e.toString());
|
||||
}
|
||||
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public static void updateServerVersion(final String serverVersion, final int accountId) {
|
||||
|
@ -15,7 +15,7 @@ import java.util.List;
|
||||
public interface UserAccountsDao {
|
||||
|
||||
@Insert
|
||||
void newAccount(UserAccount userAccounts);
|
||||
long newAccount(UserAccount userAccounts);
|
||||
|
||||
@Query("SELECT * FROM UserAccounts ORDER BY accountId ASC")
|
||||
LiveData<List<UserAccount>> fetchAllAccounts();
|
||||
|
Loading…
Reference in New Issue
Block a user