feat: append footerHtml to cookie (#3508)

This commit is contained in:
DacongDA 2025-01-19 23:34:43 +08:00 committed by GitHub
parent a74a004540
commit 49dda2aea5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 12 deletions

View File

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

View File

@ -270,7 +270,9 @@ class App extends Component {
});
}
renderFooter(logo) {
renderFooter(logo, footerHtml) {
logo = logo ?? this.state.logo;
footerHtml = footerHtml ?? this.state.application?.footerHtml;
return (
<React.Fragment>
{!this.state.account ? null : <div style={{display: "none"}} id="CasdoorApplicationName" value={this.state.account.signupApplication} />}
@ -281,14 +283,14 @@ class App extends Component {
}
}>
{
this.state.application?.footerHtml && this.state.application.footerHtml !== "" ?
footerHtml && footerHtml !== "" ?
<React.Fragment>
<div dangerouslySetInnerHTML={{__html: this.state.application.footerHtml}} />
<div dangerouslySetInnerHTML={{__html: footerHtml}} />logo
</React.Fragment>
: (
Conf.CustomFooter !== null ? Conf.CustomFooter : (
<React.Fragment>
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>
Powered by <a target="_blank" href="https://casdoor.org" rel="noreferrer"><img style={{paddingBottom: "3px"}} height={"20px"} alt={"Casdoor"} src={logo} /></a>
</React.Fragment>
)
)
@ -363,6 +365,7 @@ class App extends Component {
if (this.isDoorPages()) {
let themeData = this.state.themeData;
let logo = this.state.logo;
let footerHtml = null;
if (this.state.organization === undefined) {
const curCookie = Cookie.parse(document.cookie);
if (curCookie["organizationTheme"] && curCookie["organizationTheme"] !== "null") {
@ -371,6 +374,9 @@ class App extends Component {
if (curCookie["organizationLogo"] && curCookie["organizationLogo"] !== "") {
logo = curCookie["organizationLogo"];
}
if (curCookie["organizationFootHtml"] && curCookie["organizationFootHtml"] !== "") {
footerHtml = curCookie["organizationFootHtml"];
}
}
return (
@ -414,7 +420,7 @@ class App extends Component {
}
</Content>
{
this.renderFooter(logo)
this.renderFooter(logo, footerHtml)
}
{
this.renderAiAssistant()