diff --git a/controllers/account.go b/controllers/account.go index 82b77822..2eda7c5f 100644 --- a/controllers/account.go +++ b/controllers/account.go @@ -246,19 +246,24 @@ func (c *ApiController) Signup() { // @Success 200 {object} controllers.Response The Response object // @router /logout [get,post] func (c *ApiController) Logout() { - user := c.GetSessionUsername() - // https://openid.net/specs/openid-connect-rpinitiated-1_0-final.html accessToken := c.Input().Get("id_token_hint") redirectUri := c.Input().Get("post_logout_redirect_uri") state := c.Input().Get("state") - if accessToken == "" && redirectUri == "" { - c.ClearUserSession() - // TODO https://github.com/casdoor/casdoor/pull/1494#discussion_r1095675265 - owner, username := util.GetOwnerAndNameFromId(user) + user := c.GetSessionUsername() + if accessToken == "" && redirectUri == "" { + // TODO https://github.com/casdoor/casdoor/pull/1494#discussion_r1095675265 + if user == "" { + c.ResponseOk() + return + } + + c.ClearUserSession() + owner, username := util.GetOwnerAndNameFromId(user) object.DeleteSessionId(util.GetSessionId(owner, username, object.CasdoorApplication), c.Ctx.Input.CruSession.SessionID()) + util.LogInfo(c.Ctx, "API: [%s] logged out", user) application := c.GetSessionApplication() diff --git a/controllers/ldap.go b/controllers/ldap.go index e4320969..2a9c8547 100644 --- a/controllers/ldap.go +++ b/controllers/ldap.go @@ -97,8 +97,7 @@ func (c *ApiController) GetLdapUser() { }) } - c.Data["json"] = Response{Status: "ok", Data: resp} - c.ServeJSON() + c.ResponseOk(resp) } // GetLdaps @@ -108,8 +107,7 @@ func (c *ApiController) GetLdapUser() { func (c *ApiController) GetLdaps() { owner := c.Input().Get("owner") - c.Data["json"] = Response{Status: "ok", Data: object.GetLdaps(owner)} - c.ServeJSON() + c.ResponseOk(object.GetLdaps(owner)) } // GetLdap @@ -124,8 +122,8 @@ func (c *ApiController) GetLdap() { return } - c.Data["json"] = Response{Status: "ok", Data: object.GetLdap(id)} - c.ServeJSON() + _, name := util.GetOwnerAndNameFromId(id) + c.ResponseOk(object.GetLdap(name)) } // AddLdap @@ -159,8 +157,7 @@ func (c *ApiController) AddLdap() { object.GetLdapAutoSynchronizer().StartAutoSync(ldap.Id) } - c.Data["json"] = resp - c.ServeJSON() + c.ResponseOk(resp) } // UpdateLdap @@ -187,8 +184,7 @@ func (c *ApiController) UpdateLdap() { object.GetLdapAutoSynchronizer().StopAutoSync(ldap.Id) } - c.Data["json"] = resp - c.ServeJSON() + c.ResponseOk(resp) } // DeleteLdap @@ -204,8 +200,7 @@ func (c *ApiController) DeleteLdap() { } object.GetLdapAutoSynchronizer().StopAutoSync(ldap.Id) - c.Data["json"] = wrapActionResponse(object.DeleteLdap(&ldap)) - c.ServeJSON() + c.ResponseOk(wrapActionResponse(object.DeleteLdap(&ldap))) } // SyncLdapUsers @@ -225,11 +220,11 @@ func (c *ApiController) SyncLdapUsers() { object.UpdateLdapSyncTime(ldapId) exist, failed := object.SyncLdapUsers(owner, users, ldapId) - c.Data["json"] = &Response{Status: "ok", Data: &LdapSyncResp{ + + c.ResponseOk(&LdapSyncResp{ Exist: *exist, Failed: *failed, - }} - c.ServeJSON() + }) } // CheckLdapUsersExist @@ -246,6 +241,5 @@ func (c *ApiController) CheckLdapUsersExist() { } exist := object.CheckLdapUuidExist(owner, uuids) - c.Data["json"] = &Response{Status: "ok", Data: exist} - c.ServeJSON() + c.ResponseOk(exist) } diff --git a/web/src/App.js b/web/src/App.js index d038d788..c2967e6f 100644 --- a/web/src/App.js +++ b/web/src/App.js @@ -516,8 +516,8 @@ class App extends Component { this.renderLoginIfNotLoggedIn()} /> this.renderLoginIfNotLoggedIn()} /> {/* this.renderLoginIfNotLoggedIn()}/>*/} - this.renderLoginIfNotLoggedIn()} /> - this.renderLoginIfNotLoggedIn()} /> + this.renderLoginIfNotLoggedIn()} /> + this.renderLoginIfNotLoggedIn()} /> this.renderLoginIfNotLoggedIn()} /> this.renderLoginIfNotLoggedIn()} /> this.renderLoginIfNotLoggedIn()} /> diff --git a/web/src/LdapEditPage.js b/web/src/LdapEditPage.js index 04f3c2b4..6a57e8c7 100644 --- a/web/src/LdapEditPage.js +++ b/web/src/LdapEditPage.js @@ -27,6 +27,7 @@ class LdapEditPage extends React.Component { super(props); this.state = { ldapId: props.match.params.ldapId, + organizationName: props.match.params.organizationName, ldap: null, organizations: [], }; @@ -38,7 +39,7 @@ class LdapEditPage extends React.Component { } getLdap() { - LddpBackend.getLdap(this.state.ldapId) + LddpBackend.getLdap(this.state.organizationName, this.state.ldapId) .then((res) => { if (res.status === "ok") { this.setState({ diff --git a/web/src/LdapSyncPage.js b/web/src/LdapSyncPage.js index ca734411..8f4be7e1 100644 --- a/web/src/LdapSyncPage.js +++ b/web/src/LdapSyncPage.js @@ -23,6 +23,7 @@ class LdapSyncPage extends React.Component { super(props); this.state = { ldapId: props.match.params.ldapId, + organizationName: props.match.params.organizationName, ldap: null, users: [], existUuids: [], @@ -73,7 +74,7 @@ class LdapSyncPage extends React.Component { } getLdap() { - LdapBackend.getLdap(this.state.ldapId) + LdapBackend.getLdap(this.state.organizationName, this.state.ldapId) .then((res) => { if (res.status === "ok") { this.setState((prevState) => { diff --git a/web/src/LdapTable.js b/web/src/LdapTable.js index c8329b53..3a6b5fda 100644 --- a/web/src/LdapTable.js +++ b/web/src/LdapTable.js @@ -154,9 +154,9 @@ class LdapTable extends React.Component {
+ onClick={() => Setting.goToLink(`/ldap/sync/${record.owner}/${record.id}`)}>{i18next.t("ldap:Sync")} + onClick={() => Setting.goToLink(`/ldap/${record.owner}/${record.id}`)}>{i18next.t("general:Edit")} this.deleteRow(table, index)} diff --git a/web/src/backend/LdapBackend.js b/web/src/backend/LdapBackend.js index 48bcd927..559d9d9c 100644 --- a/web/src/backend/LdapBackend.js +++ b/web/src/backend/LdapBackend.js @@ -24,8 +24,8 @@ export function getLdaps(owner) { }).then(res => res.json()); } -export function getLdap(id) { - return fetch(`${Setting.ServerUrl}/api/get-ldap?id=${id}`, { +export function getLdap(owner, name) { + return fetch(`${Setting.ServerUrl}/api/get-ldap?id=${owner}/${encodeURIComponent(name)}`, { method: "GET", credentials: "include", headers: {