feat: Logo and copyright in verify email are same with these in company info

This commit is contained in:
rainzm
2020-06-02 20:52:06 +08:00
parent 847c296b64
commit 3630164960
3 changed files with 56 additions and 2 deletions
File diff suppressed because one or more lines are too long
+50
View File
@@ -32,6 +32,8 @@ import (
"yunion.io/x/onecloud/pkg/cloudcommon/db"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/auth"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/notify/options"
"yunion.io/x/onecloud/pkg/notify/rpc/apis"
"yunion.io/x/onecloud/pkg/util/httputils"
@@ -120,6 +122,54 @@ func (tm *STemplateManager) defaultTemplate() ([]STemplate, error) {
return templates, nil
}
var (
InitVerifyEmailOver = false
)
type CompanyInfo struct {
Logo string
LogoFormat string
Copyright string
}
func (tm *STemplateManager) TryInitVerifyEmail(ctx context.Context) error {
if InitVerifyEmailOver {
return nil
}
// fetch copyright and logo
session := auth.GetAdminSession(ctx, "", "")
obj, err := modules.Info.Get(session, "info", jsonutils.NewDict())
if err != nil {
return err
}
var info CompanyInfo
err = obj.Unmarshal(&info)
if err != nil {
return err
}
// fetch verify email template
q := tm.Query().Equals("contact_type", "email").Equals("topic", "VERIFY").Equals("template_type", "content")
tem := &STemplate{}
err = q.First(tem)
if err != nil {
return err
}
tem.SetModelManager(TemplateManager, tem)
content, err := tem.Execute(jsonutils.Marshal(info).String())
if err != nil {
return err
}
_, err = db.Update(tem, func() error {
tem.Content = content
return nil
})
return err
}
func (tm *STemplateManager) InitializeData() error {
templates, err := tm.defaultTemplate()
if err != nil {
+4
View File
@@ -75,6 +75,10 @@ func SendVerifyMessage(ctx context.Context, userCred mcclient.TokenCredential, v
err error
msg string
)
err = TemplateManager.TryInitVerifyEmail(ctx)
if err != nil {
log.Errorf("unable to try to init verify eamil: %s", err.Error())
}
processId, token := verify.ID, verify.Token
if contact.ContactType == "email" {
emailUrl := strings.Replace(TemplateManager.GetEmailUrl(), "{0}", processId, 1)