Sfoglia il codice sorgente

Fix credentials update

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 6 anni fa
parent
commit
5000b3e9de

+ 0 - 5
app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java

@@ -460,11 +460,6 @@ public class SettingsController extends BaseController {
                     messageText.setText(getResources().getString(R.string.nc_settings_account_updated));
                     messageView.setVisibility(View.VISIBLE);
                     break;
-                case WRONG_ACCOUNT:
-                    messageText.setTextColor(getResources().getColor(R.color.nc_darkRed));
-                    messageText.setText(getResources().getString(R.string.nc_settings_wrong_account));
-                    messageView.setVisibility(View.VISIBLE);
-                    break;
                 case SERVER_WITHOUT_TALK:
                     messageText.setTextColor(getResources().getColor(R.color.nc_darkRed));
                     messageText.setText(getResources().getString(R.string.nc_settings_wrong_account));

+ 50 - 52
app/src/main/java/com/nextcloud/talk/controllers/WebViewLoginController.java

@@ -325,69 +325,67 @@ public class WebViewLoginController extends BaseController {
             UserEntity currentUser = userUtils.getCurrentUser();
 
             ApplicationWideMessageHolder.MessageType messageType = null;
-            if (currentUser != null && isPasswordUpdate &&
-                    !currentUser.getUsername().equals(loginData.getUsername())) {
-                ApplicationWideMessageHolder.getInstance().setMessageType(
-                        ApplicationWideMessageHolder.MessageType.WRONG_ACCOUNT);
-                getRouter().popToRoot();
-            } else {
 
-                if (!isPasswordUpdate && userUtils.getIfUserWithUsernameAndServer(loginData.getUsername(), baseUrl)) {
-                    messageType = ApplicationWideMessageHolder.MessageType.ACCOUNT_UPDATED_NOT_ADDED;
-                }
+            if (!isPasswordUpdate && userUtils.getIfUserWithUsernameAndServer(loginData.getUsername(), baseUrl)) {
+                messageType = ApplicationWideMessageHolder.MessageType.ACCOUNT_UPDATED_NOT_ADDED;
+            }
+
+            if (userUtils.checkIfUserIsScheduledForDeletion(loginData.getUsername(), baseUrl)) {
+                ApplicationWideMessageHolder.getInstance().setMessageType(
+                        ApplicationWideMessageHolder.MessageType.ACCOUNT_SCHEDULED_FOR_DELETION);
 
-                if (userUtils.checkIfUserIsScheduledForDeletion(loginData.getUsername(), baseUrl)) {
-                    ApplicationWideMessageHolder.getInstance().setMessageType(
-                            ApplicationWideMessageHolder.MessageType.ACCOUNT_SCHEDULED_FOR_DELETION);
+                if (!isPasswordUpdate) {
                     getRouter().popToRoot();
+                } else {
+                    getRouter().popCurrentController();
                 }
+            }
 
-                ApplicationWideMessageHolder.MessageType finalMessageType = messageType;
-                cookieManager.getCookieStore().removeAll();
+            ApplicationWideMessageHolder.MessageType finalMessageType = messageType;
+            cookieManager.getCookieStore().removeAll();
 
-                if (!isPasswordUpdate && finalMessageType == null) {
-                    Bundle bundle = new Bundle();
-                    bundle.putString(BundleKeys.KEY_USERNAME, loginData.getUsername());
-                    bundle.putString(BundleKeys.KEY_TOKEN, loginData.getToken());
-                    bundle.putString(BundleKeys.KEY_BASE_URL, loginData.getServerUrl());
-                    String protocol = "";
+            if (!isPasswordUpdate && finalMessageType == null) {
+                Bundle bundle = new Bundle();
+                bundle.putString(BundleKeys.KEY_USERNAME, loginData.getUsername());
+                bundle.putString(BundleKeys.KEY_TOKEN, loginData.getToken());
+                bundle.putString(BundleKeys.KEY_BASE_URL, loginData.getServerUrl());
+                String protocol = "";
 
-                    if (baseUrl.startsWith("http://")) {
-                        protocol = "http://";
-                    } else if (baseUrl.startsWith("https://")) {
-                        protocol = "https://";
-                    }
+                if (baseUrl.startsWith("http://")) {
+                    protocol = "http://";
+                } else if (baseUrl.startsWith("https://")) {
+                    protocol = "https://";
+                }
+
+                if (!TextUtils.isEmpty(protocol)) {
+                    bundle.putString(BundleKeys.KEY_ORIGINAL_PROTOCOL, protocol);
+                }
 
-                    if (!TextUtils.isEmpty(protocol)) {
-                        bundle.putString(BundleKeys.KEY_ORIGINAL_PROTOCOL, protocol);
+                getRouter().pushController(RouterTransaction.with(new AccountVerificationController
+                        (bundle)).pushChangeHandler(new HorizontalChangeHandler())
+                        .popChangeHandler(new HorizontalChangeHandler()));
+            } else {
+                if (isPasswordUpdate) {
+                    if (currentUser != null) {
+                        userQueryDisposable = userUtils.createOrUpdateUser(null, loginData.getToken(),
+                                null, null, null, true,
+                                null, currentUser.getId(), null, appPreferences.getTemporaryClientCertAlias(), null)
+                                .subscribeOn(Schedulers.newThread())
+                                .observeOn(AndroidSchedulers.mainThread())
+                                .subscribe(userEntity -> {
+                                            if (finalMessageType != null) {
+                                                ApplicationWideMessageHolder.getInstance().setMessageType(finalMessageType);
+                                            }
+                                            getRouter().popCurrentController();
+                                        }, throwable -> dispose(),
+                                        this::dispose);
                     }
-                    
-                    getRouter().pushController(RouterTransaction.with(new AccountVerificationController
-                            (bundle)).pushChangeHandler(new HorizontalChangeHandler())
-                            .popChangeHandler(new HorizontalChangeHandler()));
                 } else {
-                    if (isPasswordUpdate) {
-                        if (currentUser != null) {
-                            userQueryDisposable = userUtils.createOrUpdateUser(null, loginData.getToken(),
-                                    null, null, null, true,
-                                    null, currentUser.getId(), null, appPreferences.getTemporaryClientCertAlias(), null)
-                                    .subscribeOn(Schedulers.newThread())
-                                    .observeOn(AndroidSchedulers.mainThread())
-                                    .subscribe(userEntity -> {
-                                                if (finalMessageType != null) {
-                                                    ApplicationWideMessageHolder.getInstance().setMessageType(finalMessageType);
-                                                }
-                                                getRouter().popCurrentController();
-                                            }, throwable -> dispose(),
-                                            this::dispose);
-                        }
-                    } else {
-                        if (finalMessageType != null) {
-                            ApplicationWideMessageHolder.getInstance().setMessageType(finalMessageType);
-                        }
-                        getRouter().popToRoot();
-
+                    if (finalMessageType != null) {
+                        ApplicationWideMessageHolder.getInstance().setMessageType(finalMessageType);
                     }
+                    getRouter().popToRoot();
+
                 }
             }
         }