diff --git a/build/notify/root/opt/yunion/share/template/content/VERIFY.email b/build/notify/root/opt/yunion/share/template/content/VERIFY.email index f4c786d670..612bd83941 100644 --- a/build/notify/root/opt/yunion/share/template/content/VERIFY.email +++ b/build/notify/root/opt/yunion/share/template/content/VERIFY.email @@ -11,7 +11,7 @@
- +
@@ -56,10 +56,10 @@ - *为了确保您的帐号安全,该链接仅48小时内访问有效,请勿直接回复此邮件。 + *为了确保您的帐号安全,该链接仅48小时内访问有效,请勿直接回复此邮件。 - 版权所有 © {{.copyright}} 保留一切权利 + 版权所有 © {{.copyright}} 保留一切权利 diff --git a/pkg/mcclient/modules/mod_notify_template.go b/pkg/mcclient/modules/mod_notify_template.go index 7017473305..42ad402635 100644 --- a/pkg/mcclient/modules/mod_notify_template.go +++ b/pkg/mcclient/modules/mod_notify_template.go @@ -26,7 +26,7 @@ type NotifyTemplateManager struct { } func (nm *NotifyTemplateManager) DeleteContents(s *mcclient.ClientSession, params jsonutils.JSONObject) (jsonutils.JSONObject, error) { - path := "/templates/delete-template" + path := "/notifytemplates/delete-template" return modulebase.Post(nm.ResourceManager, s, path, params, "") } diff --git a/pkg/notify/models/mod_template.go b/pkg/notify/models/mod_template.go index df7b5b9db0..1299a5fa65 100644 --- a/pkg/notify/models/mod_template.go +++ b/pkg/notify/models/mod_template.go @@ -90,7 +90,7 @@ var templatePath = "/opt/yunion/share/template" func (tm *STemplateManager) defaultTemplate() ([]STemplate, error) { templates := make([]STemplate, 0, 4) - for _, templateType := range []string{"title", "content", "remote"} { + for _, templateType := range []string{"title", "content"} { contactType, topic := CONTACTTYPE_ALL, "" titleTemplatePath := fmt.Sprintf("%s/%s", templatePath, templateType) files, err := ioutil.ReadDir(titleTemplatePath) @@ -122,52 +122,25 @@ func (tm *STemplateManager) defaultTemplate() ([]STemplate, error) { return templates, nil } -var ( - InitVerifyEmailOver = false -) - -type CompanyInfo struct { - Logo string - LogoFormat string - Copyright string +type SCompanyInfo struct { + LoginLogo string `json:"login_logo"` + LoginLogoFormat string `json:"login_logo_format"` + Copyright string `json:"copyright"` } -func (tm *STemplateManager) TryInitVerifyEmail(ctx context.Context) error { - if InitVerifyEmailOver { - return nil - } +func (tm *STemplateManager) GetCompanyInfo(ctx context.Context) (SCompanyInfo, error) { // fetch copyright and logo session := auth.GetAdminSession(ctx, "", "") obj, err := modules.Info.Get(session, "info", jsonutils.NewDict()) if err != nil { - return err + return SCompanyInfo{}, err } - var info CompanyInfo + var info SCompanyInfo err = obj.Unmarshal(&info) if err != nil { - return err + return SCompanyInfo{}, 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 + return info, nil } func (tm *STemplateManager) InitializeData() error { diff --git a/pkg/notify/models/worker.go b/pkg/notify/models/worker.go index 07803f6e6e..3c90fbe1b9 100644 --- a/pkg/notify/models/worker.go +++ b/pkg/notify/models/worker.go @@ -75,9 +75,9 @@ func SendVerifyMessage(ctx context.Context, userCred mcclient.TokenCredential, v err error msg string ) - err = TemplateManager.TryInitVerifyEmail(ctx) + info, err := TemplateManager.GetCompanyInfo(ctx) if err != nil { - log.Errorf("unable to try to init verify eamil: %s", err.Error()) + log.Errorf("unable to try to get company info: %s", err.Error()) } processId, token := verify.ID, verify.Token if contact.ContactType == "email" { @@ -92,7 +92,12 @@ func SendVerifyMessage(ctx context.Context, userCred mcclient.TokenCredential, v data := struct { Name string Link string - }{uName, emailUrl} + SCompanyInfo + }{ + Name: uName, + Link: emailUrl, + SCompanyInfo: info, + } msg = jsonutils.Marshal(data).String() } else if contact.ContactType == "mobile" { msg = fmt.Sprintf(`{"code": "%s"}`, token)