mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
fix(cloudid): add en-US html templte
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/appctx"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/cloudid/models"
|
||||
"yunion.io/x/onecloud/pkg/cloudid/options"
|
||||
@@ -74,7 +75,12 @@ func initSAMLIdp(app *appsrv.Application, prefix string) error {
|
||||
}
|
||||
|
||||
logoutFunc := func(ctx context.Context, idpId string) string {
|
||||
return fmt.Sprintf(`<!DOCTYPE html><html lang="zh_CN"><head><meta charset="utf-8"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><h1>成功退出登录,<a href="%s">重新登录</a></h1></body></html>`, options.Options.ApiServer)
|
||||
switch appctx.AppContextLang(ctx) {
|
||||
case "zh-CN":
|
||||
return fmt.Sprintf(`<!DOCTYPE html><html lang="zh_CN"><head><meta charset="utf-8"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><h1>成功退出登录,<a href="%s">重新登录</a></h1></body></html>`, options.Options.ApiServer)
|
||||
default:
|
||||
return fmt.Sprintf(`<!DOCTYPE html><html lang="zh_CN"><head><meta charset="utf-8"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><h1>Log out successfully,<a href="%s">Login again</a></h1></body></html>`, options.Options.ApiServer)
|
||||
}
|
||||
}
|
||||
|
||||
idpInst := idp.NewIdpInstance(saml, spFunc, idpFunc, logoutFunc)
|
||||
@@ -105,7 +111,8 @@ func initSAMLIdp(app *appsrv.Application, prefix string) error {
|
||||
}
|
||||
|
||||
idpInst.AddHandlers(app, prefix, auth.Authenticate)
|
||||
idpInst.SetHtmlTemplate(`<!DOCTYPE html><html lang="zh_CN"><head><meta charset="utf-8"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><h1>正在跳转到云控制台,请等待。。。</h1>$FORM$</body></html>`)
|
||||
idpInst.SetHtmlTemplate("zh-CN", `<!DOCTYPE html><html lang="zh"><head><meta charset="utf-8"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><h1>正在跳转到云控制台,请等待。。。</h1>$FORM$</body></html>`)
|
||||
idpInst.SetHtmlTemplate("en", `<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><h1>Jumping to the console, please wait。。。</h1>$FORM$</body></html>`)
|
||||
|
||||
idpInstance = idpInst
|
||||
|
||||
|
||||
@@ -371,7 +371,7 @@ func prepareServer() error {
|
||||
}
|
||||
}
|
||||
idpInst.AddHandlers(app, "SAML/idp", nil)
|
||||
idpInst.SetHtmlTemplate(`<!DOCTYPE html><html lang="zh_CN"><head><meta charset="utf-8"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><h1>正在跳转到云控制台,请等待。。。</h1>$FORM$</body></html>`)
|
||||
idpInst.SetHtmlTemplate("zh-CN", `<!DOCTYPE html><html lang="zh_CN"><head><meta charset="utf-8"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body><h1>正在跳转到云控制台,请等待。。。</h1>$FORM$</body></html>`)
|
||||
|
||||
app.AddHandler("GET", "SAML/idp", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
idpInitUrl := httputils.JoinPath(options.Entity, "SAML/idp/sso")
|
||||
|
||||
@@ -54,7 +54,7 @@ type SSAMLIdpInstance struct {
|
||||
onIdpInitiatedLogin OnIdpInitiatedLogin
|
||||
onLogout OnLogout
|
||||
|
||||
htmlTemplate string
|
||||
htmlTemplate map[string]string
|
||||
}
|
||||
|
||||
func NewIdpInstance(saml *samlutils.SSAMLInstance, spLoginFunc OnSpInitiatedLogin, idpLoginFunc OnIdpInitiatedLogin, logoutFunc OnLogout) *SSAMLIdpInstance {
|
||||
@@ -63,6 +63,7 @@ func NewIdpInstance(saml *samlutils.SSAMLInstance, spLoginFunc OnSpInitiatedLogi
|
||||
onSpInitiatedLogin: spLoginFunc,
|
||||
onIdpInitiatedLogin: idpLoginFunc,
|
||||
onLogout: logoutFunc,
|
||||
htmlTemplate: map[string]string{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,11 +97,11 @@ func (idp *SSAMLIdpInstance) AddHandlers(app *appsrv.Application, prefix string,
|
||||
log.Infof("IDP initated SSO: %s", idp.getIdpInitiatedSSOUrl())
|
||||
}
|
||||
|
||||
func (idp *SSAMLIdpInstance) SetHtmlTemplate(tmp string) error {
|
||||
func (idp *SSAMLIdpInstance) SetHtmlTemplate(lang, tmp string) error {
|
||||
if strings.Index(tmp, samlutils.HTML_SAML_FORM_TOKEN) < 0 {
|
||||
return errors.Wrapf(httperrors.ErrInvalidFormat, "no %s found", samlutils.HTML_SAML_FORM_TOKEN)
|
||||
}
|
||||
idp.htmlTemplate = tmp
|
||||
idp.htmlTemplate[lang] = tmp
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -235,7 +236,7 @@ func (idp *SSAMLIdpInstance) processLoginRequest(ctx context.Context, idpId stri
|
||||
return "", errors.Wrap(err, "getLoginResponse")
|
||||
}
|
||||
|
||||
form, err := idp.samlResponse2Form(sp.GetPostAssertionConsumerServiceUrl(), resp, input.RelayState)
|
||||
form, err := idp.samlResponse2Form(ctx, sp.GetPostAssertionConsumerServiceUrl(), resp, input.RelayState)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "samlResponse2Form")
|
||||
}
|
||||
@@ -243,7 +244,7 @@ func (idp *SSAMLIdpInstance) processLoginRequest(ctx context.Context, idpId stri
|
||||
return form, nil
|
||||
}
|
||||
|
||||
func (idp *SSAMLIdpInstance) samlResponse2Form(url string, resp *samlutils.Response, state string) (string, error) {
|
||||
func (idp *SSAMLIdpInstance) samlResponse2Form(ctx context.Context, url string, resp *samlutils.Response, state string) (string, error) {
|
||||
respXml, err := xml.Marshal(resp)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "xml.Marshal")
|
||||
@@ -263,7 +264,9 @@ func (idp *SSAMLIdpInstance) samlResponse2Form(url string, resp *samlutils.Respo
|
||||
})
|
||||
template := samlutils.DEFAULT_HTML_TEMPLATE
|
||||
if len(idp.htmlTemplate) > 0 {
|
||||
template = idp.htmlTemplate
|
||||
if _temp, ok := idp.htmlTemplate[appctx.AppContextLang(ctx)]; ok {
|
||||
template = _temp
|
||||
}
|
||||
}
|
||||
form = strings.Replace(template, samlutils.HTML_SAML_FORM_TOKEN, form, 1)
|
||||
return form, nil
|
||||
@@ -316,7 +319,7 @@ func (idp *SSAMLIdpInstance) processIdpInitiatedLogin(ctx context.Context, input
|
||||
SSAMLSpInitiatedLoginData: data.SSAMLSpInitiatedLoginData,
|
||||
}
|
||||
resp := samlutils.NewResponse(respInput)
|
||||
form, err := idp.samlResponse2Form(sp.GetPostAssertionConsumerServiceUrl(), &resp, data.RelayState)
|
||||
form, err := idp.samlResponse2Form(ctx, sp.GetPostAssertionConsumerServiceUrl(), &resp, data.RelayState)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "samlResponse2Form")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user