Search in sources :

Example 1 with LoginData

use of com.nextcloud.talk.models.LoginData in project talk-android by nextcloud.

the class WebViewLoginController method parseAndLoginFromWebView.

private void parseAndLoginFromWebView(String dataString) {
    LoginData loginData = parseLoginData(assembledPrefix, dataString);
    if (loginData != null) {
        dispose();
        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 (userUtils.checkIfUserIsScheduledForDeletion(loginData.getUsername(), baseUrl)) {
                ApplicationWideMessageHolder.getInstance().setMessageType(ApplicationWideMessageHolder.MessageType.ACCOUNT_SCHEDULED_FOR_DELETION);
                getRouter().popToRoot();
            }
            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 (baseUrl.startsWith("http://")) {
                    protocol = "http://";
                } else if (baseUrl.startsWith("https://")) {
                    protocol = "https://";
                }
                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, null, null, null, null, true, null, currentUser.getId(), null).subscribe(userEntity -> {
                            if (finalMessageType != null) {
                                ApplicationWideMessageHolder.getInstance().setMessageType(finalMessageType);
                            }
                            getRouter().popToRoot();
                        }, throwable -> dispose(), this::dispose);
                    }
                } else {
                    if (finalMessageType != null) {
                        ApplicationWideMessageHolder.getInstance().setMessageType(finalMessageType);
                    }
                    getRouter().popToRoot();
                }
            }
        }
    }
}
Also used : X509Certificate(java.security.cert.X509Certificate) AutoInjector(autodagger.AutoInjector) Bundle(android.os.Bundle) KeyChain(android.security.KeyChain) UserUtils(com.nextcloud.talk.utils.database.user.UserUtils) URLDecoder(java.net.URLDecoder) ProgressBar(android.widget.ProgressBar) URL(java.net.URL) BindView(butterknife.BindView) SslErrorHandler(android.webkit.SslErrorHandler) Locale(java.util.Locale) Map(java.util.Map) ActivityInfo(android.content.pm.ActivityInfo) WebViewClient(android.webkit.WebViewClient) View(android.view.View) CookieSyncManager(android.webkit.CookieSyncManager) WebView(android.webkit.WebView) Persistable(io.requery.Persistable) Log(android.util.Log) ReactiveEntityStore(io.requery.reactivex.ReactiveEntityStore) ViewGroup(android.view.ViewGroup) BundleKeys(com.nextcloud.talk.utils.bundle.BundleKeys) Disposable(io.reactivex.disposables.Disposable) ClientCertRequest(android.webkit.ClientCertRequest) LoginData(com.nextcloud.talk.models.LoginData) PrivateKey(java.security.PrivateKey) UserEntity(com.nextcloud.talk.models.database.UserEntity) HashMap(java.util.HashMap) NonNull(android.support.annotation.NonNull) CertificateEvent(com.nextcloud.talk.events.CertificateEvent) MagicTrustManager(com.nextcloud.talk.utils.ssl.MagicTrustManager) Inject(javax.inject.Inject) WebSettings(android.webkit.WebSettings) BaseController(com.nextcloud.talk.controllers.base.BaseController) EventBus(org.greenrobot.eventbus.EventBus) Build(android.os.Build) SslError(android.net.http.SslError) R(com.nextcloud.talk.R) MalformedURLException(java.net.MalformedURLException) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) CertificateException(java.security.cert.CertificateException) Field(java.lang.reflect.Field) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler) KeyChainException(android.security.KeyChainException) SslCertificate(android.net.http.SslCertificate) ApplicationWideMessageHolder(com.nextcloud.talk.utils.ApplicationWideMessageHolder) NextcloudTalkApplication(com.nextcloud.talk.application.NextcloudTalkApplication) RouterTransaction(com.bluelinelabs.conductor.RouterTransaction) ApplicationWideMessageHolder(com.nextcloud.talk.utils.ApplicationWideMessageHolder) LoginData(com.nextcloud.talk.models.LoginData) Bundle(android.os.Bundle) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler) UserEntity(com.nextcloud.talk.models.database.UserEntity)

Example 2 with LoginData

use of com.nextcloud.talk.models.LoginData in project talk-android by nextcloud.

the class WebViewLoginController method parseLoginData.

private LoginData parseLoginData(String prefix, String dataString) {
    if (dataString.length() < prefix.length()) {
        return null;
    }
    LoginData loginData = new LoginData();
    // format is xxx://login/server:xxx&user:xxx&password:xxx
    String data = dataString.substring(prefix.length());
    String[] values = data.split("&");
    if (values.length != 3) {
        return null;
    }
    for (String value : values) {
        if (value.startsWith("user" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR)) {
            loginData.setUsername(URLDecoder.decode(value.substring(("user" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR).length())));
        } else if (value.startsWith("password" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR)) {
            loginData.setToken(URLDecoder.decode(value.substring(("password" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR).length())));
        } else if (value.startsWith("server" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR)) {
            loginData.setServerUrl(URLDecoder.decode(value.substring(("server" + LOGIN_URL_DATA_KEY_VALUE_SEPARATOR).length())));
        } else {
            return null;
        }
    }
    if (!TextUtils.isEmpty(loginData.getServerUrl()) && !TextUtils.isEmpty(loginData.getUsername()) && !TextUtils.isEmpty(loginData.getToken())) {
        return loginData;
    } else {
        return null;
    }
}
Also used : LoginData(com.nextcloud.talk.models.LoginData)

Aggregations

LoginData (com.nextcloud.talk.models.LoginData)2 ActivityInfo (android.content.pm.ActivityInfo)1 SslCertificate (android.net.http.SslCertificate)1 SslError (android.net.http.SslError)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 KeyChain (android.security.KeyChain)1 KeyChainException (android.security.KeyChainException)1 NonNull (android.support.annotation.NonNull)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ClientCertRequest (android.webkit.ClientCertRequest)1 CookieSyncManager (android.webkit.CookieSyncManager)1 SslErrorHandler (android.webkit.SslErrorHandler)1 WebSettings (android.webkit.WebSettings)1 WebView (android.webkit.WebView)1 WebViewClient (android.webkit.WebViewClient)1