Search in sources :

Example 1 with User

use of com.odysee.app.model.lbryinc.User in project odysee-android by OdyseeTeam.

the class VerificationActivity method onPhoneVerified.

@Override
public void onPhoneVerified() {
    showLoading();
    FetchCurrentUserTask task = new FetchCurrentUserTask(this, new FetchCurrentUserTask.FetchUserTaskHandler() {

        @Override
        public void onSuccess(User user) {
            Lbryio.currentUser = user;
            if (user.isIdentityVerified() && user.isRewardApproved()) {
                // verified for rewards
                LbryAnalytics.logEvent(LbryAnalytics.EVENT_REWARD_ELIGIBILITY_COMPLETED);
                setResult(RESULT_OK);
                finish();
                return;
            }
            findViewById(R.id.verification_close_button).setVisibility(View.VISIBLE);
            // show manual verification page if the user is still not reward approved
            ViewPager2 viewPager = findViewById(R.id.verification_pager);
            viewPager.setCurrentItem(VerificationPagerAdapter.PAGE_VERIFICATION_MANUAL, false);
            hideLoading();
        }

        @Override
        public void onError(Exception error) {
            showFetchUserError(error != null ? error.getMessage() : getString(R.string.fetch_current_user_error));
            hideLoading();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) User(com.odysee.app.model.lbryinc.User) FetchCurrentUserTask(com.odysee.app.tasks.lbryinc.FetchCurrentUserTask)

Example 2 with User

use of com.odysee.app.model.lbryinc.User in project odysee-android by OdyseeTeam.

the class VerificationActivity method checkFlow.

public void checkFlow() {
    ViewPager2 viewPager = findViewById(R.id.verification_pager);
    if (Lbryio.isSignedIn()) {
        boolean flowHandled = false;
        if (flow == VERIFICATION_FLOW_WALLET) {
            viewPager.setCurrentItem(VerificationPagerAdapter.PAGE_VERIFICATION_WALLET, false);
            flowHandled = true;
        } else if (flow == VERIFICATION_FLOW_REWARDS) {
            User user = Lbryio.currentUser;
            // disable phone verification for now
            if (!user.isIdentityVerified()) {
                // phone number verification required
                viewPager.setCurrentItem(VerificationPagerAdapter.PAGE_VERIFICATION_PHONE, false);
                flowHandled = true;
            } else {
                if (!user.isRewardApproved()) {
                    // manual verification required
                    viewPager.setCurrentItem(VerificationPagerAdapter.PAGE_VERIFICATION_MANUAL, false);
                    flowHandled = true;
                }
            }
        }
        if (!flowHandled) {
            // user has already been verified and or reward approved
            setResult(RESULT_CANCELED);
            finish();
            return;
        }
    }
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) User(com.odysee.app.model.lbryinc.User)

Example 3 with User

use of com.odysee.app.model.lbryinc.User in project odysee-android by OdyseeTeam.

the class Lbryio method fetchCurrentUser.

public static User fetchCurrentUser(Context context) throws AuthTokenInvalidatedException {
    try {
        Response response = Lbryio.call("user", "me", context);
        JSONObject object = (JSONObject) parseResponse(response);
        Type type = new TypeToken<User>() {
        }.getType();
        Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
        User user = gson.fromJson(object.toString(), type);
        return user;
    } catch (LbryioRequestException | LbryioResponseException | ClassCastException | IllegalStateException ex) {
        LbryAnalytics.logError(String.format("/user/me failed: %s", ex.getMessage()), ex.getClass().getName());
        if (ex instanceof LbryioResponseException) {
            LbryioResponseException error = (LbryioResponseException) ex;
            if (error.getStatusCode() == 403) {
                // auth token invalidated
                AUTH_TOKEN = null;
                throw new AuthTokenInvalidatedException();
            }
        }
        Log.e(TAG, "Could not retrieve the current user", ex);
        return null;
    }
}
Also used : User(com.odysee.app.model.lbryinc.User) GsonBuilder(com.google.gson.GsonBuilder) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) Gson(com.google.gson.Gson) Response(okhttp3.Response) AuthTokenInvalidatedException(com.odysee.app.exceptions.AuthTokenInvalidatedException) Type(java.lang.reflect.Type) JSONObject(org.json.JSONObject) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException)

Example 4 with User

use of com.odysee.app.model.lbryinc.User in project odysee-android by OdyseeTeam.

the class SignInActivity method performSignIn.

private void performSignIn(final String email, final String password) {
    if (requestInProgress) {
        return;
    }
    if (!emailSignInChecked) {
        requestInProgress = true;
        beforeSignInTransition();
        executor.execute(new Runnable() {

            @Override
            public void run() {
                Map<String, String> options = new HashMap<>();
                options.put("email", email);
                try {
                    Object response = Lbryio.parseResponse(Lbryio.call("user", "exists", options, Helper.METHOD_POST, SignInActivity.this));
                    requestInProgress = false;
                    if (response instanceof JSONObject) {
                        JSONObject json = (JSONObject) response;
                        boolean hasPassword = Helper.getJSONBoolean("has_password", false, json);
                        if (!hasPassword) {
                            setCurrentEmail(email);
                            handleUserSignInWithoutPassword(email);
                            return;
                        }
                        // email exists, we can use sign in flow. Show password field
                        setCurrentEmail(email);
                        emailSignInChecked = true;
                        displaySignInControls();
                        displayMagicLink();
                    }
                } catch (LbryioRequestException | LbryioResponseException ex) {
                    if (ex instanceof LbryioResponseException) {
                        LbryioResponseException rex = (LbryioResponseException) ex;
                        if (rex.getStatusCode() == 412) {
                            // old email verification flow
                            setCurrentEmail(email);
                            handleUserSignInWithoutPassword(email);
                            Bundle bundle = new Bundle();
                            bundle.putString("email", currentEmail);
                            LbryAnalytics.logEvent(LbryAnalytics.EVENT_EMAIL_ADDED, bundle);
                            LbryAnalytics.logEvent("");
                            requestInProgress = false;
                            return;
                        }
                    }
                    requestInProgress = false;
                    restoreControls(true);
                    showError(ex.getMessage());
                }
            }
        });
        return;
    }
    if (Helper.isNullOrEmpty(password)) {
        showError(getString(R.string.please_enter_signin_password));
        return;
    }
    beforeSignInTransition();
    requestInProgress = true;
    executor.execute(new Runnable() {

        @Override
        public void run() {
            Map<String, String> options = new HashMap<>();
            options.put("email", email);
            options.put("password", password);
            try {
                Object response = Lbryio.parseResponse(Lbryio.call("user", "signin", options, Helper.METHOD_POST, SignInActivity.this));
                requestInProgress = false;
                if (response instanceof JSONObject) {
                    Type type = new TypeToken<User>() {
                    }.getType();
                    Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
                    User user = gson.fromJson(response.toString(), type);
                    Lbryio.currentUser = user;
                    addOdyseeAccountExplicitly(user.getPrimaryEmail());
                    finishWithWalletSync();
                    return;
                }
            } catch (LbryioRequestException | LbryioResponseException ex) {
                if (ex instanceof LbryioResponseException) {
                    if (((LbryioResponseException) ex).getStatusCode() == 409) {
                        handleEmailVerificationFlow(email);
                        return;
                    }
                }
                showError(ex.getMessage());
                requestInProgress = false;
                restoreControls(true);
                return;
            }
            requestInProgress = false;
            restoreControls(true);
            showError(getString(R.string.unknown_error_occurred));
        }
    });
}
Also used : User(com.odysee.app.model.lbryinc.User) GsonBuilder(com.google.gson.GsonBuilder) Bundle(android.os.Bundle) Gson(com.google.gson.Gson) Type(java.lang.reflect.Type) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken) JSONObject(org.json.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException)

