Commit 6c49a9fb authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Add strings to alert the user about an invalid TwoFA code.

parent 30cf2a14
...@@ -2,11 +2,12 @@ package chat.rocket.android.authentication.twofactor.presentation ...@@ -2,11 +2,12 @@ package chat.rocket.android.authentication.twofactor.presentation
import chat.rocket.android.authentication.presentation.AuthenticationNavigator import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.helper.NetworkHelper
import chat.rocket.android.util.launchUI import chat.rocket.android.util.launchUI
import chat.rocket.common.RocketChatAuthException
import chat.rocket.common.RocketChatException import chat.rocket.common.RocketChatException
import chat.rocket.core.RocketChatClient import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.rest.login import chat.rocket.core.internal.rest.login
import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class TwoFAPresenter @Inject constructor(private val view: TwoFAView, class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
...@@ -20,19 +21,26 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView, ...@@ -20,19 +21,26 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
view.alertBlankTwoFactorAuthenticationCode() view.alertBlankTwoFactorAuthenticationCode()
} else { } else {
launchUI(strategy) { launchUI(strategy) {
view.showLoading() if (NetworkHelper.hasInternetAccess()) {
try { view.showLoading()
val token = client.login(usernameOrEmail, password, twoFactorAuthenticationCode) try {
Timber.d("Created token: $token") val token = client.login(usernameOrEmail, password, twoFactorAuthenticationCode)
// Todo Salve token?. // TODO Salve token?
navigator.toChatList() navigator.toChatList()
} catch (ex: RocketChatException) { } catch (rocketChatException: RocketChatException) {
val errorMessage = ex.message if (rocketChatException is RocketChatAuthException) {
if (errorMessage != null) { view.alertInvalidTwoFactorAuthenticationCode()
view.showMessage(errorMessage) } else {
val errorMessage = rocketChatException.message
if (errorMessage != null) {
view.showMessage(errorMessage)
}
}
} finally {
view.hideLoading()
} }
} finally { } else {
view.hideLoading() view.showNoInternetConnection()
} }
} }
} }
......
...@@ -7,7 +7,12 @@ import chat.rocket.android.core.behaviours.MessageView ...@@ -7,7 +7,12 @@ import chat.rocket.android.core.behaviours.MessageView
interface TwoFAView : LoadingView, MessageView, InternetView { interface TwoFAView : LoadingView, MessageView, InternetView {
/** /**
* Alerts the user about a blank two factor authentication code. * Alerts the user about a blank Two Factor Authentication code.
*/ */
fun alertBlankTwoFactorAuthenticationCode() fun alertBlankTwoFactorAuthenticationCode()
/**
* Alerts the user about an invalid inputted Two Factor Authentication code.
*/
fun alertInvalidTwoFactorAuthenticationCode()
} }
\ No newline at end of file
...@@ -72,12 +72,19 @@ class TwoFAFragment : Fragment(), TwoFAView { ...@@ -72,12 +72,19 @@ class TwoFAFragment : Fragment(), TwoFAView {
AnimationHelper.shakeView(text_two_factor_auth) AnimationHelper.shakeView(text_two_factor_auth)
} }
override fun alertInvalidTwoFactorAuthenticationCode() {
showMessage(getString(R.string.msg_invalid_2fa_code))
}
override fun showLoading() { override fun showLoading() {
view_loading.setVisibility(true) view_loading.setVisibility(true)
enableUserInput(false)
view_loading.show()
} }
override fun hideLoading() { override fun hideLoading() {
view_loading.setVisibility(false) view_loading.hide()
enableUserInput(true)
} }
override fun showMessage(message: String) { override fun showMessage(message: String) {
...@@ -85,7 +92,7 @@ class TwoFAFragment : Fragment(), TwoFAView { ...@@ -85,7 +92,7 @@ class TwoFAFragment : Fragment(), TwoFAView {
} }
override fun showNoInternetConnection() { override fun showNoInternetConnection() {
Toast.makeText(activity, getString(R.string.msg_no_internet_connection), Toast.LENGTH_SHORT).show() showMessage(getString(R.string.msg_no_internet_connection))
} }
private fun tintEditTextDrawableStart() { private fun tintEditTextDrawableStart() {
...@@ -97,4 +104,9 @@ class TwoFAFragment : Fragment(), TwoFAView { ...@@ -97,4 +104,9 @@ class TwoFAFragment : Fragment(), TwoFAView {
DrawableHelper.compoundDrawable(text_two_factor_auth, lockDrawable) DrawableHelper.compoundDrawable(text_two_factor_auth, lockDrawable)
} }
} }
private fun enableUserInput(value: Boolean) {
button_log_in.isEnabled = value
text_two_factor_auth.isEnabled = value
}
} }
\ No newline at end of file
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<string name="msg_new_to_rocket_chat">Novo no Rocket Chat? %1$s</string> <string name="msg_new_to_rocket_chat">Novo no Rocket Chat? %1$s</string>
<string name="msg_new_user_agreement">Ao proceder você concorda com nossos %1$s e %2$s</string> <string name="msg_new_user_agreement">Ao proceder você concorda com nossos %1$s e %2$s</string>
<string name="msg_2fa_code">Código 2FA</string> <string name="msg_2fa_code">Código 2FA</string>
<string name="msg_invalid_2fa_code">Código 2FA inválido</string>
<string name="msg_yesterday">ontem</string> <string name="msg_yesterday">ontem</string>
<string name="msg_message">Messagem</string> <string name="msg_message">Messagem</string>
<string name="msg_content_description_log_in_using_facebook">Fazer login através do Facebook</string> <string name="msg_content_description_log_in_using_facebook">Fazer login através do Facebook</string>
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
<string name="msg_new_to_rocket_chat">New to Rocket Chat? %1$s</string> <string name="msg_new_to_rocket_chat">New to Rocket Chat? %1$s</string>
<string name="msg_new_user_agreement">By proceeding you are agreeing to our\n%1$s and %2$s</string> <string name="msg_new_user_agreement">By proceeding you are agreeing to our\n%1$s and %2$s</string>
<string name="msg_2fa_code">2FA Code</string> <string name="msg_2fa_code">2FA Code</string>
<string name="msg_invalid_2fa_code">Invalid 2FA Code</string>
<string name="msg_more_than_ninety_nine_unread_messages" translatable="false">99+</string> <string name="msg_more_than_ninety_nine_unread_messages" translatable="false">99+</string>
<string name="msg_yesterday">Yesterday</string> <string name="msg_yesterday">Yesterday</string>
<string name="msg_message">Message</string> <string name="msg_message">Message</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment