1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-02-22 18:14:44 +01:00

Add register variant auto-matching based on email (#1041)

This commit is contained in:
Mikołaj Pich 2020-12-06 21:23:02 +01:00 committed by GitHub
parent 6ca5e11371
commit 67cef0f6d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 20 deletions

View File

@ -142,7 +142,7 @@ configurations.all {
} }
dependencies { dependencies {
implementation "io.github.wulkanowy:sdk:bcf6b53" implementation "io.github.wulkanowy:sdk:50c049ef"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1' coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1'

View File

@ -14,7 +14,7 @@ class TimetableRemote @Inject constructor(private val sdk: Sdk) {
suspend fun getTimetable(student: Student, semester: Semester, startDate: LocalDate, endDate: LocalDate): List<Timetable> { suspend fun getTimetable(student: Student, semester: Semester, startDate: LocalDate, endDate: LocalDate): List<Timetable> {
return sdk.init(student).switchDiary(semester.diaryId, semester.schoolYear) return sdk.init(student).switchDiary(semester.diaryId, semester.schoolYear)
.getTimetable(startDate, endDate) .getTimetable(startDate, endDate).first
.map { .map {
Timetable( Timetable(
studentId = semester.studentId, studentId = semester.studentId,

View File

@ -89,6 +89,8 @@ class LoginFormFragment : BaseFragment<FragmentLoginFormBinding>(R.layout.fragme
} }
} }
override fun getHostsValues(): List<String> = hostValues.toList()
override fun setCredentials(username: String, pass: String) { override fun setCredentials(username: String, pass: String) {
with(binding) { with(binding) {
loginFormUsername.setText(username) loginFormUsername.setText(username)
@ -96,6 +98,12 @@ class LoginFormFragment : BaseFragment<FragmentLoginFormBinding>(R.layout.fragme
} }
} }
override fun setHost(host: String) {
binding.loginFormHost.setText(
hostKeys.getOrNull(hostValues.indexOf(host)).orEmpty()
)
}
override fun setUsernameLabel(label: String) { override fun setUsernameLabel(label: String) {
binding.loginFormUsernameLayout.hint = label binding.loginFormUsernameLayout.hint = label
} }

View File

@ -1,5 +1,6 @@
package io.github.wulkanowy.ui.modules.login.form package io.github.wulkanowy.ui.modules.login.form
import androidx.core.net.toUri
import io.github.wulkanowy.data.Status import io.github.wulkanowy.data.Status
import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.data.repositories.student.StudentRepository
import io.github.wulkanowy.ui.base.BasePresenter import io.github.wulkanowy.ui.base.BasePresenter
@ -56,7 +57,7 @@ class LoginFormPresenter @Inject constructor(
fun updateUsernameLabel() { fun updateUsernameLabel() {
view?.run { view?.run {
setUsernameLabel(if ("standard" in formHostValue) emailLabel else nicknameLabel) setUsernameLabel(if ("login" in formHostValue) nicknameLabel else emailLabel)
} }
} }
@ -66,6 +67,16 @@ class LoginFormPresenter @Inject constructor(
fun onUsernameTextChanged() { fun onUsernameTextChanged() {
view?.clearUsernameError() view?.clearUsernameError()
val username = view?.formUsernameValue.orEmpty().trim()
if ("@" in username && "@vulcan" !in username) {
val hosts = view?.getHostsValues().orEmpty().map { it.toUri().host to it }.toMap()
val usernameHost = username.substringAfter("@")
hosts[usernameHost]?.let {
view?.setHost(it)
}
}
} }
fun onSignInClick() { fun onSignInClick() {
@ -135,12 +146,12 @@ class LoginFormPresenter @Inject constructor(
view?.setErrorUsernameRequired() view?.setErrorUsernameRequired()
isCorrect = false isCorrect = false
} else { } else {
if ("@" in login && "standard" !in host) { if ("@" in login && "login" in host) {
view?.setErrorLoginRequired() view?.setErrorLoginRequired()
isCorrect = false isCorrect = false
} }
if ("@" !in login && "standard" in host) { if ("@" !in login && "email" in host) {
view?.setErrorEmailRequired() view?.setErrorEmailRequired()
isCorrect = false isCorrect = false
} }

View File

@ -19,8 +19,12 @@ interface LoginFormView : BaseView {
val emailLabel: String val emailLabel: String
fun getHostsValues(): List<String>
fun setCredentials(username: String, pass: String) fun setCredentials(username: String, pass: String)
fun setHost(host: String)
fun setUsernameLabel(label: String) fun setUsernameLabel(label: String)
fun setErrorUsernameRequired() fun setErrorUsernameRequired()

View File

@ -22,25 +22,25 @@
<item>Fakelog</item> <item>Fakelog</item>
</string-array> </string-array>
<string-array name="hosts_values"> <string-array name="hosts_values">
<item>https://vulcan.net.pl/?standard</item> <item>https://vulcan.net.pl/?email</item>
<item>https://eszkola.opolskie.pl</item> <item>https://eszkola.opolskie.pl</item>
<item>https://edu.gdansk.pl</item> <item>https://edu.gdansk.pl</item>
<item>https://edu.lublin.eu</item> <item>https://edu.lublin.eu</item>
<item>https://umt.tarnow.pl</item> <item>https://umt.tarnow.pl</item>
<item>https://resman.pl</item> <item>https://resman.pl</item>
<item>https://eduportal.koszalin.pl</item> <item>https://eduportal.koszalin.pl</item>
<item>https://vulcan.net.pl/</item> <item>https://vulcan.net.pl/?login</item>
<item>https://vulcan.net.pl/</item> <item>https://vulcan.net.pl/?login</item>
<item>https://vulcan.net.pl/</item> <item>https://vulcan.net.pl/?login</item>
<item>https://vulcan.net.pl/</item> <item>https://vulcan.net.pl/?login</item>
<item>https://vulcan.net.pl/</item> <item>https://vulcan.net.pl/?login</item>
<item>https://vulcan.net.pl/</item> <item>https://vulcan.net.pl/?login</item>
<item>https://vulcan.net.pl/</item> <item>https://vulcan.net.pl/?login</item>
<item>https://vulcan.net.pl/</item> <item>https://vulcan.net.pl/?login</item>
<item>https://vulcan.net.pl/</item> <item>https://vulcan.net.pl/?login</item>
<item>https://vulcan.net.pl/</item> <item>https://vulcan.net.pl/?login</item>
<item>https://vulcan.net.pl/</item> <item>https://vulcan.net.pl/?login</item>
<item>http://fakelog.tk/?standard</item> <item>http://fakelog.cf/?email</item>
</string-array> </string-array>
<string-array name="hosts_symbols"> <string-array name="hosts_symbols">
<item>Default</item> <item>Default</item>

View File

@ -39,10 +39,10 @@ class TimetableRemoteTest {
of(2018, 9, 10), of(2018, 9, 10),
of(2018, 9, 15) of(2018, 9, 15)
) )
} returns listOf( } returns (listOf(
getTimetable(of(2018, 9, 10)), getTimetable(of(2018, 9, 10)),
getTimetable(of(2018, 9, 17)) getTimetable(of(2018, 9, 17))
) ) to emptyList())
every { semesterMock.studentId } returns 1 every { semesterMock.studentId } returns 1
every { semesterMock.diaryId } returns 1 every { semesterMock.diaryId } returns 1