feat(15): associating session with root page

This commit is contained in:
efim 2023-07-13 18:31:30 +00:00
parent 2d514e9258
commit 03aa9f8b94
5 changed files with 65 additions and 42 deletions

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
hello from the resource file!

View File

@ -548,6 +548,14 @@ video {
bottom: 0px; bottom: 0px;
} }
.end-0 {
inset-inline-end: 0px;
}
.top-0 {
top: 0px;
}
.col-start-2 { .col-start-2 {
grid-column-start: 2; grid-column-start: 2;
} }
@ -569,6 +577,10 @@ video {
margin-top: -5rem; margin-top: -5rem;
} }
.mb-2 {
margin-bottom: 0.5rem;
}
.ml-2 { .ml-2 {
margin-left: 0.5rem; margin-left: 0.5rem;
} }
@ -593,10 +605,6 @@ video {
margin-top: 0.3rem; margin-top: 0.3rem;
} }
.mb-2 {
margin-bottom: 0.5rem;
}
.flex { .flex {
display: flex; display: flex;
} }
@ -621,6 +629,10 @@ video {
height: 3rem; height: 3rem;
} }
.h-14 {
height: 3.5rem;
}
.h-20 { .h-20 {
height: 5rem; height: 5rem;
} }
@ -653,20 +665,12 @@ video {
height: 100vh; height: 100vh;
} }
.h-16 {
height: 4rem;
}
.h-14 {
height: 3.5rem;
}
.w-11\/12 { .w-11\/12 {
width: 91.666667%; width: 91.666667%;
} }
.w-20 { .w-14 {
width: 5rem; width: 3.5rem;
} }
.w-24 { .w-24 {
@ -693,18 +697,6 @@ video {
width: 100vw; width: 100vw;
} }
.w-16 {
width: 4rem;
}
.w-12 {
width: 3rem;
}
.w-14 {
width: 3.5rem;
}
.grow { .grow {
flex-grow: 1; flex-grow: 1;
} }
@ -856,6 +848,11 @@ video {
padding-right: 1.5rem; padding-right: 1.5rem;
} }
.py-20 {
padding-top: 5rem;
padding-bottom: 5rem;
}
.py-3 { .py-3 {
padding-top: 0.75rem; padding-top: 0.75rem;
padding-bottom: 0.75rem; padding-bottom: 0.75rem;
@ -871,11 +868,6 @@ video {
padding-bottom: 2rem; padding-bottom: 2rem;
} }
.py-20 {
padding-top: 5rem;
padding-bottom: 5rem;
}
.pl-6 { .pl-6 {
padding-left: 1.5rem; padding-left: 1.5rem;
} }
@ -903,11 +895,6 @@ video {
line-height: 1.25rem; line-height: 1.25rem;
} }
.text-xl {
font-size: 1.25rem;
line-height: 1.75rem;
}
.font-bold { .font-bold {
font-weight: 700; font-weight: 700;
} }

View File

@ -9,10 +9,14 @@
rel="icon" rel="icon"
type="image/png" type="image/png"
sizes="32x32" sizes="32x32"
href="./assets/images/favicon-32x32.png" th:href="'public/images/favicon-32x32.png'"
href="../public/images/favicon-32x32.png"
/> />
<link href="../public/out.css" rel="stylesheet" /> <link th:href="'public/out.css'" href="../public/out.css" rel="stylesheet" />
<script
th:src="'public/htmx.min.js'"
src="../public/htmx.min.js"
></script>
<title>Frontend Mentor | Multi-step form</title> <title>Frontend Mentor | Multi-step form</title>
<!-- Feel free to remove these styles or customise in your own stylesheet 👍 --> <!-- Feel free to remove these styles or customise in your own stylesheet 👍 -->
@ -28,6 +32,14 @@
</head> </head>
<body> <body>
<main class="bg-light-gray h-screen w-screen"> <main class="bg-light-gray h-screen w-screen">
<section
class="absolute top-0 end-0"
>
<button
hx-get="/force-new-session"
>Request new session</button>
</section>
<!-- here be immediate hx-get for the form. to subscitute the body --> <!-- here be immediate hx-get for the form. to subscitute the body -->
</main>
</body> </body>
</html> </html>

View File

@ -3,6 +3,8 @@ package multistepform
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver
import org.thymeleaf.TemplateEngine import org.thymeleaf.TemplateEngine
import org.thymeleaf.context.Context import org.thymeleaf.context.Context
import cask.endpoints.ParamReader
import java.util.UUID
case class Routes()(implicit cc: castor.Context, log: cask.Logger) case class Routes()(implicit cc: castor.Context, log: cask.Logger)
extends cask.Routes { extends cask.Routes {
@ -14,13 +16,35 @@ case class Routes()(implicit cc: castor.Context, log: cask.Logger)
val templateEngine = new TemplateEngine() val templateEngine = new TemplateEngine()
templateEngine.setTemplateResolver(templateResolver) templateEngine.setTemplateResolver(templateResolver)
val sessoinCookieName = "sessionId"
@cask.get("/") @cask.get("/")
def getIndex() = { def getIndex(ctx: cask.Request) = {
val sessionCookie = ctx.cookies.get(sessoinCookieName)
lazy val newSessionCookies = sessionCookie match {
case None => Seq(cask.Cookie(sessoinCookieName, UUID.randomUUID().toString(), path = "/"))
case Some(_) => Seq.empty // don't set new cookies
}
println(s"getting cookie $sessionCookie will set new? ${newSessionCookies}")
val context = new Context() val context = new Context()
val indexPage = templateEngine.process("index", context) val indexPage = templateEngine.process("index", context)
cask.Response( cask.Response(
indexPage, indexPage,
headers = Seq("Content-Type" -> "text/html;charset=UTF-8") headers = Seq("Content-Type" -> "text/html;charset=UTF-8"),
cookies = newSessionCookies
)
}
@cask.get("/force-new-session")
def forceNewSession() = {
val newSessionCookie = cask.Cookie(sessoinCookieName, UUID.randomUUID().toString(), path = "/")
println(s"setting new session ${newSessionCookie.value}")
cask.Response(
s"New session forced. Force new session",
headers = Seq("Content-Type" -> "text/html;charset=UTF-8"),
cookies = Seq(newSessionCookie)
) )
} }