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);
}
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;
}
}
}
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;
}
}
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));
}
});
}
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);
}
}
Aggregations