forked from github/wulkanowy-mirror
Add missing symbol and custom domain suffix validation (#2425)
This commit is contained in:
parent
b5e17c4ff7
commit
6f4a8d5534
@ -195,7 +195,7 @@ ext {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'io.github.wulkanowy:sdk:2.4.0'
|
||||
implementation 'io.github.wulkanowy:sdk:2.4.1-SNAPSHOT'
|
||||
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
|
||||
|
||||
|
@ -94,6 +94,7 @@ class LoginFormFragment : BaseFragment<FragmentLoginFormBinding>(R.layout.fragme
|
||||
loginFormUsername.doOnTextChanged { _, _, _, _ -> presenter.onUsernameTextChanged() }
|
||||
loginFormPass.doOnTextChanged { _, _, _, _ -> presenter.onPassTextChanged() }
|
||||
loginFormHost.setOnItemClickListener { _, _, _, _ -> presenter.onHostSelected() }
|
||||
loginFormDomainSuffix.doOnTextChanged { _, _, _, _ -> presenter.onDomainSuffixChanged() }
|
||||
loginFormSignIn.setOnClickListener { presenter.onSignInClick() }
|
||||
loginFormAdvancedButton.setOnClickListener { presenter.onAdvancedLoginClick() }
|
||||
loginFormPrivacyLink.setOnClickListener { presenter.onPrivacyLinkClick() }
|
||||
@ -188,6 +189,12 @@ class LoginFormFragment : BaseFragment<FragmentLoginFormBinding>(R.layout.fragme
|
||||
}
|
||||
}
|
||||
|
||||
override fun setDomainSuffixInvalid() {
|
||||
with(binding.loginFormDomainSuffixLayout) {
|
||||
error = getString(R.string.login_invalid_domain_suffix)
|
||||
}
|
||||
}
|
||||
|
||||
override fun clearUsernameError() {
|
||||
binding.loginFormUsernameLayout.error = null
|
||||
binding.loginFormErrorBox.isVisible = false
|
||||
@ -206,6 +213,10 @@ class LoginFormFragment : BaseFragment<FragmentLoginFormBinding>(R.layout.fragme
|
||||
binding.loginFormErrorBox.isVisible = false
|
||||
}
|
||||
|
||||
override fun clearDomainSuffixError() {
|
||||
binding.loginFormDomainSuffixLayout.error = null
|
||||
}
|
||||
|
||||
override fun showSoftKeyboard() {
|
||||
activity?.showSoftInput()
|
||||
}
|
||||
|
@ -101,6 +101,12 @@ class LoginFormPresenter @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun onDomainSuffixChanged() {
|
||||
view?.apply {
|
||||
clearDomainSuffixError()
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCustomDomainSuffixVisibility() {
|
||||
view?.run {
|
||||
showDomainSuffixInput("customSuffix" in formHostValue)
|
||||
@ -159,7 +165,7 @@ class LoginFormPresenter @Inject constructor(
|
||||
fun onSignInClick() {
|
||||
val loginData = getLoginData()
|
||||
|
||||
if (!validateCredentials(loginData.login, loginData.password, loginData.baseUrl)) return
|
||||
if (!validateCredentials(loginData)) return
|
||||
|
||||
resourceFlow {
|
||||
studentRepository.getUserSubjectsFromScrapper(
|
||||
@ -229,24 +235,29 @@ class LoginFormPresenter @Inject constructor(
|
||||
view?.onRecoverClick()
|
||||
}
|
||||
|
||||
private fun validateCredentials(login: String, password: String, host: String): Boolean {
|
||||
private fun validateCredentials(loginData: LoginData): Boolean {
|
||||
var isCorrect = true
|
||||
|
||||
if (login.isEmpty()) {
|
||||
if (loginData.login.isEmpty()) {
|
||||
view?.setErrorUsernameRequired()
|
||||
isCorrect = false
|
||||
} else {
|
||||
if ("@" in login && "login" in host) {
|
||||
if ("@" in loginData.login && "login" in loginData.baseUrl) {
|
||||
view?.setErrorLoginRequired()
|
||||
isCorrect = false
|
||||
}
|
||||
if ("@" !in login && "email" in host) {
|
||||
if ("@" !in loginData.login && "email" in loginData.baseUrl) {
|
||||
view?.setErrorEmailRequired()
|
||||
isCorrect = false
|
||||
}
|
||||
if ("@" in login && "||" !in login && "login" !in host && "email" !in host) {
|
||||
val emailHost = login.substringAfter("@")
|
||||
val emailDomain = URL(host).host
|
||||
|
||||
val isEmailLogin = "@" in loginData.login
|
||||
val isEmailWithLogin = "||" !in loginData.login
|
||||
val isLoginNotRequired = "login" !in loginData.baseUrl
|
||||
val isEmailNotRequired = "email" !in loginData.baseUrl
|
||||
if (isEmailLogin && isEmailWithLogin && isLoginNotRequired && isEmailNotRequired) {
|
||||
val emailHost = loginData.login.substringAfter("@")
|
||||
val emailDomain = URL(loginData.baseUrl).host
|
||||
if (!emailHost.equals(emailDomain, true)) {
|
||||
view?.setErrorEmailInvalid(domain = emailDomain)
|
||||
isCorrect = false
|
||||
@ -254,16 +265,21 @@ class LoginFormPresenter @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
if (password.isEmpty()) {
|
||||
if (loginData.password.isEmpty()) {
|
||||
view?.setErrorPassRequired(focus = isCorrect)
|
||||
isCorrect = false
|
||||
}
|
||||
|
||||
if (password.length < 6 && password.isNotEmpty()) {
|
||||
if (loginData.password.length < 6 && loginData.password.isNotEmpty()) {
|
||||
view?.setErrorPassInvalid(focus = isCorrect)
|
||||
isCorrect = false
|
||||
}
|
||||
|
||||
if (loginData.domainSuffix !in listOf("", "rc", "kurs")) {
|
||||
view?.setDomainSuffixInvalid()
|
||||
isCorrect = false
|
||||
}
|
||||
|
||||
return isCorrect
|
||||
}
|
||||
}
|
||||
|
@ -46,12 +46,16 @@ interface LoginFormView : BaseView {
|
||||
|
||||
fun setErrorEmailInvalid(domain: String)
|
||||
|
||||
fun setDomainSuffixInvalid()
|
||||
|
||||
fun clearUsernameError()
|
||||
|
||||
fun clearPassError()
|
||||
|
||||
fun clearHostError()
|
||||
|
||||
fun clearDomainSuffixError()
|
||||
|
||||
fun showSoftKeyboard()
|
||||
|
||||
fun hideSoftKeyboard()
|
||||
|
@ -96,10 +96,7 @@ class LoginSymbolPresenter @Inject constructor(
|
||||
?.takeIf { it.symbol == loginData.userEnteredSymbol }
|
||||
|
||||
if (enteredSymbolDetails?.error is InvalidSymbolException) {
|
||||
view?.run {
|
||||
setErrorSymbolInvalid()
|
||||
showContact(true)
|
||||
}
|
||||
showInvalidSymbolError()
|
||||
} else {
|
||||
Timber.i("Login with symbol result: Success")
|
||||
view?.navigateToStudentSelect(loginData, requireNotNull(user.data))
|
||||
@ -128,6 +125,9 @@ class LoginSymbolPresenter @Inject constructor(
|
||||
loginErrorHandler.dispatch(user.error)
|
||||
lastError = user.error
|
||||
view?.showContact(true)
|
||||
if (user.error is InvalidSymbolException) {
|
||||
showInvalidSymbolError()
|
||||
}
|
||||
}
|
||||
}
|
||||
}.onResourceNotLoading {
|
||||
@ -145,6 +145,13 @@ class LoginSymbolPresenter @Inject constructor(
|
||||
return normalizedSymbol in definitelyInvalidSymbols
|
||||
}
|
||||
|
||||
private fun showInvalidSymbolError() {
|
||||
view?.run {
|
||||
setErrorSymbolInvalid()
|
||||
showContact(true)
|
||||
}
|
||||
}
|
||||
|
||||
fun onFaqClick() {
|
||||
view?.openFaqPage()
|
||||
}
|
||||
|
@ -261,6 +261,7 @@
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_marginRight="24dp"
|
||||
android:hint="@string/login_domain_suffix_hint"
|
||||
app:errorEnabled="true"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/loginFormHostLayout"
|
||||
|
@ -61,6 +61,7 @@
|
||||
<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_custom_email">Use the assigned login or email in @%1$s</string>
|
||||
<string name="login_invalid_domain_suffix">Invalid domain suffix</string>
|
||||
<string name="login_invalid_symbol">Invalid symbol. If you cannot find it, please contact the school</string>
|
||||
<string name="login_invalid_symbol_definitely">Don\'t make this up! If you cannot find it, please contact the school</string>
|
||||
<string name="login_incorrect_symbol">Student not found. Validate the symbol and the chosen variation of the UONET+ register</string>
|
||||
|
Loading…
Reference in New Issue
Block a user