326 lines
18 KiB
Java
326 lines
18 KiB
Java
package com.discord.widgets.auth;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.view.View;
|
|
import androidx.activity.result.ActivityResultLauncher;
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.fragment.app.FragmentActivity;
|
|
import b.a.d.m;
|
|
import b.a.k.b;
|
|
import b.d.b.a.a;
|
|
import com.discord.R;
|
|
import com.discord.app.AppFragment;
|
|
import com.discord.app.LoggingConfig;
|
|
import com.discord.databinding.WidgetAuthLoginBinding;
|
|
import com.discord.restapi.RestAPIParams;
|
|
import com.discord.stores.StorePhone;
|
|
import com.discord.stores.StoreStream;
|
|
import com.discord.stores.updates.ObservationDeck;
|
|
import com.discord.stores.updates.ObservationDeckProvider;
|
|
import com.discord.utilities.auth.GoogleSmartLockManager;
|
|
import com.discord.utilities.auth.GoogleSmartLockManagerKt;
|
|
import com.discord.utilities.auth.RegistrationFlowRepo;
|
|
import com.discord.utilities.captcha.CaptchaHelper;
|
|
import com.discord.utilities.error.Error;
|
|
import com.discord.utilities.rx.ObservableExtensionsKt;
|
|
import com.discord.utilities.view.extensions.ViewExtensions;
|
|
import com.discord.utilities.view.validators.ValidationManager;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegate;
|
|
import com.discord.utilities.viewbinding.FragmentViewBindingDelegateKt;
|
|
import com.discord.widgets.auth.WidgetAuthCaptcha;
|
|
import com.discord.widgets.auth.WidgetAuthPhoneVerify;
|
|
import com.google.android.material.textfield.TextInputLayout;
|
|
import d0.g;
|
|
import d0.g0.t;
|
|
import d0.t.u;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import kotlin.Lazy;
|
|
import kotlin.jvm.functions.Function0;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
|
import kotlin.reflect.KProperty;
|
|
/* compiled from: WidgetAuthLogin.kt */
|
|
public final class WidgetAuthLogin extends AppFragment {
|
|
public static final /* synthetic */ KProperty[] $$delegatedProperties = {a.b0(WidgetAuthLogin.class, "binding", "getBinding()Lcom/discord/databinding/WidgetAuthLoginBinding;", 0)};
|
|
public static final Companion Companion = new Companion(null);
|
|
public static final String GOOGLE_SMARTLOCK_LOGIN_EXTRA_ID = "smartlock_extra_id";
|
|
public static final String GOOGLE_SMARTLOCK_LOGIN_EXTRA_PASSWORD = "smartlock_extra_password";
|
|
private final FragmentViewBindingDelegate binding$delegate = FragmentViewBindingDelegateKt.viewBinding$default(this, WidgetAuthLogin$binding$2.INSTANCE, null, 2, null);
|
|
private final ActivityResultLauncher<Intent> captchaForgotPasswordLauncher;
|
|
private final ActivityResultLauncher<Intent> captchaLoginLauncher;
|
|
public GoogleSmartLockManager googleSmartLockManager;
|
|
private final LoggingConfig loggingConfig = new LoggingConfig(false, null, WidgetAuthLogin$loggingConfig$1.INSTANCE, 3);
|
|
private final ActivityResultLauncher<Intent> phoneVerifyLoginLauncher;
|
|
private final ActivityResultLauncher<Intent> phoneVerifyPasswordLauncher;
|
|
private GoogleSmartLockManager.SmartLockCredentials smartLockCredentials;
|
|
private final ActivityResultLauncher<Intent> undeleteAccountLauncher;
|
|
private final Lazy validationManager$delegate;
|
|
|
|
/* compiled from: WidgetAuthLogin.kt */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
public WidgetAuthLogin() {
|
|
super(R.layout.widget_auth_login);
|
|
WidgetAuthCaptcha.Companion companion = WidgetAuthCaptcha.Companion;
|
|
this.captchaForgotPasswordLauncher = companion.registerForResult(this, new WidgetAuthLogin$captchaForgotPasswordLauncher$1(this));
|
|
this.captchaLoginLauncher = companion.registerForResult(this, new WidgetAuthLogin$captchaLoginLauncher$1(this));
|
|
WidgetAuthPhoneVerify.Companion companion2 = WidgetAuthPhoneVerify.Companion;
|
|
this.phoneVerifyLoginLauncher = companion2.registerForResult(this, new WidgetAuthLogin$phoneVerifyLoginLauncher$1(this));
|
|
this.phoneVerifyPasswordLauncher = companion2.registerForResult(this, new WidgetAuthLogin$phoneVerifyPasswordLauncher$1(this));
|
|
this.undeleteAccountLauncher = WidgetAuthUndeleteAccount.Companion.registerForResult(this, new WidgetAuthLogin$undeleteAccountLauncher$1(this));
|
|
this.validationManager$delegate = g.lazy(new WidgetAuthLogin$validationManager$2(this));
|
|
}
|
|
|
|
public static final /* synthetic */ void access$forgotPassword(WidgetAuthLogin widgetAuthLogin, CaptchaHelper.CaptchaPayload captchaPayload) {
|
|
widgetAuthLogin.forgotPassword(captchaPayload);
|
|
}
|
|
|
|
public static final /* synthetic */ WidgetAuthLoginBinding access$getBinding$p(WidgetAuthLogin widgetAuthLogin) {
|
|
return widgetAuthLogin.getBinding();
|
|
}
|
|
|
|
public static final /* synthetic */ ActivityResultLauncher access$getCaptchaForgotPasswordLauncher$p(WidgetAuthLogin widgetAuthLogin) {
|
|
return widgetAuthLogin.captchaForgotPasswordLauncher;
|
|
}
|
|
|
|
public static final /* synthetic */ ActivityResultLauncher access$getPhoneVerifyPasswordLauncher$p(WidgetAuthLogin widgetAuthLogin) {
|
|
return widgetAuthLogin.phoneVerifyPasswordLauncher;
|
|
}
|
|
|
|
public static final /* synthetic */ ValidationManager access$getValidationManager$p(WidgetAuthLogin widgetAuthLogin) {
|
|
return widgetAuthLogin.getValidationManager();
|
|
}
|
|
|
|
public static final /* synthetic */ void access$handleError(WidgetAuthLogin widgetAuthLogin, Error error, String str) {
|
|
widgetAuthLogin.handleError(error, str);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$onLoginSuccess(WidgetAuthLogin widgetAuthLogin, String str, String str2) {
|
|
widgetAuthLogin.onLoginSuccess(str, str2);
|
|
}
|
|
|
|
public static final /* synthetic */ void access$showEmailSentToast(WidgetAuthLogin widgetAuthLogin, String str) {
|
|
widgetAuthLogin.showEmailSentToast(str);
|
|
}
|
|
|
|
private final void forgotPassword(CaptchaHelper.CaptchaPayload captchaPayload) {
|
|
String textOrEmpty = getBinding().e.getTextOrEmpty();
|
|
if (textOrEmpty.length() == 0) {
|
|
m.g(getContext(), R.string.login_required, 0, null, 12);
|
|
} else {
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.withDimmer$default(ObservableExtensionsKt.ui(StoreStream.Companion.getAuthentication().forgotPassword(textOrEmpty, captchaPayload)), getBinding().h, 0, 2, null), getContext(), "REST: forgotPassword", (Function1) null, new WidgetAuthLogin$forgotPassword$1(this, textOrEmpty), new WidgetAuthLogin$forgotPassword$2(this, textOrEmpty), (Function0) null, (Function0) null, 100, (Object) null);
|
|
}
|
|
}
|
|
|
|
public static /* synthetic */ void forgotPassword$default(WidgetAuthLogin widgetAuthLogin, CaptchaHelper.CaptchaPayload captchaPayload, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
captchaPayload = null;
|
|
}
|
|
widgetAuthLogin.forgotPassword(captchaPayload);
|
|
}
|
|
|
|
private final WidgetAuthLoginBinding getBinding() {
|
|
return (WidgetAuthLoginBinding) this.binding$delegate.getValue((Fragment) this, $$delegatedProperties[0]);
|
|
}
|
|
|
|
private final ValidationManager getValidationManager() {
|
|
return (ValidationManager) this.validationManager$delegate.getValue();
|
|
}
|
|
|
|
private final void handleError(Error error, String str) {
|
|
Error.Response response = error.getResponse();
|
|
d0.z.d.m.checkNotNullExpressionValue(response, "error.response");
|
|
boolean z2 = response.getCode() == 20011;
|
|
boolean z3 = response.getCode() == 20013;
|
|
boolean z4 = response.getCode() == 70007;
|
|
if (response.getCode() == 50035) {
|
|
if (str != null && this.smartLockCredentials != null) {
|
|
GoogleSmartLockManager googleSmartLockManager = this.googleSmartLockManager;
|
|
if (googleSmartLockManager == null) {
|
|
d0.z.d.m.throwUninitializedPropertyAccessException("googleSmartLockManager");
|
|
}
|
|
googleSmartLockManager.getSmartLockRepo().onSmartLockCredentialsFailed();
|
|
GoogleSmartLockManager googleSmartLockManager2 = this.googleSmartLockManager;
|
|
if (googleSmartLockManager2 == null) {
|
|
d0.z.d.m.throwUninitializedPropertyAccessException("googleSmartLockManager");
|
|
}
|
|
googleSmartLockManager2.deleteCredentials(str);
|
|
this.smartLockCredentials = null;
|
|
GoogleSmartLockManagerKt.clearSmartLockCredentials(getMostRecentIntent());
|
|
}
|
|
} else if (z2) {
|
|
WidgetAuthUndeleteAccount.Companion.launch(requireContext(), this.undeleteAccountLauncher, false);
|
|
} else if (z3) {
|
|
WidgetAuthUndeleteAccount.Companion.launch(requireContext(), this.undeleteAccountLauncher, true);
|
|
} else if (z4) {
|
|
WidgetAuthPhoneVerify.Companion companion = WidgetAuthPhoneVerify.Companion;
|
|
Context requireContext = requireContext();
|
|
ActivityResultLauncher<Intent> activityResultLauncher = this.phoneVerifyLoginLauncher;
|
|
String textOrEmpty = getBinding().e.getTextOrEmpty();
|
|
String string = getString(R.string.phone_ip_authorization_title);
|
|
d0.z.d.m.checkNotNullExpressionValue(string, "getString(R.string.phone_ip_authorization_title)");
|
|
String string2 = getString(R.string.phone_ip_authorization_subtitle);
|
|
d0.z.d.m.checkNotNullExpressionValue(string2, "getString(R.string.phone…p_authorization_subtitle)");
|
|
companion.launch(requireContext, activityResultLauncher, textOrEmpty, string, string2);
|
|
} else {
|
|
Error.Response response2 = error.getResponse();
|
|
d0.z.d.m.checkNotNullExpressionValue(response2, "error.response");
|
|
if (!response2.getMessages().isEmpty()) {
|
|
ValidationManager validationManager = getValidationManager();
|
|
Map<String, List<String>> messages = response.getMessages();
|
|
d0.z.d.m.checkNotNullExpressionValue(messages, "errorResponse.messages");
|
|
List<String> mutableList = u.toMutableList((Collection) validationManager.setErrors(messages));
|
|
WidgetAuthCaptcha.Companion.processErrorsForCaptcha(requireContext(), this.captchaLoginLauncher, mutableList, error);
|
|
error.setShowErrorToasts(!mutableList.isEmpty());
|
|
}
|
|
}
|
|
}
|
|
|
|
public static /* synthetic */ void handleError$default(WidgetAuthLogin widgetAuthLogin, Error error, String str, int i, Object obj) {
|
|
if ((i & 2) != 0) {
|
|
str = null;
|
|
}
|
|
widgetAuthLogin.handleError(error, str);
|
|
}
|
|
|
|
private final void loadCachedLogin() {
|
|
String savedLogin = StoreStream.Companion.getAuthentication().getSavedLogin();
|
|
if (savedLogin == null || !(!t.isBlank(savedLogin))) {
|
|
getBinding().e.requestFocus();
|
|
return;
|
|
}
|
|
getBinding().e.setText(savedLogin);
|
|
getBinding().g.requestFocus();
|
|
}
|
|
|
|
private final void login(CaptchaHelper.CaptchaPayload captchaPayload, boolean z2) {
|
|
if (ValidationManager.validate$default(getValidationManager(), false, 1, null)) {
|
|
String textOrEmpty = getBinding().e.getTextOrEmpty();
|
|
TextInputLayout textInputLayout = getBinding().g;
|
|
d0.z.d.m.checkNotNullExpressionValue(textInputLayout, "binding.authLoginPasswordWrap");
|
|
login(textOrEmpty, ViewExtensions.getTextOrEmpty(textInputLayout), captchaPayload, z2);
|
|
}
|
|
}
|
|
|
|
private final void login(String str, String str2, CaptchaHelper.CaptchaPayload captchaPayload, boolean z2) {
|
|
Context context = getContext();
|
|
if (context != null) {
|
|
d0.z.d.m.checkNotNullExpressionValue(context, "context ?: return");
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.withDimmer$default(ObservableExtensionsKt.ui$default(StoreStream.Companion.getAuthentication().login(str, str2, captchaPayload, z2, GoogleSmartLockManagerKt.hasSmartLockCredentials(getMostRecentIntent()) ? RestAPIParams.AuthLogin.LoginSource.LOGIN_SOURCE_KEYCHAIN_AUTO : null), this, null, 2, null), getBinding().h, 0, 2, null), context, "REST: login", (Function1) null, new WidgetAuthLogin$login$1(this, str, str2, context), new WidgetAuthLogin$login$2(this, str), (Function0) null, (Function0) null, 100, (Object) null);
|
|
}
|
|
}
|
|
|
|
public static /* synthetic */ void login$default(WidgetAuthLogin widgetAuthLogin, CaptchaHelper.CaptchaPayload captchaPayload, boolean z2, int i, Object obj) {
|
|
if ((i & 1) != 0) {
|
|
captchaPayload = null;
|
|
}
|
|
if ((i & 2) != 0) {
|
|
z2 = false;
|
|
}
|
|
widgetAuthLogin.login(captchaPayload, z2);
|
|
}
|
|
|
|
public static /* synthetic */ void login$default(WidgetAuthLogin widgetAuthLogin, String str, String str2, CaptchaHelper.CaptchaPayload captchaPayload, boolean z2, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
captchaPayload = null;
|
|
}
|
|
if ((i & 8) != 0) {
|
|
z2 = false;
|
|
}
|
|
widgetAuthLogin.login(str, str2, captchaPayload, z2);
|
|
}
|
|
|
|
private final void onLoginSuccess(String str, String str2) {
|
|
if (GoogleSmartLockManagerKt.hasSmartLockCredentials(getMostRecentIntent())) {
|
|
GoogleSmartLockManager googleSmartLockManager = this.googleSmartLockManager;
|
|
if (googleSmartLockManager == null) {
|
|
d0.z.d.m.throwUninitializedPropertyAccessException("googleSmartLockManager");
|
|
}
|
|
googleSmartLockManager.getSmartLockRepo().onLoginWithSmartLockSuccess();
|
|
}
|
|
GoogleSmartLockManager googleSmartLockManager2 = this.googleSmartLockManager;
|
|
if (googleSmartLockManager2 == null) {
|
|
d0.z.d.m.throwUninitializedPropertyAccessException("googleSmartLockManager");
|
|
}
|
|
googleSmartLockManager2.saveCredentials(str, str2);
|
|
}
|
|
|
|
private final void showEmailSentToast(String str) {
|
|
m.h(getContext(), b.h(requireContext(), R.string.email_verification_instructions_body, new Object[]{str}, null, 4), 0, null, 12);
|
|
}
|
|
|
|
public final GoogleSmartLockManager getGoogleSmartLockManager() {
|
|
GoogleSmartLockManager googleSmartLockManager = this.googleSmartLockManager;
|
|
if (googleSmartLockManager == null) {
|
|
d0.z.d.m.throwUninitializedPropertyAccessException("googleSmartLockManager");
|
|
}
|
|
return googleSmartLockManager;
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment, com.discord.app.AppLogger.a
|
|
public LoggingConfig getLoggingConfig() {
|
|
return this.loggingConfig;
|
|
}
|
|
|
|
public final GoogleSmartLockManager.SmartLockCredentials getSmartLockCredentials() {
|
|
return this.smartLockCredentials;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onCreate(Bundle bundle) {
|
|
super.onCreate(bundle);
|
|
RegistrationFlowRepo.Companion.getINSTANCE().setRegistering(false);
|
|
FragmentActivity requireActivity = requireActivity();
|
|
d0.z.d.m.checkNotNullExpressionValue(requireActivity, "requireActivity()");
|
|
this.googleSmartLockManager = new GoogleSmartLockManager(requireActivity, null, 2, null);
|
|
this.smartLockCredentials = GoogleSmartLockManagerKt.toSmartLockCredentials(getMostRecentIntent());
|
|
}
|
|
|
|
@Override // com.discord.app.AppFragment
|
|
public void onViewBound(View view) {
|
|
d0.z.d.m.checkNotNullParameter(view, "view");
|
|
super.onViewBound(view);
|
|
StoreStream.Companion companion = StoreStream.Companion;
|
|
companion.getInviteSettings().trackWithInvite$app_productionBetaRelease(WidgetAuthLogin.class, WidgetAuthLogin$onViewBound$1.INSTANCE);
|
|
loadCachedLogin();
|
|
getBinding().f2217b.setOnClickListener(new WidgetAuthLogin$onViewBound$2(this));
|
|
TextInputLayout textInputLayout = getBinding().g;
|
|
d0.z.d.m.checkNotNullExpressionValue(textInputLayout, "binding.authLoginPasswordWrap");
|
|
ViewExtensions.setOnImeActionDone$default(textInputLayout, false, new WidgetAuthLogin$onViewBound$3(this), 1, null);
|
|
getBinding().d.setOnClickListener(new WidgetAuthLogin$onViewBound$4(this));
|
|
getBinding().f.setOnClickListener(new WidgetAuthLogin$onViewBound$5(this));
|
|
getBinding().c.setOnClickListener(new WidgetAuthLogin$onViewBound$6(this));
|
|
getBinding().e.b(this);
|
|
GoogleSmartLockManager.SmartLockCredentials smartLockCredentials = this.smartLockCredentials;
|
|
if (smartLockCredentials != null) {
|
|
getBinding().e.setText(smartLockCredentials.getId());
|
|
TextInputLayout textInputLayout2 = getBinding().g;
|
|
d0.z.d.m.checkNotNullExpressionValue(textInputLayout2, "binding.authLoginPasswordWrap");
|
|
ViewExtensions.setText(textInputLayout2, smartLockCredentials.getPassword());
|
|
login$default(this, null, false, 3, null);
|
|
}
|
|
StorePhone phone = companion.getPhone();
|
|
ObservableExtensionsKt.appSubscribe$default(ObservableExtensionsKt.ui$default(ObservationDeck.connectRx$default(ObservationDeckProvider.get(), new ObservationDeck.UpdateSource[]{phone}, false, null, null, new WidgetAuthLogin$onViewBound$8(phone), 14, null), this, null, 2, null), WidgetAuthLogin.class, (Context) null, (Function1) null, (Function1) null, (Function0) null, (Function0) null, new WidgetAuthLogin$onViewBound$9(this), 62, (Object) null);
|
|
}
|
|
|
|
public final void setGoogleSmartLockManager(GoogleSmartLockManager googleSmartLockManager) {
|
|
d0.z.d.m.checkNotNullParameter(googleSmartLockManager, "<set-?>");
|
|
this.googleSmartLockManager = googleSmartLockManager;
|
|
}
|
|
|
|
public final void setSmartLockCredentials(GoogleSmartLockManager.SmartLockCredentials smartLockCredentials) {
|
|
this.smartLockCredentials = smartLockCredentials;
|
|
}
|
|
}
|