feat: append logo url to cookie (#3507)

This commit is contained in:
DacongDA
2025-01-19 08:02:44 +08:00
committed by GitHub
parent 2b89f6b37b
commit a74a004540
2 changed files with 15 additions and 10 deletions

View File

@ -30,7 +30,7 @@ func appendThemeCookie(ctx *context.Context, urlPath string) error {
return err return err
} }
if application.ThemeData != nil { if application.ThemeData != nil {
return setThemeDataCookie(ctx, application.ThemeData) return setThemeDataCookie(ctx, application.ThemeData, application.Logo)
} }
organization := application.OrganizationObj organization := application.OrganizationObj
if organization == nil { if organization == nil {
@ -40,7 +40,7 @@ func appendThemeCookie(ctx *context.Context, urlPath string) error {
} }
} }
if organization != nil { if organization != nil {
return setThemeDataCookie(ctx, organization.ThemeData) return setThemeDataCookie(ctx, organization.ThemeData, organization.Logo)
} }
} else if strings.HasPrefix(urlPath, "/login/oauth/authorize") { } else if strings.HasPrefix(urlPath, "/login/oauth/authorize") {
clientId := ctx.Input.Query("client_id") clientId := ctx.Input.Query("client_id")
@ -57,10 +57,10 @@ func appendThemeCookie(ctx *context.Context, urlPath string) error {
return err return err
} }
if application.ThemeData != nil { if application.ThemeData != nil {
return setThemeDataCookie(ctx, application.ThemeData) return setThemeDataCookie(ctx, application.ThemeData, application.Logo)
} }
if organization != nil { if organization != nil {
return setThemeDataCookie(ctx, organization.ThemeData) return setThemeDataCookie(ctx, organization.ThemeData, organization.Logo)
} }
} }
} else if strings.HasPrefix(urlPath, "/login/") { } else if strings.HasPrefix(urlPath, "/login/") {
@ -71,7 +71,7 @@ func appendThemeCookie(ctx *context.Context, urlPath string) error {
return err return err
} }
if application.ThemeData != nil { if application.ThemeData != nil {
return setThemeDataCookie(ctx, application.ThemeData) return setThemeDataCookie(ctx, application.ThemeData, application.Logo)
} }
organization := application.OrganizationObj organization := application.OrganizationObj
if organization == nil { if organization == nil {
@ -81,7 +81,7 @@ func appendThemeCookie(ctx *context.Context, urlPath string) error {
} }
} }
if organization != nil { if organization != nil {
return setThemeDataCookie(ctx, organization.ThemeData) return setThemeDataCookie(ctx, organization.ThemeData, organization.Logo)
} }
} }
} }
@ -89,11 +89,12 @@ func appendThemeCookie(ctx *context.Context, urlPath string) error {
return nil return nil
} }
func setThemeDataCookie(ctx *context.Context, themeData *object.ThemeData) error { func setThemeDataCookie(ctx *context.Context, themeData *object.ThemeData, logoUrl string) error {
themeDataString, err := json.Marshal(themeData) themeDataString, err := json.Marshal(themeData)
if err != nil { if err != nil {
return err return err
} }
ctx.SetCookie("organizationTheme", string(themeDataString)) ctx.SetCookie("organizationTheme", string(themeDataString))
ctx.SetCookie("organizationLogo", logoUrl)
return nil return nil
} }

View File

@ -270,7 +270,7 @@ class App extends Component {
}); });
} }
renderFooter() { renderFooter(logo) {
return ( return (
<React.Fragment> <React.Fragment>
{!this.state.account ? null : <div style={{display: "none"}} id="CasdoorApplicationName" value={this.state.account.signupApplication} />} {!this.state.account ? null : <div style={{display: "none"}} id="CasdoorApplicationName" value={this.state.account.signupApplication} />}
@ -288,7 +288,7 @@ class App extends Component {
: ( : (
Conf.CustomFooter !== null ? Conf.CustomFooter : ( Conf.CustomFooter !== null ? Conf.CustomFooter : (
<React.Fragment> <React.Fragment>
Powered by <a target="_blank" href="https://casdoor.org" rel="noreferrer"><img style={{paddingBottom: "3px"}} height={"20px"} alt={"Casdoor"} src={this.state.logo} /></a> Powered by <a target="_blank" href="https://casdoor.org" rel="noreferrer"><img style={{paddingBottom: "3px"}} height={"20px"} alt={"Casdoor"} src={logo ?? this.state.logo} /></a>
</React.Fragment> </React.Fragment>
) )
) )
@ -362,11 +362,15 @@ class App extends Component {
renderPage() { renderPage() {
if (this.isDoorPages()) { if (this.isDoorPages()) {
let themeData = this.state.themeData; let themeData = this.state.themeData;
let logo = this.state.logo;
if (this.state.organization === undefined) { if (this.state.organization === undefined) {
const curCookie = Cookie.parse(document.cookie); const curCookie = Cookie.parse(document.cookie);
if (curCookie["organizationTheme"] && curCookie["organizationTheme"] !== "null") { if (curCookie["organizationTheme"] && curCookie["organizationTheme"] !== "null") {
themeData = JSON.parse(curCookie["organizationTheme"]); themeData = JSON.parse(curCookie["organizationTheme"]);
} }
if (curCookie["organizationLogo"] && curCookie["organizationLogo"] !== "") {
logo = curCookie["organizationLogo"];
}
} }
return ( return (
@ -410,7 +414,7 @@ class App extends Component {
} }
</Content> </Content>
{ {
this.renderFooter() this.renderFooter(logo)
} }
{ {
this.renderAiAssistant() this.renderAiAssistant()