This commit is contained in:
00asdf 2025-04-26 03:12:13 +02:00
parent 4fa908779d
commit f0e5732cc7

View File

@ -92,15 +92,15 @@ fun main() {
</head> </head>
<body> <body>
<h1>Welcome to HeatControl</h1> <h1>Welcome to HeatControl</h1>
<p>Please log in to view the current temperature</p> <p>Please log in to view the current temperature.</p>
<br /> <br />
<p> <p>
Login Form Login Form
<br /> <br />
<form action="/login/in" method="post"> <form action="/login/in" method="post">
<label for="uname">user name:</label><br /> <label for="uname">Username:</label><br />
<input type="text" id="uname" name="uname"><br /> <input type="text" id="uname" name="uname"><br />
<label for="pwd">password:</label><br /> <label for="pwd">Password:</label><br />
<input type="password" id="pwd" name="pwd"><br /> <input type="password" id="pwd" name="pwd"><br />
<input type="submit" value="Submit"> <input type="submit" value="Submit">
</form> </form>
@ -224,7 +224,7 @@ fun main() {
} }
val forecastQuery = Thread { val forecastQuery = Thread {
while (!Thread.interrupted()) { whileNotInterrupted {
var success = false var success = false
val request = HttpRequest.newBuilder(URI.create(GlobalDataStore.API)).GET().build() val request = HttpRequest.newBuilder(URI.create(GlobalDataStore.API)).GET().build()
HttpClient.newHttpClient() HttpClient.newHttpClient()
@ -320,7 +320,7 @@ fun main() {
val pidController = PidController(c1, c2, c3) val pidController = PidController(c1, c2, c3)
var cycles = -1 var cycles = -1
while (!Thread.interrupted()) { whileNotInterrupted {
if (cycles < 0) { if (cycles < 0) {
c1.runCalibrationSequence() c1.runCalibrationSequence()
c2.runCalibrationSequence() c2.runCalibrationSequence()
@ -372,8 +372,17 @@ private fun getAuthToken(exchange: HttpExchange) =
exchange.requestHeaders["Cookie"] exchange.requestHeaders["Cookie"]
?.let { if (it.size > 0) it[0] else null } ?.let { if (it.size > 0) it[0] else null }
?.let { it.split("; ") } ?.let { it.split("; ") }
?.filter { it.startsWith("auth=") } ?.firstOrNull { it.startsWith("auth=") }
?.firstOrNull()
?.let { it.split("=").let { if (it.size == 2) it[1] else "" } } ?.let { it.split("=").let { if (it.size == 2) it[1] else "" } }
?: "" ?: ""
fun whileNotInterrupted(body: () -> Unit) {
try {
while (!Thread.interrupted()) {
body()
}
Thread.currentThread().interrupt()
} catch (e: InterruptedException) {
Thread.currentThread().interrupt()
}
}