This should fix dashboard login

This commit is contained in:
NovaFox161
2021-07-06 13:38:46 -05:00
parent d240dc7d82
commit 7f9eeb93a5

View File

@@ -18,6 +18,7 @@ import org.json.JSONObject
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.reactive.function.server.ServerResponse
import org.springframework.web.server.ServerWebExchange
import reactor.core.publisher.Mono
import reactor.core.scheduler.Schedulers
@@ -27,8 +28,7 @@ import java.util.*
@RestController
class DiscordLoginHandler {
@GetMapping("/account/login")
fun handleDiscordCode(swe: ServerWebExchange, @RequestParam("code") code: String):
Mono<String> {
fun handleDiscordCode(swe: ServerWebExchange, @RequestParam("code") code: String): Mono<ServerResponse> {
val client = OkHttpClient()
return Mono.fromCallable {
@@ -135,20 +135,20 @@ class DiscordLoginHandler {
model["key"] = keyGrantResponseBody.getString("key")
DiscordAccountHandler.addAccount(model, swe)
.thenReturn("redirect:/dashboard")
.then(ServerResponse.ok().render("redirect:/dashboard"))
} else {
//Something didn't work, just redirect back to login page
LogFeed.log(
LogObject.forDebug("login issue", keyGrantResponse.body?.string())
)
Mono.just("redirect:/login")
ServerResponse.ok().render("redirect:/login")
}
})
})
} else {
//Token not provided. Auth denied or error. Redirect to login page
return@flatMap Mono.just("redirect:/login")
return@flatMap ServerResponse.ok().render("redirect:/login")
}
}.doOnError {
LogFeed.log(LogObject.forException("[Login-Discord] Discord login failed", it, this.javaClass))
@@ -156,11 +156,11 @@ class DiscordLoginHandler {
}
@GetMapping("/logout")
fun handleLogout(swe: ServerWebExchange): Mono<String> {
fun handleLogout(swe: ServerWebExchange): Mono<ServerResponse> {
return DiscordAccountHandler.getAccount(swe).flatMap { model ->
if (!model.containsKey("key")) {
//User isn't logged in, just redirect to home page
return@flatMap Mono.just("redirect:/")
return@flatMap ServerResponse.ok().render("redirect:/")
} else {
//Tell the API server the user has logged out and to delete the temp key
val client = OkHttpClient()
@@ -176,10 +176,10 @@ class DiscordLoginHandler {
return@flatMap Mono.fromCallable(client.newCall(logoutRequest)::execute)
.subscribeOn(Schedulers.boundedElastic())
.then(DiscordAccountHandler.removeAccount(swe))
.thenReturn("redirect:/")
.then(ServerResponse.ok().render("redirect:/"))
.doOnError {
LogFeed.log(LogObject.forException("[Web] Discord logout fail", it, this.javaClass))
}.onErrorReturn("redirect:/")
}.onErrorResume { ServerResponse.ok().render("redirect:/") }
}
}
}