Fix account switching

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2017-11-28 20:45:45 +01:00
parent af48bc9a50
commit a621401520
7 changed files with 39 additions and 16 deletions

View File

@ -130,8 +130,8 @@ public class ApiHelper {
return baseUrl + ocsApiVersion + spreedApiVersion + "/signaling"; return baseUrl + ocsApiVersion + spreedApiVersion + "/signaling";
} }
public static String getUrlForUserProfile(String baseUrl, String username) { public static String getUrlForUserProfile(String baseUrl) {
return baseUrl + ocsApiVersion + "/cloud/users/" + username; return baseUrl + ocsApiVersion + "/cloud/user";
} }
public static String getUrlPostfixForStatus() { public static String getUrlPostfixForStatus() {

View File

@ -114,7 +114,7 @@ public class AccountVerificationController extends BaseController {
R.string.nc_nextcloud_talk_app_installed), getResources().getString(R.string.nc_app_name))); R.string.nc_nextcloud_talk_app_installed), getResources().getString(R.string.nc_app_name)));
profileQueryDisposable = ncApi.getUserProfile(credentials, profileQueryDisposable = ncApi.getUserProfile(credentials,
ApiHelper.getUrlForUserProfile(baseUrl, username)) ApiHelper.getUrlForUserProfile(baseUrl))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(userProfileOverall -> { .subscribe(userProfileOverall -> {

View File

@ -36,6 +36,7 @@ import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -236,6 +237,7 @@ public class CallsListController extends BaseController implements SearchView.On
callItems = new ArrayList<>(); callItems = new ArrayList<>();
Log.d("MARIO", userEntity.getUsername());
roomsQueryDisposable = ncApi.getRooms(ApiHelper.getCredentials(userEntity.getUsername(), roomsQueryDisposable = ncApi.getRooms(ApiHelper.getCredentials(userEntity.getUsername(),
userEntity.getToken()), ApiHelper.getUrlForGetRooms(userEntity.getBaseUrl())) userEntity.getToken()), ApiHelper.getUrlForGetRooms(userEntity.getBaseUrl()))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())

View File

@ -33,7 +33,6 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import com.bluelinelabs.conductor.RouterTransaction; import com.bluelinelabs.conductor.RouterTransaction;
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler; import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler;
import com.bumptech.glide.load.model.GlideUrl; import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaders; import com.bumptech.glide.load.model.LazyHeaders;
@ -62,6 +61,7 @@ import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import java.net.CookieManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -140,6 +140,9 @@ public class SettingsController extends BaseController {
@Inject @Inject
UserUtils userUtils; UserUtils userUtils;
@Inject
CookieManager cookieManager;
private UserEntity userEntity; private UserEntity userEntity;
private OnPreferenceValueChangedListener<String> proxyTypeChangeListener; private OnPreferenceValueChangedListener<String> proxyTypeChangeListener;
@ -282,7 +285,7 @@ public class SettingsController extends BaseController {
profileQueryDisposable = ncApi.getUserProfile(ApiHelper.getCredentials(userEntity.getUsername(), profileQueryDisposable = ncApi.getUserProfile(ApiHelper.getCredentials(userEntity.getUsername(),
userEntity.getToken()), userEntity.getToken()),
ApiHelper.getUrlForUserProfile(userEntity.getBaseUrl(), userEntity.getUsername())) ApiHelper.getUrlForUserProfile(userEntity.getBaseUrl()))
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(userProfileOverall -> { .subscribe(userProfileOverall -> {
@ -318,15 +321,16 @@ public class SettingsController extends BaseController {
}, () -> dispose(profileQueryDisposable)); }, () -> dispose(profileQueryDisposable));
removeAccountButton.setOnClickListener(view1 -> { removeAccountButton.setOnClickListener(view1 -> {
cookieManager.getCookieStore().removeAll();
boolean otherUserExists = userUtils.scheduleUserForDeletionWithId(userEntity.getId()); boolean otherUserExists = userUtils.scheduleUserForDeletionWithId(userEntity.getId());
if (otherUserExists && getView() != null) { if (otherUserExists && getView() != null) {
onAttach(getView());
onViewBound(getView()); onViewBound(getView());
onAttach(getView());
} else if (!otherUserExists) { } else if (!otherUserExists) {
getParentController().getRouter().setRoot(RouterTransaction.with( getParentController().getRouter().setRoot(RouterTransaction.with(
new ServerSelectionController()) new ServerSelectionController())
.pushChangeHandler(new HorizontalChangeHandler()) .pushChangeHandler(new VerticalChangeHandler())
.popChangeHandler(new HorizontalChangeHandler())); .popChangeHandler(new VerticalChangeHandler()));
} }
new JobRequest.Builder(AccountRemovalJob.TAG).setUpdateCurrent(true) new JobRequest.Builder(AccountRemovalJob.TAG).setUpdateCurrent(true)

View File

@ -37,6 +37,7 @@ import com.nextcloud.talk.controllers.base.BaseController;
import com.nextcloud.talk.persistence.entities.UserEntity; import com.nextcloud.talk.persistence.entities.UserEntity;
import com.nextcloud.talk.utils.database.user.UserUtils; import com.nextcloud.talk.utils.database.user.UserUtils;
import java.net.CookieManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -55,6 +56,9 @@ public class SwitchAccountController extends BaseController {
@Inject @Inject
UserUtils userUtils; UserUtils userUtils;
@Inject
CookieManager cookieManager;
@BindView(R.id.recycler_view) @BindView(R.id.recycler_view)
RecyclerView recyclerView; RecyclerView recyclerView;
@ -80,6 +84,7 @@ public class SwitchAccountController extends BaseController {
@Override @Override
public void onNext(UserEntity userEntity) { public void onNext(UserEntity userEntity) {
cookieManager.getCookieStore().removeAll();
userUtils.disableAllUsersWithoutId(userEntity.getId()); userUtils.disableAllUsersWithoutId(userEntity.getId());
getRouter().popCurrentController(); getRouter().popCurrentController();
} }

View File

@ -29,7 +29,6 @@ import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager; import android.webkit.CookieSyncManager;
import android.webkit.SslErrorHandler; import android.webkit.SslErrorHandler;
import android.webkit.WebView; import android.webkit.WebView;
@ -84,6 +83,8 @@ public class WebViewLoginController extends BaseController {
MagicTrustManager magicTrustManager; MagicTrustManager magicTrustManager;
@Inject @Inject
EventBus eventBus; EventBus eventBus;
@Inject
java.net.CookieManager cookieManager;
@BindView(R.id.webview) @BindView(R.id.webview)
WebView webView; WebView webView;
@ -140,7 +141,7 @@ public class WebViewLoginController extends BaseController {
webView.clearHistory(); webView.clearHistory();
CookieSyncManager.createInstance(getActivity()); CookieSyncManager.createInstance(getActivity());
CookieManager.getInstance().removeAllCookies(null); android.webkit.CookieManager.getInstance().removeAllCookies(null);
Map<String, String> headers = new HashMap<>(); Map<String, String> headers = new HashMap<>();
headers.put("OCS-APIRequest", "true"); headers.put("OCS-APIRequest", "true");
@ -244,6 +245,7 @@ public class WebViewLoginController extends BaseController {
userQueryDisposable = userUtils.createOrUpdateUser(loginData.getUsername(), loginData.getToken(), userQueryDisposable = userUtils.createOrUpdateUser(loginData.getUsername(), loginData.getToken(),
baseUrl, null, null, true). baseUrl, null, null, true).
subscribe(userEntity -> { subscribe(userEntity -> {
cookieManager.getCookieStore().removeAll();
if (!isPasswordUpdate && finalErrorMessageType == null) { if (!isPasswordUpdate && finalErrorMessageType == null) {
BundleBuilder bundleBuilder = new BundleBuilder(new Bundle()); BundleBuilder bundleBuilder = new BundleBuilder(new Bundle());
bundleBuilder.putString(BundleKeys.KEY_USERNAME, userEntity.getUsername()); bundleBuilder.putString(BundleKeys.KEY_USERNAME, userEntity.getUsername());

View File

@ -112,22 +112,32 @@ public class RestModule {
return new SSLSocketFactoryCompat(magicTrustManager); return new SSLSocketFactoryCompat(magicTrustManager);
} }
@Provides
@Singleton
CookieManager provideCookieManager() {
return new CookieManager();
}
@Provides
@Singleton
Cache provideCache() {
int cacheSize = 128 * 1024 * 1024; // 128 MB
return new Cache(NextcloudTalkApplication.getSharedApplication().getCacheDir(), cacheSize);
}
@Provides @Provides
@Singleton @Singleton
OkHttpClient provideHttpClient(Proxy proxy, AppPreferences appPreferences, OkHttpClient provideHttpClient(Proxy proxy, AppPreferences appPreferences,
MagicTrustManager magicTrustManager, MagicTrustManager magicTrustManager,
SSLSocketFactoryCompat sslSocketFactoryCompat) { SSLSocketFactoryCompat sslSocketFactoryCompat, Cache cache,
CookieManager cookieManager) {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.connectTimeout(30, TimeUnit.SECONDS); httpClient.connectTimeout(30, TimeUnit.SECONDS);
httpClient.readTimeout(30, TimeUnit.SECONDS); httpClient.readTimeout(30, TimeUnit.SECONDS);
httpClient.writeTimeout(30, TimeUnit.SECONDS); httpClient.writeTimeout(30, TimeUnit.SECONDS);
httpClient.cookieJar(new JavaNetCookieJar(new CookieManager())); httpClient.cookieJar(new JavaNetCookieJar(cookieManager));
httpClient.cache(cache);
int cacheSize = 128 * 1024 * 1024; // 128 MB
httpClient.cache(new Cache(NextcloudTalkApplication.getSharedApplication().getCacheDir(), cacheSize));
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();