Create registers selector consts in account repo

This commit is contained in:
Mikołaj Pich 2020-06-01 02:22:33 +02:00
parent b8654c37c4
commit aadeb64a9f
3 changed files with 27 additions and 12 deletions

View file

@ -7,6 +7,10 @@ import io.github.wulkanowy.sdk.scrapper.Scrapper.LoginType.ADFSLight
import io.github.wulkanowy.sdk.scrapper.Scrapper.LoginType.ADFSLightScoped
import io.github.wulkanowy.sdk.scrapper.Scrapper.LoginType.STANDARD
import io.github.wulkanowy.sdk.scrapper.login.NotLoggedInException
import io.github.wulkanowy.sdk.scrapper.repository.AccountRepository.Companion.SELECTOR_ADFS
import io.github.wulkanowy.sdk.scrapper.repository.AccountRepository.Companion.SELECTOR_ADFS_CARDS
import io.github.wulkanowy.sdk.scrapper.repository.AccountRepository.Companion.SELECTOR_ADFS_LIGHT
import io.github.wulkanowy.sdk.scrapper.repository.AccountRepository.Companion.SELECTOR_STANDARD
import okhttp3.Interceptor
import okhttp3.Response
import org.jsoup.Jsoup
@ -26,10 +30,10 @@ class NotLoggedInErrorInterceptor(private val loginType: LoginType) : Intercepto
}
if (when (loginType) {
STANDARD -> doc.select(".loginButton, .LogOnBoard input[type=submit]")
ADFS -> doc.select("form[name=form1] #SubmitButton")
ADFSLight, ADFSLightScoped -> doc.select(".submit-button, form #SubmitButton")
ADFSCards -> doc.select("#PassiveSignInButton")
STANDARD -> doc.select(SELECTOR_STANDARD)
ADFS -> doc.select(SELECTOR_ADFS)
ADFSLight, ADFSLightScoped -> doc.select(SELECTOR_ADFS_LIGHT)
ADFSCards -> doc.select(SELECTOR_ADFS_CARDS)
else -> Elements()
}.isNotEmpty()
) {

View file

@ -20,6 +20,13 @@ import java.net.URL
class AccountRepository(private val account: AccountService) {
companion object {
const val SELECTOR_STANDARD = ".loginButton, .LogOnBoard input[type=submit]" // remove second selector?
const val SELECTOR_ADFS = "form[name=form1] #SubmitButton"
const val SELECTOR_ADFS_LIGHT = ".submit-button, form #SubmitButton"
const val SELECTOR_ADFS_CARDS = "#PassiveSignInButton"
}
fun getPasswordResetCaptcha(registerBaseUrl: String, symbol: String): Single<Pair<String, String>> {
return getPasswordResetUrl(registerBaseUrl, symbol.trim()).flatMap { (_, resetUrl) ->
account.getPasswordResetPageWithCaptcha(resetUrl)
@ -82,9 +89,9 @@ class AccountRepository(private val account: AccountService) {
private fun getLoginType(urlGenerator: ServiceManager.UrlGenerator): Single<Scrapper.LoginType> {
return account.getFormType(urlGenerator.generate(ServiceManager.UrlGenerator.Site.LOGIN) + "Account/LogOn").map { it.page }.map {
when {
it.select(".LogOnBoard input[type=submit]").isNotEmpty() -> STANDARD
it.select("form[name=form1] #SubmitButton").isNotEmpty() -> ADFS
it.select(".submit-button, form #SubmitButton").isNotEmpty() -> {
it.select(SELECTOR_STANDARD).isNotEmpty() -> STANDARD
it.select(SELECTOR_ADFS).isNotEmpty() -> ADFS
it.select(SELECTOR_ADFS_LIGHT).isNotEmpty() -> {
it.selectFirst("form").attr("action").run {
when {
contains("cufs.edu.lublin.eu") -> ADFSLightCufs
@ -94,7 +101,7 @@ class AccountRepository(private val account: AccountService) {
}
}
}
it.select("#PassiveSignInButton").isNotEmpty() -> ADFSCards
it.select(SELECTOR_ADFS_CARDS).isNotEmpty() -> ADFSCards
else -> throw ScrapperException("Nieznany typ dziennika '${it.select("title")}")
}
}

View file

@ -12,6 +12,10 @@ import io.github.wulkanowy.sdk.scrapper.login.LoginHelper
import io.github.wulkanowy.sdk.scrapper.register.SendCertificateResponse
import io.github.wulkanowy.sdk.scrapper.register.Student
import io.github.wulkanowy.sdk.scrapper.register.StudentAndParentResponse
import io.github.wulkanowy.sdk.scrapper.repository.AccountRepository.Companion.SELECTOR_ADFS
import io.github.wulkanowy.sdk.scrapper.repository.AccountRepository.Companion.SELECTOR_ADFS_CARDS
import io.github.wulkanowy.sdk.scrapper.repository.AccountRepository.Companion.SELECTOR_ADFS_LIGHT
import io.github.wulkanowy.sdk.scrapper.repository.AccountRepository.Companion.SELECTOR_STANDARD
import io.github.wulkanowy.sdk.scrapper.service.RegisterService
import io.github.wulkanowy.sdk.scrapper.service.ServiceManager
import io.github.wulkanowy.sdk.scrapper.service.StudentAndParentService
@ -100,9 +104,9 @@ class RegisterRepository(
private fun getLoginType(urlGenerator: ServiceManager.UrlGenerator): Single<Scrapper.LoginType> {
return register.getFormType(urlGenerator.generate(ServiceManager.UrlGenerator.Site.LOGIN) + "Account/LogOn").map { it.page }.map {
when {
it.select(".LogOnBoard input[type=submit]").isNotEmpty() -> Scrapper.LoginType.STANDARD
it.select("form[name=form1] #SubmitButton").isNotEmpty() -> Scrapper.LoginType.ADFS
it.select(".submit-button, form #SubmitButton").isNotEmpty() -> {
it.select(SELECTOR_STANDARD).isNotEmpty() -> Scrapper.LoginType.STANDARD
it.select(SELECTOR_ADFS).isNotEmpty() -> Scrapper.LoginType.ADFS
it.select(SELECTOR_ADFS_LIGHT).isNotEmpty() -> {
it.selectFirst("form").attr("action").run {
when {
contains("cufs.edu.lublin.eu") -> Scrapper.LoginType.ADFSLightCufs
@ -112,7 +116,7 @@ class RegisterRepository(
}
}
}
it.select("#PassiveSignInButton").isNotEmpty() -> Scrapper.LoginType.ADFSCards
it.select(SELECTOR_ADFS_CARDS).isNotEmpty() -> Scrapper.LoginType.ADFSCards
else -> throw ScrapperException("Nieznany typ dziennika")
}
}