Skip to content

Commit

Permalink
try logging in twice as there are sometimes no authorization code on …
Browse files Browse the repository at this point in the history
…the reservation page
  • Loading branch information
dyrkin committed Nov 22, 2024
1 parent 0d99007 commit cb299a0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 -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
Expand Down
31 changes: 20 additions & 11 deletions server/src/main/scala/com/lbs/server/service/ApiService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cb299a0

Please sign in to comment.