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
import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.helper.NetworkHelper
import chat.rocket.android.util.launchUI
import chat.rocket.common.RocketChatAuthException
import chat.rocket.common.RocketChatException
import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.rest.login
import timber.log.Timber
import javax.inject.Inject
class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
......@@ -20,19 +21,26 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
view.alertBlankTwoFactorAuthenticationCode()
} else {
launchUI(strategy) {
view.showLoading()
try {
val token = client.login(usernameOrEmail, password, twoFactorAuthenticationCode)
Timber.d("Created token: $token")
// Todo Salve token?.
navigator.toChatList()
} catch (ex: RocketChatException) {
val errorMessage = ex.message
if (errorMessage != null) {
view.showMessage(errorMessage)
if (NetworkHelper.hasInternetAccess()) {
view.showLoading()
try {
val token = client.login(usernameOrEmail, password, twoFactorAuthenticationCode)
// TODO Salve token?
navigator.toChatList()
} catch (rocketChatException: RocketChatException) {
if (rocketChatException is RocketChatAuthException) {
view.alertInvalidTwoFactorAuthenticationCode()
} else {
val errorMessage = rocketChatException.message
if (errorMessage != null) {
view.showMessage(errorMessage)
}
}
} finally {
view.hideLoading()
}
} finally {
view.hideLoading()
} else {
view.showNoInternetConnection()
}
}
}
......
......@@ -7,7 +7,12 @@ import chat.rocket.android.core.behaviours.MessageView
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()
/**
* 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 {
AnimationHelper.shakeView(text_two_factor_auth)
}
override fun alertInvalidTwoFactorAuthenticationCode() {
showMessage(getString(R.string.msg_invalid_2fa_code))
}
override fun showLoading() {
view_loading.setVisibility(true)
enableUserInput(false)
view_loading.show()
}
override fun hideLoading() {
view_loading.setVisibility(false)
view_loading.hide()
enableUserInput(true)
}
override fun showMessage(message: String) {
......@@ -85,7 +92,7 @@ class TwoFAFragment : Fragment(), TwoFAView {
}
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() {
......@@ -97,4 +104,9 @@ class TwoFAFragment : Fragment(), TwoFAView {
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 @@
<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_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_message">Messagem</string>
<string name="msg_content_description_log_in_using_facebook">Fazer login através do Facebook</string>
......
......@@ -24,6 +24,7 @@
<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_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_yesterday">Yesterday</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