1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-09-19 22:49:08 -05:00

Show all known adfslight registers in register list (#766)

This commit is contained in:
Mikołaj Pich 2020-04-12 18:55:16 +02:00 committed by GitHub
parent 64a19d9627
commit 3ac085573f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 397 additions and 195 deletions

View File

@ -7,7 +7,6 @@ import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.ViewGroup
import android.widget.ArrayAdapter
import androidx.core.widget.doOnTextChanged
import io.github.wulkanowy.R
import io.github.wulkanowy.data.db.entities.Student
@ -46,9 +45,6 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
override val formHostSymbol: String
get() = hostSymbols.getOrNull(hostKeys.indexOf(loginFormHost.text.toString())).orEmpty()
override val formSymbolValue: String
get() = loginFormSymbol.text.toString()
override val nicknameLabel: String
get() = getString(R.string.login_nickname_hint)
@ -77,7 +73,6 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
loginFormUsername.doOnTextChanged { _, _, _, _ -> presenter.onUsernameTextChanged() }
loginFormPass.doOnTextChanged { _, _, _, _ -> presenter.onPassTextChanged() }
loginFormSymbol.doOnTextChanged { _, _, _, _ -> presenter.onSymbolTextChanged() }
loginFormHost.setOnItemClickListener { _, _, _, _ -> presenter.onHostSelected() }
loginFormSignIn.setOnClickListener { presenter.onSignInClick() }
loginFormAdvancedButton.setOnClickListener { presenter.onAdvancedLoginClick() }
@ -86,9 +81,6 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
loginFormContactEmail.setOnClickListener { presenter.onEmailClick() }
loginFormRecoverLink.setOnClickListener { presenter.onRecoverClick() }
loginFormPass.setOnEditorDoneSignIn { loginFormSignIn.callOnClick() }
loginFormSymbol.setOnEditorDoneSignIn { loginFormSignIn.callOnClick() }
loginFormSymbol.setAdapter(ArrayAdapter(requireContext(), android.R.layout.simple_list_item_1, resources.getStringArray(R.array.symbols_values)))
with(loginFormHost) {
setText(hostKeys.getOrNull(0).orEmpty())
@ -102,18 +94,10 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
loginFormPass.setText(pass)
}
override fun setSymbol(symbol: String) {
loginFormSymbol.setText(symbol)
}
override fun setUsernameLabel(label: String) {
loginFormUsernameLayout.hint = label
}
override fun showSymbol(show: Boolean) {
loginFormSymbolLayout.visibility = if (show) VISIBLE else GONE
}
override fun setErrorUsernameRequired() {
with(loginFormUsernameLayout) {
requestFocus()
@ -135,13 +119,6 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
}
}
override fun setErrorSymbolRequired(focus: Boolean) {
with(loginFormSymbolLayout) {
if (focus) requestFocus()
error = getString(R.string.login_symbol_helper)
}
}
override fun setErrorPassRequired(focus: Boolean) {
with(loginFormPassLayout) {
if (focus) requestFocus()
@ -171,10 +148,6 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
loginFormPassLayout.error = null
}
override fun clearSymbolError() {
loginFormSymbolLayout.error = null
}
override fun showSoftKeyboard() {
activity?.showSoftInput()
}
@ -227,10 +200,7 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
override fun onResume() {
super.onResume()
with(presenter) {
updateUsernameLabel()
updateSymbolInputVisibility()
}
presenter.updateUsernameLabel()
}
override fun openEmail(lastError: String) {
@ -242,7 +212,7 @@ class LoginFormFragment : BaseFragment(), LoginFormView {
"${appInfo.systemManufacturer} ${appInfo.systemModel}",
appInfo.systemVersion.toString(),
appInfo.versionName,
"$formHostValue/$formSymbolValue",
"$formHostValue/$formHostSymbol",
lastError
)
)

View File

@ -48,9 +48,7 @@ class LoginFormPresenter @Inject constructor(
if (formHostValue.contains("fakelog")) {
setCredentials("jan@fakelog.cf", "jan123")
}
setSymbol(formHostSymbol)
updateUsernameLabel()
updateSymbolInputVisibility()
}
}
@ -60,12 +58,6 @@ class LoginFormPresenter @Inject constructor(
}
}
fun updateSymbolInputVisibility() {
view?.run {
showSymbol("adfs" in formHostValue)
}
}
fun onPassTextChanged() {
view?.clearPassError()
}
@ -74,17 +66,13 @@ class LoginFormPresenter @Inject constructor(
view?.clearUsernameError()
}
fun onSymbolTextChanged() {
view?.clearSymbolError()
}
fun onSignInClick() {
val email = view?.formUsernameValue.orEmpty().trim()
val password = view?.formPassValue.orEmpty().trim()
val host = view?.formHostValue.orEmpty().trim()
val symbol = view?.formSymbolValue.orEmpty().trim()
val symbol = view?.formHostSymbol.orEmpty().trim()
if (!validateCredentials(email, password, host, symbol)) return
if (!validateCredentials(email, password, host)) return
disposable.add(studentRepository.getStudentsScrapper(email, password, host, symbol)
.subscribeOn(schedulers.backgroundThread)
@ -128,7 +116,7 @@ class LoginFormPresenter @Inject constructor(
view?.onRecoverClick()
}
private fun validateCredentials(login: String, password: String, host: String, symbol: String): Boolean {
private fun validateCredentials(login: String, password: String, host: String): Boolean {
var isCorrect = true
if (login.isEmpty()) {
@ -156,11 +144,6 @@ class LoginFormPresenter @Inject constructor(
isCorrect = false
}
if ("standard" !in host && symbol.isBlank()) {
view?.setErrorSymbolRequired(focus = isCorrect)
isCorrect = false
}
return isCorrect
}
}

View File

@ -15,28 +15,20 @@ interface LoginFormView : BaseView {
val formHostSymbol: String
val formSymbolValue: String
val nicknameLabel: String
val emailLabel: String
fun setCredentials(username: String, pass: String)
fun setSymbol(symbol: String)
fun setUsernameLabel(label: String)
fun showSymbol(show: Boolean)
fun setErrorUsernameRequired()
fun setErrorLoginRequired()
fun setErrorEmailRequired()
fun setErrorSymbolRequired(focus: Boolean)
fun setErrorPassRequired(focus: Boolean)
fun setErrorPassInvalid(focus: Boolean)
@ -47,8 +39,6 @@ interface LoginFormView : BaseView {
fun clearPassError()
fun clearSymbolError()
fun showSoftKeyboard()
fun hideSoftKeyboard()

View File

@ -11,7 +11,6 @@ import android.view.ViewGroup
import android.webkit.JavascriptInterface
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.ArrayAdapter
import androidx.core.widget.doOnTextChanged
import io.github.wulkanowy.R
import io.github.wulkanowy.ui.base.BaseFragment
@ -35,15 +34,17 @@ class LoginRecoverFragment : BaseFragment(), LoginRecoverView {
private lateinit var hostValues: Array<String>
private lateinit var hostSymbols: Array<String>
override val recoverHostValue: String
get() = hostValues.getOrNull(hostKeys.indexOf(loginRecoverHost.text.toString())).orEmpty()
override val formHostSymbol: String
get() = hostSymbols.getOrNull(hostKeys.indexOf(loginRecoverHost.text.toString())).orEmpty()
override val recoverNameValue: String
get() = loginRecoverName.text.toString().trim()
override val recoverSymbolValue: String
get() = loginRecoverSymbol.text.toString().trim()
override val emailHintString: String
get() = getString(R.string.login_email_hint)
@ -66,17 +67,15 @@ class LoginRecoverFragment : BaseFragment(), LoginRecoverView {
loginRecoverWebView.setBackgroundColor(Color.TRANSPARENT)
hostKeys = resources.getStringArray(R.array.hosts_keys)
hostValues = resources.getStringArray(R.array.hosts_values)
hostSymbols = resources.getStringArray(R.array.hosts_symbols)
loginRecoverName.doOnTextChanged { _, _, _, _ -> presenter.onNameTextChanged() }
loginRecoverSymbol.doOnTextChanged { _, _, _, _ -> presenter.onSymbolTextChanged() }
loginRecoverHost.setOnItemClickListener { _, _, _, _ -> presenter.onHostSelected() }
loginRecoverButton.setOnClickListener { presenter.onRecoverClick() }
loginRecoverErrorRetry.setOnClickListener { presenter.onRecoverClick() }
loginRecoverErrorDetails.setOnClickListener { presenter.onDetailsClick() }
loginRecoverLogin.setOnClickListener { (activity as LoginActivity).switchView(0) }
loginRecoverSymbol.setAdapter(ArrayAdapter(requireContext(), android.R.layout.simple_list_item_1, resources.getStringArray(R.array.symbols_values)))
with(loginRecoverHost) {
setText(hostKeys.getOrNull(0).orEmpty())
setAdapter(LoginSymbolAdapter(context, R.layout.support_simple_spinner_dropdown_item, hostKeys))
@ -106,25 +105,10 @@ class LoginRecoverFragment : BaseFragment(), LoginRecoverView {
}
}
override fun setSymbolError(focus: Boolean) {
with(loginRecoverSymbolLayout) {
if (focus) requestFocus()
error = getString(R.string.login_field_required)
}
}
override fun clearUsernameError() {
loginRecoverNameLayout.error = null
}
override fun clearSymbolError() {
loginRecoverSymbolLayout.error = null
}
override fun showSymbol(show: Boolean) {
loginRecoverSymbolLayout.visibility = if (show) VISIBLE else GONE
}
override fun showProgress(show: Boolean) {
loginRecoverProgress.visibility = if (show) VISIBLE else GONE
}

View File

@ -34,10 +34,6 @@ class LoginRecoverPresenter @Inject constructor(
view?.clearUsernameError()
}
fun onSymbolTextChanged() {
view?.clearSymbolError()
}
fun onHostSelected() {
view?.run {
if ("fakelog" in recoverHostValue) setDefaultCredentials("jan@fakelog.cf")
@ -48,7 +44,6 @@ class LoginRecoverPresenter @Inject constructor(
fun updateFields() {
view?.run {
showSymbol("adfs" in recoverHostValue)
setUsernameHint(if ("standard" in recoverHostValue) emailHintString else loginPeselEmailHintString)
}
}
@ -56,9 +51,9 @@ class LoginRecoverPresenter @Inject constructor(
fun onRecoverClick() {
val username = view?.recoverNameValue.orEmpty()
val host = view?.recoverHostValue.orEmpty()
val symbol = view?.recoverSymbolValue.orEmpty()
val symbol = view?.formHostSymbol.orEmpty()
if (!validateInput(username, host, symbol)) return
if (!validateInput(username, host)) return
disposable.add(recoverRepository.getReCaptchaSiteKey(host, symbol.ifBlank { "Default" })
.subscribeOn(schedulers.backgroundThread)
@ -80,7 +75,7 @@ class LoginRecoverPresenter @Inject constructor(
})
}
private fun validateInput(username: String, host: String, symbol: String): Boolean {
private fun validateInput(username: String, host: String): Boolean {
var isCorrect = true
if (username.isEmpty()) {
@ -93,18 +88,13 @@ class LoginRecoverPresenter @Inject constructor(
isCorrect = false
}
if ("adfs" in host && symbol.isBlank()) {
view?.setSymbolError(focus = isCorrect)
isCorrect = false
}
return isCorrect
}
fun onReCaptchaVerified(reCaptchaResponse: String) {
val username = view?.recoverNameValue.orEmpty()
val host = view?.recoverHostValue.orEmpty()
val symbol = view?.recoverSymbolValue.ifNullOrBlank { "Default" }
val symbol = view?.formHostSymbol.ifNullOrBlank { "Default" }
with(disposable) {
clear()

View File

@ -6,9 +6,9 @@ interface LoginRecoverView : BaseView {
val recoverHostValue: String
val recoverNameValue: String
val formHostSymbol: String
val recoverSymbolValue: String
val recoverNameValue: String
val emailHintString: String
@ -22,18 +22,12 @@ interface LoginRecoverView : BaseView {
fun clearUsernameError()
fun clearSymbolError()
fun showSymbol(show: Boolean)
fun setErrorNameRequired()
fun setUsernameHint(hint: String)
fun setUsernameError(message: String)
fun setSymbolError(focus: Boolean)
fun showSoftKeyboard()
fun hideSoftKeyboard()

View File

@ -202,7 +202,7 @@
android:layout_marginRight="24dp"
android:hint="@string/login_host_hint"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/loginFormSymbolLayout"
app:layout_constraintBottom_toTopOf="@+id/loginFormAdvancedButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginFormRecoverLink">
@ -215,36 +215,6 @@
tools:ignore="Deprecated,LabelFor" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/loginFormSymbolLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:hint="@string/login_symbol_hint"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@+id/loginFormSignIn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginFormHostLayout">
<AutoCompleteTextView
android:id="@+id/loginFormSymbol"
style="@style/Widget.MaterialComponents.TextInputEditText.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeActionLabel="@string/login_sign_in"
android:imeOptions="actionDone"
android:importantForAutofill="no"
android:inputType="textAutoComplete|textNoSuggestions"
android:maxLines="1"
tools:ignore="LabelFor" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/loginFormAdvancedButton"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
@ -259,7 +229,7 @@
app:layout_constraintBottom_toBottomOf="@id/loginFormSignIn"
app:layout_constraintEnd_toStartOf="@+id/loginFormSignIn"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@id/loginFormSymbolLayout"
app:layout_constraintStart_toStartOf="@id/loginFormHostLayout"
app:layout_constraintTop_toTopOf="@+id/loginFormSignIn" />
<com.google.android.material.button.MaterialButton
@ -274,7 +244,7 @@
android:text="@string/login_sign_in"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginFormSymbolLayout" />
app:layout_constraintTop_toBottomOf="@+id/loginFormHostLayout" />
<TextView
android:id="@+id/loginFormPrivacyLink"

View File

@ -88,6 +88,7 @@
android:autofillHints="emailAddress"
android:inputType="textEmailAddress"
android:maxLines="1"
android:imeOptions="actionDone"
tools:targetApi="o" />
<requestFocus />
@ -105,7 +106,7 @@
android:layout_marginRight="24dp"
android:hint="@string/login_host_hint"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/loginRecoverSymbolLayout"
app:layout_constraintBottom_toTopOf="@+id/loginRecoverButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginRecoverNameLayout">
@ -118,46 +119,17 @@
tools:ignore="Deprecated,LabelFor" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/loginRecoverSymbolLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:hint="@string/login_symbol_hint"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@+id/loginRecoverButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginRecoverHostLayout">
<AutoCompleteTextView
android:id="@+id/loginRecoverSymbol"
style="@style/Widget.MaterialComponents.TextInputEditText.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeActionLabel="@string/login_sign_in"
android:imeOptions="actionDone"
android:inputType="textAutoComplete|textNoSuggestions"
android:maxLines="1"
tools:ignore="LabelFor" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/loginRecoverButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:text="@string/login_recover"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginRecoverSymbolLayout" />
app:layout_constraintTop_toBottomOf="@+id/loginRecoverHostLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -1,33 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
<string-array name="hosts_keys">
<item>Vulcan - standardowy</item>
<item>Vulcan - niestandardowy</item>
<item>Vulcan</item>
<item>Opolska eSzkoła</item>
<item>Gdańska Platforma Edukacyjna</item>
<item>Lubelski Portal Oświatowy</item>
<item>EduNet Miasta Tarnowa</item>
<item>ResMan Rzeszów</item>
<item>Rawa Mazowiecka - Platforma vEdukacja</item>
<item>Zduńska Wola - e-Urząd</item>
<item>Sieradz - Portal oświatowy</item>
<item>Łask - Platforma vEdukacja</item>
<item>Powiat łaski - Platforma edukacyjna</item>
<item>Powiat Krasnostawski - Platforma oświatowa</item>
<item>Powiat kętrzyński - Platforma e-Usług</item>
<item>Gmina Ulan-Majorat - Platforma oświatowa</item>
<item>Gmina Ozorków - Platforma edukacyjna</item>
<item>Gmina Łopiennik Górny - Platforma oświatowa</item>
<item>Fakelog</item>
</string-array>
<string-array name="hosts_values">
<item>https://vulcan.net.pl/?standard</item>
<item>https://vulcan.net.pl/?adfs</item>
<item>https://eszkola.opolskie.pl</item>
<item>https://edu.gdansk.pl</item>
<item>https://edu.lublin.eu</item>
<item>https://umt.tarnow.pl</item>
<item>https://resman.pl</item>
<item>https://vulcan.net.pl/</item>
<item>https://vulcan.net.pl/</item>
<item>https://vulcan.net.pl/</item>
<item>https://vulcan.net.pl/</item>
<item>https://vulcan.net.pl/</item>
<item>https://vulcan.net.pl/</item>
<item>https://vulcan.net.pl/</item>
<item>https://vulcan.net.pl/</item>
<item>https://vulcan.net.pl/</item>
<item>https://vulcan.net.pl/</item>
<item>http://fakelog.cf/?standard</item>
</string-array>
<string-array name="hosts_symbols">
<item>Default</item>
<item />
<item>opole</item>
<item>gdansk</item>
<item>lublin</item>
<item>tarnow</item>
<item>rzeszow</item>
<item>rawamazowiecka</item>
<item>zdunskawola</item>
<item>sieradz</item>
<item>lask</item>
<item>powiatlaski</item>
<item>powiatkrasnostawski</item>
<item>powiatketrzynski</item>
<item>gminaulanmajorat</item>
<item>gminaozorkow</item>
<item>gminalopiennikgorny</item>
<item>powiatwulkanowy</item>
</string-array>
</resources>

File diff suppressed because it is too large Load Diff

View File

@ -92,7 +92,6 @@ class LoginFormPresenterTest {
`when`(loginFormView.formUsernameValue).thenReturn("@")
`when`(loginFormView.formPassValue).thenReturn("123456")
`when`(loginFormView.formHostValue).thenReturn("https://fakelog.cf/?standard")
`when`(loginFormView.formSymbolValue).thenReturn("Default")
`when`(loginFormView.formHostSymbol).thenReturn("Default")
presenter.onSignInClick()
@ -110,7 +109,6 @@ class LoginFormPresenterTest {
`when`(loginFormView.formUsernameValue).thenReturn("@")
`when`(loginFormView.formPassValue).thenReturn("123456")
`when`(loginFormView.formHostValue).thenReturn("https://fakelog.cf/?standard")
`when`(loginFormView.formSymbolValue).thenReturn("Default")
`when`(loginFormView.formHostSymbol).thenReturn("Default")
presenter.onSignInClick()
@ -128,7 +126,6 @@ class LoginFormPresenterTest {
`when`(loginFormView.formUsernameValue).thenReturn("@")
`when`(loginFormView.formPassValue).thenReturn("123456")
`when`(loginFormView.formHostValue).thenReturn("https://fakelog.cf/?standard")
`when`(loginFormView.formSymbolValue).thenReturn("Default")
`when`(loginFormView.formHostSymbol).thenReturn("Default")
presenter.onSignInClick()
presenter.onSignInClick()
@ -147,7 +144,6 @@ class LoginFormPresenterTest {
`when`(loginFormView.formUsernameValue).thenReturn("@")
`when`(loginFormView.formPassValue).thenReturn("123456")
`when`(loginFormView.formHostValue).thenReturn("https://fakelog.cf/?standard")
`when`(loginFormView.formSymbolValue).thenReturn("Default")
`when`(loginFormView.formHostSymbol).thenReturn("Default")
presenter.onSignInClick()