Example 5 with User

use of com.odysee.app.model.lbryinc.User in project odysee-android by OdyseeTeam.

the class VerificationActivity method onEmailVerified.

public void onEmailVerified() {
    Snackbar.make(findViewById(R.id.verification_pager), R.string.sign_in_successful, Snackbar.LENGTH_LONG).show();
    sendBroadcast(new Intent(MainActivity.ACTION_USER_SIGN_IN_SUCCESS));
    Bundle bundle = new Bundle();
    bundle.putString("email", email);
    LbryAnalytics.logEvent(LbryAnalytics.EVENT_EMAIL_VERIFIED, bundle);
    finish();
    if (flow == VERIFICATION_FLOW_SIGN_IN) {
        final Intent resultIntent = new Intent();
        resultIntent.putExtra("flow", VERIFICATION_FLOW_SIGN_IN);
        resultIntent.putExtra("email", email);
        // only sign in required, don't do anything else
        showLoading();
        FetchCurrentUserTask task = new FetchCurrentUserTask(this, new FetchCurrentUserTask.FetchUserTaskHandler() {

            @Override
            public void onSuccess(User user) {
                Lbryio.currentUser = user;
                setResult(RESULT_OK, resultIntent);
                finish();
            }

            @Override
            public void onError(Exception error) {
                showFetchUserError(error != null ? error.getMessage() : getString(R.string.fetch_current_user_error));
                hideLoading();
            }
        });
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        // change pager view depending on flow
        showLoading();
        FetchCurrentUserTask task = new FetchCurrentUserTask(this, new FetchCurrentUserTask.FetchUserTaskHandler() {

            @Override
            public void onSuccess(User user) {
                hideLoading();
                findViewById(R.id.verification_close_button).setVisibility(View.VISIBLE);
                Lbryio.currentUser = user;
                ViewPager2 viewPager = findViewById(R.id.verification_pager);
                // for rewards, (show phone verification if not done, or manual verification if required)
                if (flow == VERIFICATION_FLOW_REWARDS) {
                    if (!user.isIdentityVerified()) {
                        // phone number verification required
                        viewPager.setCurrentItem(VerificationPagerAdapter.PAGE_VERIFICATION_PHONE, false);
                    } else {
                        if (!user.isRewardApproved()) {
                            // manual verification required
                            viewPager.setCurrentItem(VerificationPagerAdapter.PAGE_VERIFICATION_MANUAL, false);
                        } else {
                            // fully verified
                            setResult(RESULT_OK);
                            finish();
                        }
                    }
                }
            }

            @Override
            public void onError(Exception error) {
                showFetchUserError(error != null ? error.getMessage() : getString(R.string.fetch_current_user_error));
                hideLoading();
            }
        });
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) User(com.odysee.app.model.lbryinc.User) Bundle(android.os.Bundle) FetchCurrentUserTask(com.odysee.app.tasks.lbryinc.FetchCurrentUserTask) Intent(android.content.Intent)

Aggregations

User (com.odysee.app.model.lbryinc.User)7 Bundle (android.os.Bundle)3 ViewPager2 (androidx.viewpager2.widget.ViewPager2)3 Gson (com.google.gson.Gson)3 GsonBuilder (com.google.gson.GsonBuilder)3 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)3 FetchCurrentUserTask (com.odysee.app.tasks.lbryinc.FetchCurrentUserTask)3 Type (java.lang.reflect.Type)3 JSONObject (org.json.JSONObject)3 TypeToken (com.google.gson.reflect.TypeToken)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Intent (android.content.Intent)1 AuthTokenInvalidatedException (com.odysee.app.exceptions.AuthTokenInvalidatedException)1 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)1 Response (okhttp3.Response)1