Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Login] Show magic link screen for suspicious emails #13335

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,10 @@ class LoginActivity :
}
}

private fun showEmailPasswordScreen(
email: String?,
verifyEmail: Boolean,
password: String? = null
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part about prefilling the password was used just for the account signup, given we don't support this anymore, I deleted it, and deleted its code from the Fragment as well.

) {
private fun showEmailPasswordScreen(email: String?, verifyEmail: Boolean) {
val wooLoginEmailPasswordFragment = WooLoginEmailPasswordFragment
.newInstance(
emailAddress = email,
password = password,
verifyMagicLinkEmail = verifyEmail
)
changeFragment(wooLoginEmailPasswordFragment, true, LoginEmailPasswordFragment.TAG)
Expand Down Expand Up @@ -901,8 +896,8 @@ class LoginActivity :
TODO("Not yet implemented")
}

override fun useMagicLinkInstead(email: String?, verifyEmail: Boolean) {
showMagicLinkRequestScreen(email, verifyEmail, allowPassword = false, forceRequestAtStart = true)
override fun useMagicLinkInstead(email: String?, verifyEmail: Boolean, requestAtStart: Boolean) {
showMagicLinkRequestScreen(email, verifyEmail, allowPassword = false, forceRequestAtStart = requestAtStart)
}

/**
Expand Down Expand Up @@ -969,7 +964,7 @@ class LoginActivity :
stat = AnalyticsEvent.LOGIN_APP_LOGIN_LINK_SUCCESS,
properties = mapOf(KEY_FLOW to VALUE_WP_COM)
)
showEmailPasswordScreen(email = wpComEmail, verifyEmail = false, password = null)
showEmailPasswordScreen(email = wpComEmail, verifyEmail = false)
}

siteUrl.isNotEmpty() && username.isNotEmpty() -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
package com.woocommerce.android.ui.login.overrides

import android.content.Context
import android.os.Bundle
import android.view.ViewGroup
import android.widget.Button
import androidx.annotation.LayoutRes
import androidx.core.view.isVisible
import com.bumptech.glide.Registry.MissingComponentException
import com.woocommerce.android.R
import com.woocommerce.android.extensions.isNotNullOrEmpty
import dagger.android.support.AndroidSupportInjection
import org.wordpress.android.login.LoginEmailPasswordFragment
import org.wordpress.android.login.LoginListener
import org.wordpress.android.login.widgets.WPLoginInputRow

class WooLoginEmailPasswordFragment : LoginEmailPasswordFragment() {
companion object {
@Suppress("LongParameterList")
fun newInstance(
emailAddress: String?,
password: String? = null,
idToken: String? = null,
service: String? = null,
isSocialLogin: Boolean = false,
Expand All @@ -28,7 +21,6 @@ class WooLoginEmailPasswordFragment : LoginEmailPasswordFragment() {
val fragment = WooLoginEmailPasswordFragment()
val args = Bundle()
args.putString(ARG_EMAIL_ADDRESS, emailAddress)
args.putString(ARG_PASSWORD, password)
args.putString(ARG_SOCIAL_ID_TOKEN, idToken)
args.putString(ARG_SOCIAL_SERVICE, service)
args.putBoolean(ARG_SOCIAL_LOGIN, isSocialLogin)
Expand All @@ -39,48 +31,19 @@ class WooLoginEmailPasswordFragment : LoginEmailPasswordFragment() {
}
}

private var loginListener: LoginListener? = null
private var email: String? = null
private var isSocialLogin: Boolean = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

email = requireArguments().getString(ARG_EMAIL_ADDRESS)
isSocialLogin = requireArguments().getBoolean(ARG_SOCIAL_LOGIN)
}

override fun onAttach(context: Context) {
AndroidSupportInjection.inject(this)
super.onAttach(context)
loginListener = if (context is LoginListener) {
context
} else {
throw MissingComponentException("$context must implement LoginListener")
}
}

override fun onDetach() {
super.onDetach()
loginListener = null
}

@LayoutRes
override fun getContentLayout(): Int = R.layout.fragment_login_email_password

override fun setupContent(rootView: ViewGroup) {
super.setupContent(rootView)

// Replace the original magic link button with the new one in bottom section
val originalMagicLinkButton = rootView.findViewById<Button>(R.id.login_get_email_link)
rootView.findViewById<Button>(R.id.bottom_button_magic_link)?.apply {
isVisible = true // this button was intentionally hidden until the password screen is shown
setOnClickListener {
loginListener?.useMagicLinkInstead(email, false)
originalMagicLinkButton.performClick()
}
}

val prefilledPassword = requireArguments().getString(ARG_PASSWORD)
if (prefilledPassword.isNotNullOrEmpty()) {
rootView.findViewById<WPLoginInputRow>(R.id.login_password_row)
}
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ tinder-statemachine = '0.2.0'
wiremock = '2.26.3'
wordpress-aztec = 'v2.1.4'
wordpress-fluxc = 'trunk-0264533ce612f74e1ae6fcbaefeb69b252163774'
wordpress-login = '1.19.0'
wordpress-login = '156-98aa2c6174009b24253133b6733be119b70b7178'
wordpress-libaddressinput = '0.0.2'
wordpress-mediapicker = '0.3.1'
wordpress-utils = '3.15.0'
Expand Down
Loading