forked from github/wulkanowy-mirror
parent
76039e5eb9
commit
06a27199ee
@ -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() {
|
override fun clearUsernameError() {
|
||||||
binding.loginFormUsernameLayout.error = null
|
binding.loginFormUsernameLayout.error = null
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import io.github.wulkanowy.utils.flowWithResource
|
|||||||
import io.github.wulkanowy.utils.ifNullOrBlank
|
import io.github.wulkanowy.utils.ifNullOrBlank
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import java.net.URL
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class LoginFormPresenter @Inject constructor(
|
class LoginFormPresenter @Inject constructor(
|
||||||
@ -87,7 +88,14 @@ class LoginFormPresenter @Inject constructor(
|
|||||||
|
|
||||||
if (!validateCredentials(email, password, host)) return
|
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) {
|
when (it.status) {
|
||||||
Status.LOADING -> view?.run {
|
Status.LOADING -> view?.run {
|
||||||
Timber.i("Login started")
|
Timber.i("Login started")
|
||||||
@ -150,11 +158,18 @@ class LoginFormPresenter @Inject constructor(
|
|||||||
view?.setErrorLoginRequired()
|
view?.setErrorLoginRequired()
|
||||||
isCorrect = false
|
isCorrect = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("@" !in login && "email" in host) {
|
if ("@" !in login && "email" in host) {
|
||||||
view?.setErrorEmailRequired()
|
view?.setErrorEmailRequired()
|
||||||
isCorrect = false
|
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()) {
|
if (password.isEmpty()) {
|
||||||
|
@ -39,6 +39,8 @@ interface LoginFormView : BaseView {
|
|||||||
|
|
||||||
fun setErrorPassIncorrect()
|
fun setErrorPassIncorrect()
|
||||||
|
|
||||||
|
fun setErrorEmailInvalid(domain: String)
|
||||||
|
|
||||||
fun clearUsernameError()
|
fun clearUsernameError()
|
||||||
|
|
||||||
fun clearPassError()
|
fun clearPassError()
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
<string name="login_expired_token">Token expired</string>
|
<string name="login_expired_token">Token expired</string>
|
||||||
<string name="login_invalid_email">Invalid email</string>
|
<string name="login_invalid_email">Invalid email</string>
|
||||||
<string name="login_invalid_login">Use the assigned login instead of email</string>
|
<string name="login_invalid_login">Use the assigned login instead of email</string>
|
||||||
|
<string name="login_invalid_custom_email">Use the assigned login or email in @%1$s</string>
|
||||||
<string name="login_invalid_symbol">Invalid symbol</string>
|
<string name="login_invalid_symbol">Invalid symbol</string>
|
||||||
<string name="login_incorrect_symbol">Student not found. Validate the symbol and the chosen variation of the UONET+ register</string>
|
<string name="login_incorrect_symbol">Student not found. Validate the symbol and the chosen variation of the UONET+ register</string>
|
||||||
<string name="login_field_required">This field is required</string>
|
<string name="login_field_required">This field is required</string>
|
||||||
|
@ -65,7 +65,7 @@ class LoginFormPresenterTest {
|
|||||||
fun emptyNicknameLoginTest() {
|
fun emptyNicknameLoginTest() {
|
||||||
every { loginFormView.formUsernameValue } returns ""
|
every { loginFormView.formUsernameValue } returns ""
|
||||||
every { loginFormView.formPassValue } returns "test123"
|
every { loginFormView.formPassValue } returns "test123"
|
||||||
every { loginFormView.formHostValue } returns "https://fakelog.cf/?standard"
|
every { loginFormView.formHostValue } returns "https://fakelog.cf/?email"
|
||||||
presenter.onSignInClick()
|
presenter.onSignInClick()
|
||||||
|
|
||||||
verify { loginFormView.setErrorUsernameRequired() }
|
verify { loginFormView.setErrorUsernameRequired() }
|
||||||
@ -73,11 +73,21 @@ class LoginFormPresenterTest {
|
|||||||
verify(exactly = 0) { loginFormView.setErrorPassInvalid(false) }
|
verify(exactly = 0) { loginFormView.setErrorPassInvalid(false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun invalidEmailLoginTest() {
|
||||||
|
every { loginFormView.formUsernameValue } returns "@"
|
||||||
|
every { loginFormView.formPassValue } returns "123456"
|
||||||
|
every { loginFormView.formHostValue } returns "https://fakelog.cf/"
|
||||||
|
presenter.onSignInClick()
|
||||||
|
|
||||||
|
verify { loginFormView.setErrorEmailInvalid("fakelog.cf") }
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun emptyPassLoginTest() {
|
fun emptyPassLoginTest() {
|
||||||
every { loginFormView.formUsernameValue } returns "@"
|
every { loginFormView.formUsernameValue } returns "@"
|
||||||
every { loginFormView.formPassValue } returns ""
|
every { loginFormView.formPassValue } returns ""
|
||||||
every { loginFormView.formHostValue } returns "https://fakelog.cf/?standard"
|
every { loginFormView.formHostValue } returns "https://fakelog.cf/?email"
|
||||||
presenter.onSignInClick()
|
presenter.onSignInClick()
|
||||||
|
|
||||||
verify(exactly = 0) { loginFormView.setErrorUsernameRequired() }
|
verify(exactly = 0) { loginFormView.setErrorUsernameRequired() }
|
||||||
@ -89,7 +99,7 @@ class LoginFormPresenterTest {
|
|||||||
fun invalidPassLoginTest() {
|
fun invalidPassLoginTest() {
|
||||||
every { loginFormView.formUsernameValue } returns "@"
|
every { loginFormView.formUsernameValue } returns "@"
|
||||||
every { loginFormView.formPassValue } returns "123"
|
every { loginFormView.formPassValue } returns "123"
|
||||||
every { loginFormView.formHostValue } returns "https://fakelog.cf/?standard"
|
every { loginFormView.formHostValue } returns "https://fakelog.cf/?email"
|
||||||
presenter.onSignInClick()
|
presenter.onSignInClick()
|
||||||
|
|
||||||
verify(exactly = 0) { loginFormView.setErrorUsernameRequired() }
|
verify(exactly = 0) { loginFormView.setErrorUsernameRequired() }
|
||||||
@ -102,7 +112,7 @@ class LoginFormPresenterTest {
|
|||||||
val studentTest = Student(
|
val studentTest = Student(
|
||||||
email = "test@",
|
email = "test@",
|
||||||
password = "123",
|
password = "123",
|
||||||
scrapperBaseUrl = "https://fakelog.cf/",
|
scrapperBaseUrl = "https://fakelog.cf/?email",
|
||||||
loginType = "AUTO",
|
loginType = "AUTO",
|
||||||
studentName = "",
|
studentName = "",
|
||||||
schoolSymbol = "",
|
schoolSymbol = "",
|
||||||
@ -128,7 +138,7 @@ class LoginFormPresenterTest {
|
|||||||
|
|
||||||
every { loginFormView.formUsernameValue } returns "@"
|
every { loginFormView.formUsernameValue } returns "@"
|
||||||
every { loginFormView.formPassValue } returns "123456"
|
every { loginFormView.formPassValue } returns "123456"
|
||||||
every { loginFormView.formHostValue } returns "https://fakelog.cf/?standard"
|
every { loginFormView.formHostValue } returns "https://fakelog.cf/?email"
|
||||||
every { loginFormView.formHostSymbol } returns "Default"
|
every { loginFormView.formHostSymbol } returns "Default"
|
||||||
presenter.onSignInClick()
|
presenter.onSignInClick()
|
||||||
|
|
||||||
@ -144,7 +154,7 @@ class LoginFormPresenterTest {
|
|||||||
coEvery { repository.getStudentsScrapper(any(), any(), any(), any()) } returns listOf()
|
coEvery { repository.getStudentsScrapper(any(), any(), any(), any()) } returns listOf()
|
||||||
every { loginFormView.formUsernameValue } returns "@"
|
every { loginFormView.formUsernameValue } returns "@"
|
||||||
every { loginFormView.formPassValue } returns "123456"
|
every { loginFormView.formPassValue } returns "123456"
|
||||||
every { loginFormView.formHostValue } returns "https://fakelog.cf/?standard"
|
every { loginFormView.formHostValue } returns "https://fakelog.cf/?email"
|
||||||
every { loginFormView.formHostSymbol } returns "Default"
|
every { loginFormView.formHostSymbol } returns "Default"
|
||||||
presenter.onSignInClick()
|
presenter.onSignInClick()
|
||||||
|
|
||||||
@ -160,7 +170,7 @@ class LoginFormPresenterTest {
|
|||||||
coEvery { repository.getStudentsScrapper(any(), any(), any(), any()) } returns listOf()
|
coEvery { repository.getStudentsScrapper(any(), any(), any(), any()) } returns listOf()
|
||||||
every { loginFormView.formUsernameValue } returns "@"
|
every { loginFormView.formUsernameValue } returns "@"
|
||||||
every { loginFormView.formPassValue } returns "123456"
|
every { loginFormView.formPassValue } returns "123456"
|
||||||
every { loginFormView.formHostValue } returns "https://fakelog.cf/?standard"
|
every { loginFormView.formHostValue } returns "https://fakelog.cf/?email"
|
||||||
every { loginFormView.formHostSymbol } returns "Default"
|
every { loginFormView.formHostSymbol } returns "Default"
|
||||||
presenter.onSignInClick()
|
presenter.onSignInClick()
|
||||||
presenter.onSignInClick()
|
presenter.onSignInClick()
|
||||||
@ -178,7 +188,7 @@ class LoginFormPresenterTest {
|
|||||||
coEvery { repository.getStudentsScrapper(any(), any(), any(), any()) } throws testException
|
coEvery { repository.getStudentsScrapper(any(), any(), any(), any()) } throws testException
|
||||||
every { loginFormView.formUsernameValue } returns "@"
|
every { loginFormView.formUsernameValue } returns "@"
|
||||||
every { loginFormView.formPassValue } returns "123456"
|
every { loginFormView.formPassValue } returns "123456"
|
||||||
every { loginFormView.formHostValue } returns "https://fakelog.cf/?standard"
|
every { loginFormView.formHostValue } returns "https://fakelog.cf/?email"
|
||||||
every { loginFormView.formHostSymbol } returns "Default"
|
every { loginFormView.formHostSymbol } returns "Default"
|
||||||
every { loginFormView.showProgress(any()) } just Runs
|
every { loginFormView.showProgress(any()) } just Runs
|
||||||
every { loginFormView.showProgress(any()) } just Runs
|
every { loginFormView.showProgress(any()) } just Runs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user