Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ef22f49 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Merge branch '4280-main-token' into 'main'

feat: Remove token from upgrade url

See merge request !319
parents d2e4faeb 9e9cdb35
Loading
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import foundation.e.drive.account.AccountUtils;
import foundation.e.drive.databinding.ActivityAccountsBinding;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.DavClientProvider;
import foundation.e.drive.utils.AccessTokenProvider;
import foundation.e.drive.widgets.EDriveWidget;
import timber.log.Timber;

@@ -76,7 +75,6 @@ public class AccountsActivity extends AppCompatActivity {
        final String totalQuota = accountManager.getUserData(account, ACCOUNT_DATA_TOTAL_QUOTA_KEY);
        final String email = accountManager.getUserData(account, ACCOUNT_DATA_EMAIL);
        String name = accountManager.getUserData(account, ACCOUNT_DATA_NAME);
        final String token = AccessTokenProvider.getToken(accountManager, account);

        // For some reason if we cant get name use email as name
        if (name == null || name.isEmpty()) {
@@ -139,7 +137,7 @@ public class AccountsActivity extends AppCompatActivity {
        binding.upgrade.setVisibility(View.VISIBLE);
        binding.upgrade.setOnClickListener(v -> {
            final Intent upgradeIntent = EDriveWidget.buildIntent(Intent.ACTION_VIEW,
                    EDriveWidget.buildUpgradeUrl(email, token, totalQuota));
                    EDriveWidget.buildUpgradeUrl(email, totalQuota));
            startActivity(upgradeIntent);
        });

+0 −52
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2024
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.drive.utils

import android.accounts.Account
import android.accounts.AccountManager
import com.owncloud.android.lib.common.accounts.AccountUtils
import net.openid.appauth.AuthState
import org.json.JSONException
import timber.log.Timber

object AccessTokenProvider {

    private const val PLACEHOLDER_TOKEN = "placeholder"

    @JvmStatic
    fun getToken(accountManager: AccountManager, account: Account?): String {
        getAuthState(accountManager, account)?.let { authState ->
            try {
                return AuthState.jsonDeserialize(authState).accessToken ?: PLACEHOLDER_TOKEN
            } catch (e: JSONException) {
                Timber.e(e)
            }
        }

        return PLACEHOLDER_TOKEN
    }

    private fun getAuthState(accountManager: AccountManager, account: Account?): String? {
        var authState: String? = null

        if (account != null) {
            authState = accountManager.getUserData(account, AccountUtils.Constants.KEY_AUTH_STATE)
        }

        return if (authState.isNullOrBlank()) null else authState
    }
}
+1 −5
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import foundation.e.drive.R;
import foundation.e.drive.account.AccountUtils;
import foundation.e.drive.utils.AppConstants;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.AccessTokenProvider;
import timber.log.Timber;

/**
@@ -69,11 +68,9 @@ public class EDriveWidget extends AppWidgetProvider {

    public static @NonNull String buildUpgradeUrl(
            @NonNull String email,
            @NonNull String token,
            @NonNull String totalQuota) {
        return "https://murena.com/ecloud-subscriptions/"
                + "?username=" + email
                + "&token=" + token
                + "&current-quota=" + dataForWeb(totalQuota)
                + "&from=wp";
    }
@@ -223,7 +220,6 @@ public class EDriveWidget extends AppWidgetProvider {
        final String totalQuota = accountManager.getUserData(account, ACCOUNT_DATA_TOTAL_QUOTA_KEY);
        final String email = accountManager.getUserData(account, ACCOUNT_DATA_EMAIL);
        String name = accountManager.getUserData(account, ACCOUNT_DATA_NAME);
        final String token = AccessTokenProvider.getToken(accountManager, account);

        if (email == null || email.trim().isEmpty()) {
            noAccountView(context);
@@ -311,7 +307,7 @@ public class EDriveWidget extends AppWidgetProvider {
        views.setOnClickPendingIntent(R.id.settings, pendingIntentSettings);

        final PendingIntent pendingIntentUpgrade = PendingIntent.getActivity(context, 0,
                buildIntent(Intent.ACTION_VIEW, buildUpgradeUrl(email, token,
                buildIntent(Intent.ACTION_VIEW, buildUpgradeUrl(email,
                        totalQuota)), PendingIntent.FLAG_IMMUTABLE);
        views.setOnClickPendingIntent(R.id.upgrade, pendingIntentUpgrade);
    }