try logging in twice as there are sometimes no authorization code on the reservation page

This commit is contained in:
Eugene Zadyra
2024-11-22 02:01:04 +01:00
parent 0d990071ad
commit 1066e31562
3 changed files with 22 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
FROM eclipse-temurin:11-jre-focal
RUN apt-get update -y && apt-get install -y netcat # nc command
RUN apt-get update --allow-unauthenticated --allow-insecure-repositories -y && apt-get install --allow-unauthenticated -y netcat # nc command
RUN ln -fs /usr/share/zoneinfo/Europe/Warsaw /etc/localtime
RUN dpkg-reconfigure -f noninteractive tzdata

View File

@@ -147,19 +147,28 @@ class ApiService extends SessionSupport {
cookies.map(_.map(v => v.getName -> v).toMap).reduce(_ ++ _).values.toSeq
}
override def fullLogin(username: String, encryptedPassword: String): ThrowableOr[Session] = {
override def fullLogin(username: String, encryptedPassword: String, secondAttempt: Boolean = false): ThrowableOr[Session] = {
val password = textEncryptor.decrypt(encryptedPassword)
val clientId = java.util.UUID.randomUUID.toString
for {
r1 <- luxmedApi.login(username, password, clientId)
tmpSession = Session(r1.body.accessToken, r1.body.accessToken, "", r1.cookies)
r2 <- luxmedApi.loginToApp(tmpSession)
cookies = joinCookies(r1.cookies, r2.cookies, Seq(new HttpCookie("GlobalLang", "pl")))
accessToken = r1.body.accessToken
tokenType = r1.body.tokenType
r3 <- luxmedApi.getReservationPage(tmpSession, cookies)
jwtToken = extractAccessTokenFromReservationPage(r3.body)
} yield Session(accessToken, tokenType, jwtToken, joinCookies(cookies, r3.cookies))
try {
for {
r1 <- luxmedApi.login(username, password, clientId)
tmpSession = Session(r1.body.accessToken, r1.body.accessToken, "", r1.cookies)
r2 <- luxmedApi.loginToApp(tmpSession)
cookies = joinCookies(r1.cookies, r2.cookies, Seq(new HttpCookie("GlobalLang", "pl")))
accessToken = r1.body.accessToken
tokenType = r1.body.tokenType
r3 <- luxmedApi.getReservationPage(tmpSession, cookies)
jwtToken = extractAccessTokenFromReservationPage(r3.body)
} yield Session(accessToken, tokenType, jwtToken, joinCookies(cookies, r3.cookies))
} catch {
case e: Exception if !secondAttempt => {
logger.warn("couldn't login from the first attempt. trying one more time after a short pause", e)
Thread.sleep(3000)
fullLogin(username, encryptedPassword, secondAttempt = true)
}
case e: Exception => Left(e)
}
}
def getXsrfToken(accountId: Long): ThrowableOr[XsrfToken] = {

View File

@@ -11,7 +11,7 @@ import scala.collection.mutable
trait SessionSupport extends StrictLogging {
def fullLogin(username: String, password: String): ThrowableOr[Session]
def fullLogin(username: String, password: String, secondAttempt: Boolean = false): ThrowableOr[Session]
protected def dataService: DataService