Add early validation for special mail domains (#1000) (#1176)

This commit is contained in:
Kamil Studziński
2021-03-03 22:37:58 +01:00
committed by GitHub
parent 76039e5eb9
commit 06a27199ee
5 changed files with 45 additions and 10 deletions

View File

@ -150,6 +150,13 @@ class LoginFormFragment : BaseFragment<FragmentLoginFormBinding>(R.layout.fragme
}
}
override fun setErrorEmailInvalid(domain: String) {
with(binding.loginFormUsernameLayout) {
requestFocus()
error = getString(R.string.login_invalid_custom_email,domain)
}
}
override fun clearUsernameError() {
binding.loginFormUsernameLayout.error = null
}

View File

@ -11,6 +11,7 @@ import io.github.wulkanowy.utils.flowWithResource
import io.github.wulkanowy.utils.ifNullOrBlank
import kotlinx.coroutines.flow.onEach
import timber.log.Timber
import java.net.URL
import javax.inject.Inject
class LoginFormPresenter @Inject constructor(
@ -87,7 +88,14 @@ class LoginFormPresenter @Inject constructor(
if (!validateCredentials(email, password, host)) return
flowWithResource { studentRepository.getStudentsScrapper(email, password, host, symbol) }.onEach {
flowWithResource {
studentRepository.getStudentsScrapper(
email,
password,
host,
symbol
)
}.onEach {
when (it.status) {
Status.LOADING -> view?.run {
Timber.i("Login started")
@ -150,11 +158,18 @@ class LoginFormPresenter @Inject constructor(
view?.setErrorLoginRequired()
isCorrect = false
}
if ("@" !in login && "email" in host) {
view?.setErrorEmailRequired()
isCorrect = false
}
if ("@" in login && "login" !in host && "email" !in host) {
val emailHost = login.substringAfter("@")
val emailDomain = URL(host).host
if (emailHost != emailDomain) {
view?.setErrorEmailInvalid(domain = emailDomain)
isCorrect = false
}
}
}
if (password.isEmpty()) {

View File

@ -39,6 +39,8 @@ interface LoginFormView : BaseView {
fun setErrorPassIncorrect()
fun setErrorEmailInvalid(domain: String)
fun clearUsernameError()
fun clearPassError()