For issue#10727 - Logins auth redirect
Added an extension function that pops the backstack of the fragment so the user is redirected to the Logins and passwords screen. This is done to force the user to re-authenticate if he wants to re-enter the saved logins flow. Additionally, some UI elements are being hidden on each Fragment since they were remained visible on the Logins and passwords screen's UI.master
parent
58a42828a1
commit
11df3aaca1
|
@ -12,7 +12,9 @@ import androidx.navigation.NavDirections
|
|||
import androidx.navigation.NavOptions
|
||||
import androidx.navigation.Navigator
|
||||
import androidx.navigation.fragment.NavHostFragment.findNavController
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.Components
|
||||
|
||||
/**
|
||||
|
@ -51,3 +53,18 @@ fun Fragment.showToolbar(title: String) {
|
|||
fun Fragment.hideToolbar() {
|
||||
(requireActivity() as AppCompatActivity).supportActionBar?.hide()
|
||||
}
|
||||
|
||||
/**
|
||||
* Pops the backstack to force users to re-auth if they put the app in the background and return to it
|
||||
* while being inside the saved logins flow
|
||||
* It also updates the FLAG_SECURE status for the activity's window
|
||||
*
|
||||
* Does nothing if the user is currently navigating to any of the [destinations] given as a parameter
|
||||
*
|
||||
*/
|
||||
fun Fragment.redirectToReAuth(destinations: List<Int>, currentDestination: Int?) {
|
||||
if (currentDestination !in destinations) {
|
||||
activity?.let { it.checkAndUpdateScreenshotPermission(it.settings()) }
|
||||
findNavController().popBackStack(R.id.savedLoginsAuthFragment, false)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.mozilla.fenix.components.FenixSnackbar
|
|||
import org.mozilla.fenix.components.StoreProvider
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.redirectToReAuth
|
||||
import org.mozilla.fenix.ext.settings
|
||||
|
||||
/**
|
||||
|
@ -114,6 +115,14 @@ class EditLoginFragment : Fragment(R.layout.fragment_edit_login) {
|
|||
inflater.inflate(R.menu.login_save, menu)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
redirectToReAuth(
|
||||
listOf(R.id.loginDetailFragment),
|
||||
findNavController().currentDestination?.id
|
||||
)
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
||||
R.id.save_login_button -> {
|
||||
view?.hideKeyboard()
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.mozilla.fenix.components.FenixSnackbar
|
|||
import org.mozilla.fenix.components.StoreProvider
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.redirectToReAuth
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.ext.showToolbar
|
||||
import org.mozilla.fenix.ext.urlToTrimmedHost
|
||||
|
@ -53,6 +54,8 @@ class LoginDetailFragment : Fragment(R.layout.fragment_login_detail) {
|
|||
private var login: SavedLogin? = null
|
||||
private lateinit var savedLoginsStore: LoginsFragmentStore
|
||||
private lateinit var loginDetailView: LoginDetailView
|
||||
private lateinit var menu: Menu
|
||||
private var deleteDialog: AlertDialog? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
|
@ -98,6 +101,21 @@ class LoginDetailFragment : Fragment(R.layout.fragment_login_detail) {
|
|||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
||||
/**
|
||||
* As described in #10727, the User should re-auth if the fragment is paused and the user is not
|
||||
* navigating to SavedLoginsFragment or EditLoginFragment
|
||||
*
|
||||
*/
|
||||
override fun onPause() {
|
||||
deleteDialog?.isShowing.run { deleteDialog?.dismiss() }
|
||||
menu.close()
|
||||
redirectToReAuth(
|
||||
listOf(R.id.editLoginFragment, R.id.savedLoginsFragment),
|
||||
findNavController().currentDestination?.id
|
||||
)
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
private fun setUpPasswordReveal() {
|
||||
passwordText.inputType =
|
||||
InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
|
@ -156,6 +174,7 @@ class LoginDetailFragment : Fragment(R.layout.fragment_login_detail) {
|
|||
} else {
|
||||
inflater.inflate(R.menu.login_delete, menu)
|
||||
}
|
||||
this.menu = menu
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) {
|
||||
|
@ -179,7 +198,7 @@ class LoginDetailFragment : Fragment(R.layout.fragment_login_detail) {
|
|||
|
||||
private fun displayDeleteLoginDialog() {
|
||||
activity?.let { activity ->
|
||||
AlertDialog.Builder(activity).apply {
|
||||
deleteDialog = AlertDialog.Builder(activity).apply {
|
||||
setMessage(R.string.login_deletion_confirmation)
|
||||
setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _ ->
|
||||
dialog.cancel()
|
||||
|
|
|
@ -38,8 +38,8 @@ import org.mozilla.fenix.HomeActivity
|
|||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.components.StoreProvider
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.ext.checkAndUpdateScreenshotPermission
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.redirectToReAuth
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.ext.showToolbar
|
||||
import org.mozilla.fenix.settings.SupportUtils
|
||||
|
@ -134,10 +134,7 @@ class SavedLoginsFragment : Fragment() {
|
|||
(activity as HomeActivity).getSupportActionBarAndInflateIfNecessary().setDisplayShowTitleEnabled(true)
|
||||
sortingStrategyPopupMenu.dismiss()
|
||||
|
||||
if (findNavController().currentDestination?.id != R.id.loginDetailFragment) {
|
||||
activity?.let { it.checkAndUpdateScreenshotPermission(it.settings()) }
|
||||
findNavController().popBackStack(R.id.savedLoginsAuthFragment, false)
|
||||
}
|
||||
redirectToReAuth(listOf(R.id.loginDetailFragment), findNavController().currentDestination?.id)
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue