From 8080927890b6e9791ff36934d3f9ee1c2c9c4c02 Mon Sep 17 00:00:00 2001 From: Yi Zhan Date: Sat, 19 Mar 2022 19:50:05 +0800 Subject: [PATCH] fix: redirect for non-built-in app logout (#587) Signed-off-by: Steve0x2a --- controllers/account.go | 7 ++++++- controllers/base.go | 9 +++++++++ web/src/App.js | 8 ++++++-- web/src/auth/PromptPage.js | 5 ++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/controllers/account.go b/controllers/account.go index 5da7ee36b..768359092 100644 --- a/controllers/account.go +++ b/controllers/account.go @@ -225,10 +225,15 @@ func (c *ApiController) Logout() { user := c.GetSessionUsername() util.LogInfo(c.Ctx, "API: [%s] logged out", user) + application := c.GetSessionApplication() c.SetSessionUsername("") c.SetSessionData(nil) - c.ResponseOk(user) + if application == nil || application.Name == "app-built-in" || application.HomepageUrl == "" { + c.ResponseOk(user) + return + } + c.ResponseOk(user, application.HomepageUrl) } // GetAccount diff --git a/controllers/base.go b/controllers/base.go index 203b120af..bbbacf631 100644 --- a/controllers/base.go +++ b/controllers/base.go @@ -72,6 +72,15 @@ func (c *ApiController) GetSessionUsername() string { return user.(string) } +func (c *ApiController) GetSessionApplication() *object.Application { + clientId := c.GetSession("aud") + if clientId == nil { + return nil + } + application := object.GetApplicationByClientId(clientId.(string)) + return application +} + func (c *ApiController) GetSessionOidc() (string, string) { sessionData := c.GetSessionData() if sessionData != nil && diff --git a/web/src/App.js b/web/src/App.js index 673865702..8f3e6cc8b 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -235,8 +235,12 @@ class App extends Component { }); Setting.showMessage("success", `Logged out successfully`); - - Setting.goToLinkSoft(this, "/"); + let redirectUri = res.data2; + if (redirectUri !== null && redirectUri !== undefined && redirectUri !== "") { + Setting.goToLink(redirectUri); + }else{ + Setting.goToLinkSoft(this, "/"); + } } else { Setting.showMessage("error", `Failed to log out: ${res.msg}`); } diff --git a/web/src/auth/PromptPage.js b/web/src/auth/PromptPage.js index dff1cf2d5..9503c3bc5 100644 --- a/web/src/auth/PromptPage.js +++ b/web/src/auth/PromptPage.js @@ -147,7 +147,10 @@ class PromptPage extends React.Component { if (res.status === 'ok') { this.onUpdateAccount(null); - const redirectUrl = this.getRedirectUrl(); + let redirectUrl = this.getRedirectUrl(); + if (redirectUrl === "") { + redirectUrl = res.data2 + } if (redirectUrl !== "") { Setting.goToLink(redirectUrl); } else {