Commit e63200ef authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Add TODO and validate inputs.

parent 9f2c01e8
package chat.rocket.android.authentication.signup.presentation package chat.rocket.android.authentication.signup.presentation
import android.widget.EditText
import chat.rocket.android.authentication.infraestructure.AuthTokenRepository import chat.rocket.android.authentication.infraestructure.AuthTokenRepository
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.util.launchUI import chat.rocket.android.util.launchUI
import chat.rocket.android.util.textContent
import chat.rocket.common.RocketChatException import chat.rocket.common.RocketChatException
import chat.rocket.common.util.PlatformLogger import chat.rocket.common.util.PlatformLogger
import chat.rocket.core.RocketChatClient import chat.rocket.core.RocketChatClient
...@@ -20,7 +22,7 @@ class SignupPresenter @Inject constructor(private val view: SignupView, ...@@ -20,7 +22,7 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
private val okHttpClient: OkHttpClient, private val okHttpClient: OkHttpClient,
private val logger: PlatformLogger, private val logger: PlatformLogger,
private val repository: AuthTokenRepository) { private val repository: AuthTokenRepository) {
// TODO: Create a single entry point to RocketChatClient
val client: RocketChatClient = RocketChatClient.create { val client: RocketChatClient = RocketChatClient.create {
httpClient = okHttpClient httpClient = okHttpClient
restUrl = HttpUrl.parse(navigator.currentServer)!! restUrl = HttpUrl.parse(navigator.currentServer)!!
...@@ -29,10 +31,18 @@ class SignupPresenter @Inject constructor(private val view: SignupView, ...@@ -29,10 +31,18 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
platformLogger = logger platformLogger = logger
} }
fun signup(email: String, name: String, username: String, password: String) { fun signup(nameEditText: EditText, emailEditText: EditText, usernameEditText: EditText, passwordEditText: EditText) {
// TODO - validate input val name = nameEditText.textContent
val email = emailEditText.textContent
val username = usernameEditText.textContent
val password = passwordEditText.textContent
launchUI(strategy) { when {
name.isBlank() -> view.shakeView(nameEditText)
email.isBlank() -> view.shakeView(emailEditText)
username.isBlank() -> view.shakeView(usernameEditText)
password.isEmpty() -> view.shakeView(passwordEditText)
else -> launchUI(strategy) {
view.showLoading() view.showLoading()
try { try {
...@@ -44,10 +54,14 @@ class SignupPresenter @Inject constructor(private val view: SignupView, ...@@ -44,10 +54,14 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
navigator.toChatList() navigator.toChatList()
} catch (ex: RocketChatException) { } catch (ex: RocketChatException) {
view.onSignupError(ex.message) val errorMessage = ex.message
if (errorMessage != null) {
view.showMessage(errorMessage)
}
} finally { } finally {
view.hideLoading() view.hideLoading()
} }
} }
} }
}
} }
\ No newline at end of file
package chat.rocket.android.authentication.twofactor.presentation package chat.rocket.android.authentication.twofactor.presentation
import android.widget.EditText
import chat.rocket.android.authentication.infraestructure.AuthTokenRepository import chat.rocket.android.authentication.infraestructure.AuthTokenRepository
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.util.launchUI import chat.rocket.android.util.launchUI
import chat.rocket.android.util.textContent
import chat.rocket.common.RocketChatException import chat.rocket.common.RocketChatException
import chat.rocket.common.util.PlatformLogger import chat.rocket.common.util.PlatformLogger
import chat.rocket.core.RocketChatClient import chat.rocket.core.RocketChatClient
...@@ -18,7 +20,7 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView, ...@@ -18,7 +20,7 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
private val okHttpClient: OkHttpClient, private val okHttpClient: OkHttpClient,
private val logger: PlatformLogger, private val logger: PlatformLogger,
private val repository: AuthTokenRepository) { private val repository: AuthTokenRepository) {
// TODO: Create a single entry point to RocketChatClient
val client: RocketChatClient = RocketChatClient.create { val client: RocketChatClient = RocketChatClient.create {
httpClient = okHttpClient httpClient = okHttpClient
restUrl = HttpUrl.parse(navigator.currentServer)!! restUrl = HttpUrl.parse(navigator.currentServer)!!
...@@ -27,14 +29,17 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView, ...@@ -27,14 +29,17 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
platformLogger = logger platformLogger = logger
} }
fun authenticate(username: String, password: String, pin: String) { // TODO: If the usernameOrEmail and password was informed by the user on the previous screen, then we should pass only the pin, like this: fun authenticate(pin: EditText)
// TODO - validate input fun authenticate(usernameOrEmail: String, password: String, pin: EditText) {
val twoFACode = pin.textContent
if (twoFACode.isBlank()) {
view.shakeView(pin)
} else {
launchUI(strategy) { launchUI(strategy) {
view.showLoading() view.showLoading()
try { try {
val token = client.login(username, password, pin) val token = client.login(usernameOrEmail, password, twoFACode)
// Todo Salve token.
navigator.toChatList() navigator.toChatList()
} catch (ex: RocketChatException) { } catch (ex: RocketChatException) {
val errorMessage = ex.message val errorMessage = ex.message
...@@ -46,6 +51,7 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView, ...@@ -46,6 +51,7 @@ class TwoFAPresenter @Inject constructor(private val view: TwoFAView,
} }
} }
} }
}
fun signup() { fun signup() {
navigator.toSignUp(navigator.currentServer!!) navigator.toSignUp(navigator.currentServer!!)
......
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