mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20:18 +08:00
feat: fix theme filter for other URLs like SAML (#3523)
* fix: fix error cause by theme filter * fix: add saml url to theme filter and use getGetOwnerAndNameFromIdWithError instead of using GetOwnerAndNameFromId * fix: fix code error * fix: add support for cas and pack judgement into a function * fix: fix linter err
This commit is contained in:
@ -481,7 +481,10 @@ func GetApplicationByClientId(clientId string) (*Application, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetApplication(id string) (*Application, error) {
|
func GetApplication(id string) (*Application, error) {
|
||||||
owner, name := util.GetOwnerAndNameFromId(id)
|
owner, name, err := util.GetOwnerAndNameFromIdWithError(id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return getApplication(owner, name)
|
return getApplication(owner, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,10 @@ func getOrganization(owner string, name string) (*Organization, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetOrganization(id string) (*Organization, error) {
|
func GetOrganization(id string) (*Organization, error) {
|
||||||
owner, name := util.GetOwnerAndNameFromId(id)
|
owner, name, err := util.GetOwnerAndNameFromIdWithError(id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return getOrganization(owner, name)
|
return getOrganization(owner, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,94 +32,79 @@ type OrganizationThemeCookie struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func appendThemeCookie(ctx *context.Context, urlPath string) (*OrganizationThemeCookie, error) {
|
func appendThemeCookie(ctx *context.Context, urlPath string) (*OrganizationThemeCookie, error) {
|
||||||
|
organizationThemeCookie, err := getOrganizationThemeCookieFromUrlPath(ctx, urlPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if organizationThemeCookie != nil {
|
||||||
|
return organizationThemeCookie, setThemeDataCookie(ctx, organizationThemeCookie)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getOrganizationThemeCookieFromUrlPath(ctx *context.Context, urlPath string) (*OrganizationThemeCookie, error) {
|
||||||
|
var application *object.Application
|
||||||
|
var organization *object.Organization
|
||||||
|
var err error
|
||||||
if urlPath == "/login" {
|
if urlPath == "/login" {
|
||||||
application, err := object.GetDefaultApplication(fmt.Sprintf("admin/built-in"))
|
application, err = object.GetDefaultApplication(fmt.Sprintf("admin/built-in"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
organization := application.OrganizationObj
|
|
||||||
if organization == nil {
|
|
||||||
organization, err = object.GetOrganization(fmt.Sprintf("admin/built-in"))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if organization != nil {
|
|
||||||
organizationThemeCookie := &OrganizationThemeCookie{
|
|
||||||
application.ThemeData,
|
|
||||||
application.Logo,
|
|
||||||
application.FooterHtml,
|
|
||||||
organization.Favicon,
|
|
||||||
organization.DisplayName,
|
|
||||||
}
|
|
||||||
|
|
||||||
if application.ThemeData != nil {
|
|
||||||
organizationThemeCookie.ThemeData = organization.ThemeData
|
|
||||||
}
|
|
||||||
return organizationThemeCookie, setThemeDataCookie(ctx, organizationThemeCookie)
|
|
||||||
}
|
|
||||||
} 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")
|
||||||
if clientId == "" {
|
if clientId == "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
application, err := object.GetApplicationByClientId(clientId)
|
application, err = object.GetApplicationByClientId(clientId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if application != nil {
|
} else if strings.HasPrefix(urlPath, "/login/saml") {
|
||||||
organization := application.OrganizationObj
|
owner, _ := strings.CutPrefix(urlPath, "/login/saml/authorize/")
|
||||||
if organization == nil {
|
application, err = object.GetApplication(owner)
|
||||||
organization, err = object.GetOrganization(fmt.Sprintf("admin/%s", application.Owner))
|
if err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
organizationThemeCookie := &OrganizationThemeCookie{
|
|
||||||
application.ThemeData,
|
|
||||||
application.Logo,
|
|
||||||
application.FooterHtml,
|
|
||||||
organization.Favicon,
|
|
||||||
organization.DisplayName,
|
|
||||||
}
|
|
||||||
|
|
||||||
if application.ThemeData != nil {
|
|
||||||
organizationThemeCookie.ThemeData = organization.ThemeData
|
|
||||||
}
|
|
||||||
return organizationThemeCookie, setThemeDataCookie(ctx, organizationThemeCookie)
|
|
||||||
}
|
}
|
||||||
} else if strings.HasPrefix(urlPath, "/login/") {
|
} else if strings.HasPrefix(urlPath, "/login/") {
|
||||||
owner := strings.Replace(urlPath, "/login/", "", -1)
|
owner, _ := strings.CutPrefix(urlPath, "/login/")
|
||||||
if owner != "undefined" && owner != "oauth/undefined" {
|
if owner == "undefined" || strings.Count(owner, "/") > 0 {
|
||||||
application, err := object.GetDefaultApplication(fmt.Sprintf("admin/%s", owner))
|
return nil, nil
|
||||||
if err != nil {
|
}
|
||||||
return nil, err
|
application, err = object.GetDefaultApplication(fmt.Sprintf("admin/%s", owner))
|
||||||
}
|
if err != nil {
|
||||||
organization := application.OrganizationObj
|
return nil, err
|
||||||
if organization == nil {
|
}
|
||||||
organization, err = object.GetOrganization(fmt.Sprintf("admin/%s", owner))
|
} else if strings.HasPrefix(urlPath, "/cas/") && strings.HasSuffix(urlPath, "/login") {
|
||||||
if err != nil {
|
owner, _ := strings.CutPrefix(urlPath, "/cas/")
|
||||||
return nil, err
|
owner, _ = strings.CutSuffix(owner, "/login")
|
||||||
}
|
application, err = object.GetApplication(owner)
|
||||||
}
|
if err != nil {
|
||||||
if organization != nil {
|
return nil, err
|
||||||
organizationThemeCookie := &OrganizationThemeCookie{
|
|
||||||
application.ThemeData,
|
|
||||||
application.Logo,
|
|
||||||
application.FooterHtml,
|
|
||||||
organization.Favicon,
|
|
||||||
organization.DisplayName,
|
|
||||||
}
|
|
||||||
|
|
||||||
if application.ThemeData != nil {
|
|
||||||
organizationThemeCookie.ThemeData = organization.ThemeData
|
|
||||||
}
|
|
||||||
return organizationThemeCookie, setThemeDataCookie(ctx, organizationThemeCookie)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
if application == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
organization = application.OrganizationObj
|
||||||
|
if organization == nil {
|
||||||
|
organization, err = object.GetOrganization(fmt.Sprintf("admin/%s", application.Organization))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
organizationThemeCookie := &OrganizationThemeCookie{
|
||||||
|
application.ThemeData,
|
||||||
|
application.Logo,
|
||||||
|
application.FooterHtml,
|
||||||
|
organization.Favicon,
|
||||||
|
organization.DisplayName,
|
||||||
|
}
|
||||||
|
|
||||||
|
return organizationThemeCookie, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setThemeDataCookie(ctx *context.Context, organizationThemeCookie *OrganizationThemeCookie) error {
|
func setThemeDataCookie(ctx *context.Context, organizationThemeCookie *OrganizationThemeCookie) error {
|
||||||
|
Reference in New Issue
Block a user