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